Skip to content
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

Incompatibility with PhpUnit 9.5.10 #3490

Closed
Koen1999 opened this issue Dec 1, 2021 · 7 comments · Fixed by PHPCSStandards/PHP_CodeSniffer#59
Closed

Incompatibility with PhpUnit 9.5.10 #3490

Koen1999 opened this issue Dec 1, 2021 · 7 comments · Fixed by PHPCSStandards/PHP_CodeSniffer#59

Comments

@Koen1999
Copy link

Koen1999 commented Dec 1, 2021

Describe the bug
PHP Fatal error: Declaration of PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in /home/user/laminas-ldap/vendor/squizlabs/php_codesniffer/tests/Standards/AbstractSniffUnitTest.php on line 55

Custom ruleset
https://github.com/laminas/laminas-coding-standard/blob/2.3.0/src/LaminasCodingStandard/ruleset.xml

To reproduce
Steps to reproduce the behavior:

  1. php7.4 vendor/bin/phpcs --standard=LaminasCodingStandard --colors -p --extensions=php .

PHPCS output here
PHP Fatal error: Declaration of PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest::setUp() must be compatible with PHPUnit\Framework\TestCase::setUp(): void in /home/user/laminas-ldap/vendor/squizlabs/php_codesniffer/tests/Standards/AbstractSniffUnitTest.php on line 55

Versions (please complete the following information):

  • OS: Ubuntu 21.10
  • PHP: 7.4, 8.0, 8.1
  • PHPCS: 3.6.1
  • Standard: LaminasCodingStandard

Additional context

phpunit/phpunit                                9.5.10  The PHP Unit Testing framework.
squizlabs/php_codesniffer                      3.6.1   PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.
slevomat/coding-standard                       7.0.16  Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.
laminas/laminas-coding-standard                2.3.0   Laminas Coding Standard
@jrfnl
Copy link
Contributor

jrfnl commented Dec 1, 2021

This is related to the fact that you are clearly using the PHPCS native test framework to run the sniff tests for an external standard.

It is, of course, perfectly fine to do so and quite common practice, but if you do, you need to abide by the PHPUnit version constraints as set by PHPCS, which are currently "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0".

As for getting things working:

  • The tests will run fine on PHP 7.4 using PHPUnit 7.5.20.
  • For PHP 8.0 (and higher), you need to make sure you are using a Composer installed version of PHPUnit 7.5.20.
    The PHPUnit 7.5.20 PHAR will not work due to it containing outdated dependencies not compatible with PHP 8.0.
  • For PHP 8.1, again, using PHPUnit 7.5.20, you need to use the CLI --no-configuration option and pass any arguments which are normally stored in a phpunit.xml file via the command-line.

Also related to #3395

@Koen1999
Copy link
Author

Koen1999 commented Dec 1, 2021

@jrfnl Thanks for your comment!
As for now it then seems that I cannot support both unit tests and PhpCB using PHP 8.1 given compatibility issues with PHP 8.1 and PhpUnit 7.5.*
I appreciate your effort

@jrfnl
Copy link
Contributor

jrfnl commented Dec 1, 2021

@Koen1999 What do you mean with PhpCB ?

@Koen1999
Copy link
Author

Koen1999 commented Dec 1, 2021

@Koen1999 What do you mean with PhpCB ?

That's a typo, I meant to say PhpCS. This project, the code sniffer.

@jrfnl
Copy link
Contributor

jrfnl commented Dec 1, 2021

Ah, I understand, but the thing is: you can. See my pointers above on how.

@Koen1999
Copy link
Author

Koen1999 commented Dec 1, 2021

Ah, I understand, but the thing is: you can. See my pointers above on how.

Your pointers suggest using PHPUnit 7, but this does not work with certain features of PHP 8.1 when running tests. (sadly, I did not store the example for reference).

https://github.com/sebastianbergmann/phpunit/blob/master/ChangeLog-9.5.md

According to the changelog, you require PhpUnit ^9.5.8 when using PHP 8.1.

@jrfnl
Copy link
Contributor

jrfnl commented Dec 1, 2021

@Koen1999 Running tests based off the PHPCS test framework will work fine on PHP 8.1 with PHPUnit 7.5 as described above. Seriously, PHPCS itself does so and I'm doing it for a number of external standards too.

The only thing which probably won't work well is running code-coverage. In most cases, you'd only run code coverage for a select number of builds anyway, not all builds, so just don't use your PHP 8.1 builds for your code coverage runs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
PHPCS v3 Development
Ready for Release
3 participants