-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EZP-28742: Add unit tests to RepositoryForms #307
EZP-28742: Add unit tests to RepositoryForms #307
Conversation
f7e7fff
to
d206b52
Compare
$this->assertSame([ContentEditEvents::CONTENT_PREVIEW => ['processPreview', 10]], $previewFormProcessor::getSubscribedEvents()); | ||
} | ||
|
||
protected function createUntouchableMock(string $class): MockObject |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the thinking behind untouchable mock? Any particular reason why you are mocking a class which should never be used by implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, if we have situation like in ProcessPreview
method, where we want to be sure, that in "positive path" we won't call any method from notificationHandler
or translator
, this is usecase for "UntouchableMock". E.g. if someone accidentally delete try-catch block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry but you are restricting implementation details in the test cases which should NEVER be the case. Right now you are making any refactoring really hard because small change can make tests fail. How not using $translator
is a valid assertion from the test standpoint?
{ | ||
$translator = $this->createMock(TranslatorInterface::class); | ||
$translator | ||
->expects(self::once()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm against creating strict mocks that are checking method calls - this is testing implementation detail which should not be in the scope of the test. From my perspective I don't see any point in mocking Translator interface and making sure it was called only once with specific message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is important to ensure that we have the right error message, and we do it once. But I would like to hear another opinion @Nattfarinn @ViniTou
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright but using "expects only once" affects implementation details which in most cases ends up as failing tests even though the changes were correct. Please test only the outcome which in case of a PreviewFormProcessor might be not that explicit but it would be saving a draft and setting a RedirectResponse with proper URL if I remember correctly.
d206b52
to
53dcaa6
Compare
$contentStruct = $this->generateContentStruct($languageCode, $fieldDefinitionIdentifier, $fieldDataValue); | ||
|
||
$contentDraft = $this->generateContentDraft($contentDraftId, $languageCode); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you work on code style a bit more? I feel like separating everything with a new line doesn't make sense here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've two minor complaints regarding code style. Other than that it's alright.
private function generateVersionInfo(APIContentInfo $contentInfo): APIVersionInfo | ||
{ | ||
return new VersionInfo( | ||
[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For arrays with only one element you can write it inline. No need to expand it as it takes more lines and forces you to scroll more.
53dcaa6
to
adf2980
Compare
@webhdx are you good now? |
Add unit tests to RepositoryForms
Checklist:
$ composer fix-cs
)