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

Tests: tweaks to work round PHP 8.4 deprecation #159

Merged
merged 1 commit into from
Apr 4, 2024
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
16 changes: 12 additions & 4 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,18 @@ jobs:
if: ${{ matrix.php < 7.0 }}
run: composer lint-lt70

- name: "Lint PHP files against parse errors - PHP 7.x"
if: ${{ startsWith( matrix.php, '7' ) }}
- name: "Lint PHP files against parse errors - PHP 7.0"
if: ${{ matrix.php == '7.0' }}
run: composer lint70

- name: "Lint PHP files against parse errors - PHP 7.1 - 7.4"
if: ${{ startsWith( matrix.php, '7' ) && matrix.php != '7.0' }}
run: composer lint7

- name: "Lint PHP files against parse errors - PHP >= 8.0"
if: ${{ matrix.php >= 8.0 }}
- name: "Lint PHP files against parse errors - PHP 8.0 - 8.3"
if: ${{ matrix.php >= 8.0 && matrix.php < 8.4 }}
run: composer lint-gte80

- name: "Lint PHP files against parse errors - PHP >= 8.4"
if: ${{ matrix.php >= 8.4 }}
run: composer lint-gte84
3 changes: 3 additions & 0 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@
<exclude-pattern>/tests/Polyfills/Fixtures/ValueObjectUnion\.php$</exclude-pattern>
<exclude-pattern>/tests/Polyfills/Fixtures/ValueObjectUnionNoReturnType\.php$</exclude-pattern>
</rule>
<rule ref="PHPCompatibility.FunctionDeclarations.NewNullableTypes.typeDeclarationFound">
<exclude-pattern>/tests/Polyfills/Fixtures/ValueObject\.php$</exclude-pattern>
</rule>
<rule ref="PHPCompatibility.Operators.NewOperators.t_spaceshipFound">
<exclude-pattern>/tests/Polyfills/Fixtures/ValueObject\.php$</exclude-pattern>
</rule>
Expand Down
12 changes: 10 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,18 @@
"lint7": [
"@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude .git --exclude src/Exceptions/Error.php --exclude src/Exceptions/TypeError.php --exclude tests/Polyfills/Fixtures/ValueObjectUnion.php --exclude tests/Polyfills/Fixtures/ValueObjectUnionNoReturnType.php"
],
"lint70": [
"@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude .git --exclude src/Exceptions/Error.php --exclude src/Exceptions/TypeError.php --exclude tests/Polyfills/Fixtures/ValueObject.php --exclude tests/Polyfills/Fixtures/ValueObjectUnion.php --exclude tests/Polyfills/Fixtures/ValueObjectUnionNoReturnType.php"
],
"lint-lt70": [
"@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude .git --exclude src/TestCases/TestCasePHPUnitGte8.php --exclude src/TestListeners/TestListenerDefaultImplementationPHPUnitGte7.php --exclude tests/Polyfills/Fixtures/ChildValueObject.php --exclude tests/Polyfills/Fixtures/ValueObject.php --exclude tests/Polyfills/Fixtures/ValueObjectUnion.php --exclude tests/Polyfills/Fixtures/ValueObjectUnionNoReturnType.php"
],
"lint-gte80": [
"@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude .git"
],
"lint-gte84": [
"@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude .git --exclude tests/Polyfills/Fixtures/ValueObjectNoReturnType.php"
],
"check-cs": [
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --runtime-set testVersion 5.4-"
],
Expand All @@ -83,9 +89,11 @@
]
},
"scripts-descriptions": {
"lint7": "Check the PHP files for parse errors. (PHP 7.x)",
"lint7": "Check the PHP files for parse errors. (PHP 7.1 - 7.4)",
"lint70": "Check the PHP files for parse errors. (PHP 7.0)",
"lint-lt70": "Check the PHP files for parse errors. (PHP < 7.0)",
"lint-gte80": "Check the PHP files for parse errors. (PHP 8.0+)",
"lint-gte80": "Check the PHP files for parse errors. (PHP 8.0 - 8.3)",
"lint-gte84": "Check the PHP files for parse errors. (PHP 8.4+)",
"check-cs": "Check the PHP files for code style violations and best practices.",
"fix-cs": "Auto-fix code style violations in the PHP files.",
"test": "Run the unit tests without code coverage.",
Expand Down
6 changes: 6 additions & 0 deletions tests/Polyfills/AssertObjectEqualsPHPUnitLt940Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
* would make a test incompatible with the PHPUnit 9.4.0+ native implementation
* of the assertion.
*
* These tests are not run on PHP 8.4+ as only PHPUnit 9.5+ is compatible with PHP 8.4.
*
* @covers \Yoast\PHPUnitPolyfills\Polyfills\AssertObjectEquals
*/
final class AssertObjectEqualsPHPUnitLt940Test extends TestCase {
Expand Down Expand Up @@ -54,6 +56,10 @@ public function maybeSkipTest() {
if ( \version_compare( PHPUnit_Version::id(), '9.4.0', '>=' ) ) {
$this->markTestSkipped( 'This test can not be run with the PHPUnit native implementation of assertObjectEquals()' );
}

if ( \version_compare( \PHP_VERSION_ID, '8.3.99', '>' ) ) {
$this->markTestSkipped( 'This test can not be run on PHP 8.4 or higher as PHPUnit < 9.4.0 is not compatible with PHP 8.4' );
}
}

/**
Expand Down
8 changes: 6 additions & 2 deletions tests/Polyfills/AssertObjectEqualsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@
* Due to the use of return types in the classes under test (fixtures), these
* tests can only run on PHP 7.0 and higher.
*
* And due to the implicitly nullable parameter deprecation in PHP 8.4 requiring a
* nullable type for one of the tests, the minimum PHP version for running this
* version of the tests has been set to PHP 7.1.
*
* The `AssertObjectEqualsPHPUnitLt940Test` class mirrors this test class
* and tests the polyfill method for PHP < 7.0.
* and tests the polyfill method for PHP < 7.1.
*
* @covers \Yoast\PHPUnitPolyfills\Polyfills\AssertObjectEquals
*
* @requires PHP 7.0
* @requires PHP 7.1
*/
final class AssertObjectEqualsTest extends TestCase {

Expand Down
2 changes: 1 addition & 1 deletion tests/Polyfills/Fixtures/ValueObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function equalsTwoParams( $other, $param ): bool {
*
* @return bool
*/
public function equalsParamNotRequired( self $other = null ): bool {
public function equalsParamNotRequired( ?self $other = null ): bool {
return ( $this->value === $other->value );
}

Expand Down
2 changes: 1 addition & 1 deletion tests/TestCases/TestCaseTestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function testAvailabilityEqualToSpecializations() {
/**
* Verify availability of trait polyfilled PHPUnit methods [14].
*
* @requires PHP 7.0
* @requires PHP 7.1
*
* @return void
*/
Expand Down