10000 [DX]|Validator] Add PHPUnit hint in AbstractConstraintValidatorTest by lyrixx · Pull Request #14059 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DX]|Validator] Add PHPUnit hint in AbstractConstraintValidatorTest #14059

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

Merged
merged 1 commit into from
Mar 26, 2015

Conversation

lyrixx
Copy link
Member
@lyrixx lyrixx commented Mar 25, 2015
Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Fixed tickets ~
Tests pass? ~
License MIT

When one extends AbstractConstraintValidatorTest, If test fails
the output is not very easy to understand because all "magic"
is done in the parent class. So we have to read the code of the
parent class to understand what happened.

@lyrixx lyrixx force-pushed the validator-explicit-message branch from dc2e62e to 11927b4 Compare March 25, 2015 22:28
@@ -244,7 +244,7 @@ protected function expectValidateValueAt($i, $propertyPath, $value, $constraints

protected function assertNoViolation()
{
$this->assertCount(0, $this->context->getViolations());
$this->assertSame(0, $violationsCount = count($this->context->getViolations()), sprintf('0 violation expected. Got %d.', $violationsCount));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be enough to add a message as the third parameter when calling assertCount()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I will not be able to get the "real" (ie not expected) count.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you mean. The output will be something like this:

Expected no violations.
Failed asserting that actual size 1 matches expected size 0.

Isn't that clear enough?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I understand what you mean. But in order to keep consistency between both "assertion", I think It's better to keep a "long" message:

1) SensioLabs\Bundle\MyBundle\Tests\Validator\Constraints\ProjectRepositoryUrlValidatorTest::testInternalRepositoryCanBeEmptyInitially
1 violation(s) expected. Got 0.
Failed asserting that 0 is identical to 1.

/home/greg/dev/github.com/sensiolabs/my_project/vendor/symfony/symfony/src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php:420
/home/greg/dev/github.com/sensiolabs/my_project/src/SensioLabs/Bundle/MyBundle/Tests/Validator/Constraints/ProjectRepositoryUrlValidatorTest.php:60
/home/greg/dev/github.com/sebastianbergmann/phpunit/src/TextUI/Command.php:151
/home/greg/dev/github.com/sebastianbergmann/phpunit/src/TextUI/Command.php:103

2) SensioLabs\Bundle\MyBundle\Tests\Validator\Constraints\ProjectRepositoryUrlValidatorTest::testInternalRepositoryCannotBeEmptyAfterFirstSync
0 violation expected. Got 1.
Failed asserting that 1 is identical to 0.

/home/greg/dev/github.com/sensiolabs/my_project/vendor/symfony/symfony/src/Symfony/Component/Validator/Tests/Constraints/AbstractConstraintValidatorTest.php:247
/home/greg/dev/github.com/sensiolabs/my_project/src/SensioLabs/Bundle/MyBundle/Tests/Validator/Constraints/ProjectRepositoryUrlValidatorTest.php:72
/home/greg/dev/github.com/sebastianbergmann/phpunit/src/TextUI/Command.php:151
/home/greg/dev/github.com/sebastianbergmann/phpunit/src/TextUI/Command.php:103

When one extends AbstractConstraintValidatorTest, If test fails
the output is not very easy to understand because all "magic"
is done in the parent class. So we have to read the code of the
parent class to understand what happened.
@lyrixx lyrixx force-pushed the validator-explicit-message branch from 11927b4 to bebca0b Compare March 26, 2015 09:49
@fabpot
Copy link
Member
fabpot commented Mar 26, 2015

Thank you @lyrixx.

@fabpot fabpot merged commit bebca0b into symfony:2.7 Mar 26, 2015
fabpot added a commit that referenced this pull request Mar 26, 2015
…lidatorTest (lyrixx)

This PR was merged into the 2.7 branch.

Discussion
----------

[DX]|Validator] Add PHPUnit hint in AbstractConstraintValidatorTest

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Fixed tickets | ~
| Tests pass?   | ~
| License       | MIT

When one extends AbstractConstraintValidatorTest, If test fails
the output is not very easy to understand because all "magic"
is done in the parent class. So we have to read the code of the
parent class to understand what happened.

Commits
-------

bebca0b |Validator] Add PHPUnit hint in AbstractConstraintValidatorTest
@lyrixx lyrixx deleted the validator-explicit-message branch March 26, 2015 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0