hamcrest-php icon indicating copy to clipboard operation
hamcrest-php copied to clipboard

PHP Fatal error setUp()

Open LocalHeroPro opened this issue 3 years ago • 5 comments

Steps to reproduce:

$ php -dxdebug.mode=coverage ./vendor/phpunit/phpunit/phpunit 

Testing started at 21:32 ...
PHP Fatal error:  Declaration of Hamcrest\Core\CombinableMatcherTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in /var/www/html/vendor/hamcrest/hamcrest-php/tests/Hamcrest/Core/CombinableMatcherTest.php on line 10

Fatal error: Declaration of Hamcrest\Core\CombinableMatcherTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in /var/www/html/vendor/hamcrest/hamcrest-php/tests/Hamcrest/Core/CombinableMatcherTest.php on line 10

Process finished with exit code 255

hamcrest/hamcrest-php: v2.0.1 PHPUnit: 9.5.25 Xdebug v3.1.5 PHP: 8.1.10

LocalHeroPro avatar Oct 10 '22 19:10 LocalHeroPro

To fix this we need to rename all setUp methods into setUpTest methods and annotate them with @before annotation.

If there are tearDown methods, then they must be renamed into tearDownTest methods and annotated with @after annotation.

PRs are welcome. I'm not sure though if PHPUnit 9.x is used in the GitHub Actions workflow.

aik099 avatar Oct 12 '22 05:10 aik099

Wouldn't be all to add only : void after setUp() method?

LocalHeroPro avatar Oct 12 '22 07:10 LocalHeroPro

Wouldn't be all to add only : void after setUp() method?

That won't work in PHP 5.x, which we support.


The PHPUnit changes public method signatures quite often (almost every major release). We can't keep up with that.

Using an annotation-based approach ensures, that the test suite will be compatible with every future major PHPUnit release.

aik099 avatar Oct 12 '22 17:10 aik099

Maybe the way is to create separate branch for EOL versions of PHP and for present one. In that way we have newest features in new one branch and ald ones for obsolete/abandoned ones.

LocalHeroPro avatar Oct 16 '22 09:10 LocalHeroPro

@LocalHeroPro , Thanks for the suggestions, I'll take this into consideration. For now please do as explained in the https://github.com/hamcrest/hamcrest-php/issues/79#issuecomment-1275597569 comment.

aik099 avatar Oct 17 '22 13:10 aik099