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
DX: do not allow overriding constructor of PHPUnit\Framework\TestCase
#7563
DX: do not allow overriding constructor of PHPUnit\Framework\TestCase
#7563
Conversation
{ | ||
$reflection = new \ReflectionObject($this); | ||
|
||
self::assertNotSame( |
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.
@kubawerlos
whenever doing things like this, use the message parameter. JohnDoe will see that they done sth we didn't want, but without understanding "why" we don't want it.
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 believe the default messages for each assert are good enough in most cases, it's not like the developer won't know anything about the failure.
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.
huh? @Wirone , once more my msg:
JohnDoe will see that they done sth we didn't want, but without understanding "why" we don't want it.
So let say JohnDoe wanted to contribute for first time, they did new test and use constructor in it.
Then, they get this result:
ker@d ~/github/FriendsOfPHP/PHP-CS-Fixer λ ./vendor/bin/phpunit tests/SomeTest.php
PHPUnit 9.6.15 by Sebastian Bergmann and contributors.
Testing PhpCsFixer\Tests\SomeTest
....F 5 / 5 (100%)
Time: 00:00.045, Memory: 26.50 MB
There was 1 failure:
1) PhpCsFixer\Tests\SomeTest::testNotDefiningConstructor
Failed asserting that two strings are not identical.
/Users/d.ruminski/github/FriendsOfPHP/PHP-CS-Fixer/tests/TestCase.php:33
So, JohnDoe got the msg what is failing (testNotDefiningConstructor
), yet without knowledge WHY not do define that constructor.
In PHPUnit 9 it would work as all parameters are optional: https://github.com/sebastianbergmann/phpunit/blob/9.6.15/src/Framework/TestCase.php#L489
However, in PHPUnit is not the same: https://github.com/sebastianbergmann/phpunit/blob/10.5.3/src/Framework/TestCase.php#L322C46-L322C46