Skip to content
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

Conversation

mikadamczyk
Copy link
Contributor

@mikadamczyk mikadamczyk commented Jan 15, 2018

Question Answer
Tickets https://jira.ez.no/browse/EZP-28742
Bug fix? no
New feature? yes
BC breaks? no
Tests pass? yes
Doc needed? no
License GPL-2.0

Add unit tests to RepositoryForms

Checklist:

  • Coding standards ($ composer fix-cs)
  • Ready for Code Review

@mikadamczyk mikadamczyk self-assigned this Jan 15, 2018
@mikadamczyk mikadamczyk force-pushed the ezp-28742-add-unit-tests-to-repository-forms branch from f7e7fff to d206b52 Compare January 16, 2018 10:54
$this->assertSame([ContentEditEvents::CONTENT_PREVIEW => ['processPreview', 10]], $previewFormProcessor::getSubscribedEvents());
}

protected function createUntouchableMock(string $class): MockObject
Copy link
Contributor

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?

Copy link
Contributor Author

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 notificationHandleror translator, this is usecase for "UntouchableMock". E.g. if someone accidentally delete try-catch block.

Copy link
Contributor

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())
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

@webhdx webhdx Jan 18, 2018

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.

@mikadamczyk mikadamczyk force-pushed the ezp-28742-add-unit-tests-to-repository-forms branch from d206b52 to 53dcaa6 Compare January 18, 2018 13:21
$contentStruct = $this->generateContentStruct($languageCode, $fieldDefinitionIdentifier, $fieldDataValue);

$contentDraft = $this->generateContentDraft($contentDraftId, $languageCode);

Copy link
Contributor

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.

Copy link
Contributor

@webhdx webhdx left a 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(
[
Copy link
Contributor

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.

@mikadamczyk mikadamczyk force-pushed the ezp-28742-add-unit-tests-to-repository-forms branch from 53dcaa6 to adf2980 Compare January 23, 2018 08:57
@lserwatka
Copy link
Member

@webhdx are you good now?

@lserwatka lserwatka merged commit 626db02 into ezsystems:1.0 Jan 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants