1
votes

I have Gitlab repo with CI integrated. Tests are passing in my computer but failing in Gitlab, which is throwing an error below. This had been worked till yesterday, but failing now even for the previously passed branches. Anyone has any idea?

Fatal error: Declaration of Symfony\Bundle\FrameworkBundle\Test\KernelTestCase::tearDown() must be compatible with PHPUnit\Framework\TestCase::tearDown(): void in /builds/prolocalisapp/backend/vendor/symfony/framework-bundle/Test/KernelTestCase.php on line 136

2
Seems like PHPUnit has updated to a newer version in CI than you have locally, one which introduces return type hints (PHP 7). Are you not giving it a constraint when installing it? E.g. composer require --dev phpunit/phpunit * will install any version, as opposed to composer require --dev phpunit/phpunit ^5.7 which will only install 5.x releases. PHPUnit 7 is probably the version that introduces return type hinting. - scrowler
Yes, @RobbieAverill is probably right. The newest major version of PHPUnit was released a few days ago. This version adds type hints and return types, which are not supported yed by Symfony's TestCase (which extends the one from PHPUnit). PHPUnit 7 should still be safe. You should see the same issue on your local machine when you update phpunit/phpunit. When you commit the composer.lock and only do a composer install in your CI you should be save from this, but best make sure to restrict phpunit to a version below 8.0 in your composer.json as described above. - dbrumann

2 Answers

1
votes

Do not use the death star version constraint to require PHPUnit, or any other dependency really, in your composer.json file.

1
votes

Thanks everyone for your answers. I didn't have any death star version constraint. The problem was in phpunit.phar version in CI. CI always install the latest version from https://phar.phpunit.de/phpunit.phar and the version phpunit-8.0.1.phar was causing the error. I replaced the URL in .gitlab-ci.sh with an older version https://phar.phpunit.de/phpunit-7.5.2.phar which solved the problem