-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
dc2e62e
to
11927b4
Compare
@@ -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)); |
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.
Wouldn't it be enough to add a message as the third parameter when calling assertCount()
?
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.
But I will not be able to get the "real" (ie not expected) count.
There was a pro 8000 blem hiding this comment.
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?
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.
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.
11927b4
to
bebca0b
Compare
Thank you @lyrixx. |
…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
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.