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

Fix checks for PHP 8.1 and above #746

Merged
merged 5 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<rule ref="WordPress-Extra">
<exclude name="WordPress.Files.FileName"/>
<exclude name="WordPress.NamingConventions.ValidVariableName"/>
<exclude name="WordPress.NamingConventions.PrefixAllGlobals"/>
rebeccahum marked this conversation as resolved.
Show resolved Hide resolved
<exclude name="Generic.Arrays.DisallowShortArraySyntax"/>
<exclude name="WordPress.PHP.YodaConditions"/>
</rule>
Expand Down
4 changes: 2 additions & 2 deletions bin/unit-tests
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#

if [[ $(php -r 'echo PHP_VERSION_ID;') -ge 80100 ]]; then
"$(pwd)/vendor/bin/phpunit" --filter WordPressVIPMinimum "$(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php" --no-coverage --no-configuration --bootstrap=./tests/bootstrap.php --dont-report-useless-tests $@
"$(pwd)/vendor/bin/phpunit" --filter=WordPressVIPMinimum "$(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php" --no-coverage --no-configuration --bootstrap=./tests/bootstrap.php --dont-report-useless-tests $@
else
"$(pwd)/vendor/bin/phpunit" --filter WordPressVIPMinimum "$(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php" --no-coverage $@
"$(pwd)/vendor/bin/phpunit" --filter=WordPressVIPMinimum "$(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php" --no-coverage $@
Comment on lines -20 to +22
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one surprises me as WPCS itself does not appear to be afflicted by the same issue, which makes me think something else is going on....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does for me. Still the same fatal happening, but the deprecation disappears when adding in the =:

Screenshot 2023-03-07 at 12 16 34

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What version of PHPUnit are you running the tests on ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, IIRC, for PHP 8.1+, this is solved via the --no-configuration bit, so if that's not the case for you, I suspect there is something else going on with your setup.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What version of PHPUnit are you running the tests on ?

7.5.20.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the --no-configuration gets applied correctly ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the Composer script to @php ./vendor/phpunit/phpunit/phpunit --filter WordPress ./vendor/squizlabs/php_codesniffer/tests/AllTests.php --no-configuration and then running it produces even more errors.

Details
PHP Warning:  Undefined global variable $PHP_CODESNIFFER_PEAR in /Users/gary/code/wpcs/vendor/squizlabs/php_codesniffer/tests/AllTests.php on line 12

Warning: Undefined global variable $PHP_CODESNIFFER_PEAR in /Users/gary/code/wpcs/vendor/squizlabs/php_codesniffer/tests/AllTests.php on line 12
PHP Warning:  include_once(CodeSniffer/Core/AllTests.php): Failed to open stream: No such file or directory in /Users/gary/code/wpcs/vendor/squizlabs/php_codesniffer/tests/AllTests.php on line 16

Warning: include_once(CodeSniffer/Core/AllTests.php): Failed to open stream: No such file or directory in /Users/gary/code/wpcs/vendor/squizlabs/php_codesniffer/tests/AllTests.php on line 16
PHP Warning:  include_once(): Failed opening 'CodeSniffer/Core/AllTests.php' for inclusion (include_path='.:/usr/local/Cellar/php@8.1/8.1.13/share/php@8.1/pear') in /Users/gary/code/wpcs/vendor/squizlabs/php_codesniffer/tests/AllTests.php on line 16

Warning: include_once(): Failed opening 'CodeSniffer/Core/AllTests.php' for inclusion (include_path='.:/usr/local/Cellar/php@8.1/8.1.13/share/php@8.1/pear') in /Users/gary/code/wpcs/vendor/squizlabs/php_codesniffer/tests/AllTests.php on line 16
PHP Warning:  include_once(CodeSniffer/Standards/AllSniffs.php): Failed to open stream: No such file or directory in /Users/gary/code/wpcs/vendor/squizlabs/php_codesniffer/tests/AllTests.php on line 17

Warning: include_once(CodeSniffer/Standards/AllSniffs.php): Failed to open stream: No such file or directory in /Users/gary/code/wpcs/vendor/squizlabs/php_codesniffer/tests/AllTests.php on line 17
PHP Warning:  include_once(): Failed opening 'CodeSniffer/Standards/AllSniffs.php' for inclusion (include_path='.:/usr/local/Cellar/php@8.1/8.1.13/share/php@8.1/pear') in /Users/gary/code/wpcs/vendor/squizlabs/php_codesniffer/tests/AllTests.php on line 17

Warning: include_once(): Failed opening 'CodeSniffer/Standards/AllSniffs.php' for inclusion (include_path='.:/usr/local/Cellar/php@8.1/8.1.13/share/php@8.1/pear') in /Users/gary/code/wpcs/vendor/squizlabs/php_codesniffer/tests/AllTests.php on line 17
PHP Fatal error:  Uncaught Error: Class "PHP_CodeSniffer\Tests\Core\AllTests" not found in /Users/gary/code/wpcs/vendor/squizlabs/php_codesniffer/tests/AllTests.php:56
Stack trace:
#0 [internal function]: PHP_CodeSniffer\Tests\PHP_CodeSniffer_AllTests::suite('PHP_CodeSniffer...')
#1 /Users/gary/code/wpcs/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(125): ReflectionMethod->invoke(NULL, 'PHP_CodeSniffer...')
#2 /Users/gary/code/wpcs/vendor/phpunit/phpunit/src/TextUI/Command.php(183): PHPUnit\Runner\BaseTestRunner->getTest('./vendor/squizl...', '/Users/gary/cod...', Array)
#3 /Users/gary/code/wpcs/vendor/phpunit/phpunit/src/TextUI/Command.php(162): PHPUnit\TextUI\Command->run(Array, true)
#4 /Users/gary/code/wpcs/vendor/phpunit/phpunit/phpunit(61): PHPUnit\TextUI\Command::main()
#5 {main}
  thrown in /Users/gary/code/wpcs/vendor/squizlabs/php_codesniffer/tests/AllTests.php on line 56

Fatal error: Uncaught Error: Class "PHP_CodeSniffer\Tests\Core\AllTests" not found in /Users/gary/code/wpcs/vendor/squizlabs/php_codesniffer/tests/AllTests.php:56
Stack trace:
#0 [internal function]: PHP_CodeSniffer\Tests\PHP_CodeSniffer_AllTests::suite('PHP_CodeSniffer...')
#1 /Users/gary/code/wpcs/vendor/phpunit/phpunit/src/Runner/BaseTestRunner.php(125): ReflectionMethod->invoke(NULL, 'PHP_CodeSniffer...')
#2 /Users/gary/code/wpcs/vendor/phpunit/phpunit/src/TextUI/Command.php(183): PHPUnit\Runner\BaseTestRunner->getTest('./vendor/squizl...', '/Users/gary/cod...', Array)
#3 /Users/gary/code/wpcs/vendor/phpunit/phpunit/src/TextUI/Command.php(162): PHPUnit\TextUI\Command->run(Array, true)
#4 /Users/gary/code/wpcs/vendor/phpunit/phpunit/phpunit(61): PHPUnit\TextUI\Command::main()
#5 {main}
  thrown in /Users/gary/code/wpcs/vendor/squizlabs/php_codesniffer/tests/AllTests.php on line 56
Script @php ./vendor/phpunit/phpunit/phpunit --filter WordPress ./vendor/squizlabs/php_codesniffer/tests/AllTests.php --no-configuration handling the run-tests event returned with error code 255

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like this would be better debugged via a videocall with screenshare at some point... ? Feel free to ping me to set it up.

fi
8 changes: 6 additions & 2 deletions tests/RulesetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public function __construct( $ruleset, $expected = [] ) {
$this->phpcs_bin = realpath( $phpcs_bin );
}

// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
printf( 'Testing the ' . $this->ruleset . ' ruleset.' . PHP_EOL );

$output = $this->collect_phpcs_result();

if ( ! is_object( $output ) || empty( $output ) ) {
Expand Down Expand Up @@ -143,11 +146,12 @@ private function collect_phpcs_result() {
}

$shell = sprintf(
'%1$s%2$s --severity=1 --standard=%3$s --report=json ./%3$s/ruleset-test.inc',
$php, // Current PHP executable if avaiable.
'%1$s%2$s --severity=1 --standard=%3$s --report=json --runtime-set minimum_supported_wp_version 0 ./%3$s/ruleset-test.inc',
$php, // Current PHP executable if available.
$this->phpcs_bin,
$this->ruleset
);

// phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.system_calls_shell_exec -- This is test code, not production.
$output = shell_exec( $shell );

Expand Down