PHP Fatal error setUp()
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
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.
Wouldn't be all to add only : void after setUp() method?
Wouldn't be all to add only
: voidafter 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.
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 , 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.