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

4.0 | Drop support for PHP < 7.1 #238

Merged
merged 3 commits into from
Jan 14, 2025
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
8 changes: 2 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

strategy:
matrix:
php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', 'nightly']
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', 'nightly']

continue-on-error: ${{ matrix.php == 'nightly' }}

Expand Down Expand Up @@ -62,12 +62,8 @@ jobs:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

- 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' }}
if: ${{ startsWith( matrix.php, '7' ) }}
run: composer lint7

- name: "Lint PHP files against parse errors - PHP 8.0+"
Expand Down
12 changes: 4 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:

strategy:
matrix:
php: ['7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3', '8.4']
phpunit: ['auto']
coverage: [true]
experimental: [false]
Expand All @@ -43,17 +43,13 @@ jobs:
include:
# Test against a version on the low-end of the PHPUnit versions supported for each PHP version.
# Using the Composer `--prefer-lowest` option is, unfortunately, not viable, as
# it would result PHP 7.0 - 7.4 all using PHPUnit 6.4.4, which is not the intention.
# it would result PHP 7.1 - 7.4 all using PHPUnit 6.4.4, which is not the intention.
# It also would run into trouble with PHP 8.5.12 being used on PHP 8.0+, while the
# 8.5.12 release still contained a bug which makes it incompatible with PHP 8.1+,
# even though it officially allows for it.
#
# Note: PHPUnit 10 is not supported for the PHPUnit Polyfills 3.x branch, so there are
# no builds against PHPUnit 10!
- php: '7.0'
phpunit: '6.4.4'
coverage: true
experimental: false
- php: '7.1'
phpunit: '~6.4.4'
coverage: true
Expand Down Expand Up @@ -208,9 +204,9 @@ jobs:
# This should be sufficient to record the coverage for the PHAR specific code.

# PHPUnit 6 is only supported for PHPUnit 6.4.4-latest on the officially supported PHP versions.
- php: '7.0'
- php: '7.1'
phpunit: '6.4'
- php: '7.0'
- php: '7.1'
phpunit: '6'
- php: '7.2'
phpunit: '6.4'
Expand Down
15 changes: 1 addition & 14 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,6 @@
<exclude-pattern>/src/Helpers/ResourceHelper\.php$</exclude-pattern>
</rule>

<!-- The TestCase for PHPUnit 8+ will only ever be loaded on PHP 7.2+. -->
<!-- The TestListenerDefaultImplementation for PHPUnit 7+ will only ever be loaded on PHP 7.1+. -->
<rule ref="PHPCompatibility.FunctionDeclarations.NewReturnTypeDeclarations.voidFound">
<exclude-pattern>/src/TestCases/TestCasePHPUnitGte8\.php$</exclude-pattern>
<exclude-pattern>/src/TestListeners/TestListenerDefaultImplementationPHPUnitGte7\.php$</exclude-pattern>
</rule>

<!-- TEST CODE -->

<!-- Final classes is irrelevant for test fixtures. -->
Expand Down Expand Up @@ -160,13 +153,7 @@
<exclude-pattern>/tests/Polyfills/Fixtures/*\.php$</exclude-pattern>
</rule>

<!-- These fixtures for the assertEqualObject() tests will only be loaded on PHP 7.1+/8+ respectively. -->
<rule ref="PHPCompatibility.FunctionDeclarations.NewNullableTypes.typeDeclarationFound">
<exclude-pattern>/tests/Polyfills/Fixtures/ValueObjectParamNotRequired\.php$</exclude-pattern>
</rule>
<rule ref="PHPCompatibility.FunctionDeclarations.NewNullableTypes.returnTypeFound">
<exclude-pattern>/tests/Polyfills/Fixtures/ValueObjectNullableReturnType\.php$</exclude-pattern>
</rule>
<!-- These fixtures for the assertEqualObject() tests will only be loaded on PHP 8+. -->
<rule ref="PHPCompatibility.FunctionDeclarations.NewParamTypeDeclarations.UnionTypeFound">
<exclude-pattern>/tests/Polyfills/Fixtures/ValueObjectUnion\.php$</exclude-pattern>
</rule>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit
Requirements
------------

* PHP 7.0 or higher.
* PHP 7.1 or higher.
* [PHPUnit] 6.4 - 9.x and 11.x (automatically required via Composer).

[PHPUnit]: https://packagist.org/packages/phpunit/phpunit
Expand Down
8 changes: 2 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"security": "https://github.com/Yoast/PHPUnit-Polyfills/security/policy"
},
"require": {
"php": ">=7.0",
"php": ">=7.1",
"phpunit/phpunit": "^6.4.4 || ^7.0 || ^8.0 || ^9.0 || ^11.0"
},
"require-dev": {
Expand Down Expand Up @@ -61,14 +61,11 @@
"lint7": [
"@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude .git --exclude tests/Polyfills/Fixtures/ValueObjectUnion.php --exclude tests/Polyfills/Fixtures/ValueObjectUnionReturnType.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/ValueObjectParamNotRequired.php --exclude tests/Polyfills/Fixtures/ValueObjectNullableReturnType.php --exclude tests/Polyfills/Fixtures/ValueObjectUnion.php --exclude tests/Polyfills/Fixtures/ValueObjectUnionReturnType.php"
],
"lint-gte80": [
"@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --show-deprecated --exclude vendor --exclude .git"
],
"check-cs": [
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --runtime-set testVersion 7.0-"
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --runtime-set testVersion 7.1-"
],
"fix-cs": [
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf"
Expand All @@ -88,7 +85,6 @@
},
"scripts-descriptions": {
"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-gte80": "Check the PHP files for parse errors. (PHP 8.0+)",
"check-cs": "Check the PHP files for code style violations and best practices.",
"fix-cs": "Auto-fix code style violations in the PHP files.",
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
phpVersion: 70100 # Needs to be 70100 or higher... sigh...
phpVersion: 70100
level: 9
bootstrapFiles:
- phpstan-bootstrap.php
Expand Down
46 changes: 6 additions & 40 deletions src/Helpers/ComparatorValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use ReflectionNamedType;
use ReflectionObject;
use ReflectionType;
use Yoast\PHPUnitPolyfills\Exceptions\InvalidComparisonMethodException;

/**
Expand Down Expand Up @@ -82,33 +81,15 @@ public static function isValid( $expected, $actual, $method = 'equals' ) {

$returnType = $reflMethod->getReturnType();

if ( \class_exists( 'ReflectionNamedType' ) ) {
// PHP >= 7.1: guard against union/intersection return types.
if ( ( $returnType instanceof ReflectionNamedType ) === false ) {
throw new InvalidComparisonMethodException( $returnTypeError );
}
}
elseif ( ( $returnType instanceof ReflectionType ) === false ) {
/*
* PHP 7.0.
* Checking for `ReflectionType` will not throw an error on union types,
* but then again union types are not supported on PHP 7.0.
*/
if ( ( $returnType instanceof ReflectionNamedType ) === false ) {
throw new InvalidComparisonMethodException( $returnTypeError );
}

if ( $returnType->allowsNull() === true ) {
throw new InvalidComparisonMethodException( $returnTypeError );
}

if ( \method_exists( $returnType, 'getName' ) ) {
// PHP >= 7.1.
if ( $returnType->getName() !== 'bool' ) {
throw new InvalidComparisonMethodException( $returnTypeError );
}
}
elseif ( (string) $returnType !== 'bool' ) {
// PHP 7.0.
if ( $returnType->getName() !== 'bool' ) {
throw new InvalidComparisonMethodException( $returnTypeError );
}

Expand Down Expand Up @@ -148,27 +129,12 @@ public static function isValid( $expected, $actual, $method = 'equals' ) {
}

$type = $reflParameter->getType();
if ( \class_exists( 'ReflectionNamedType' ) ) {
// PHP >= 7.1.
if ( ( $type instanceof ReflectionNamedType ) === false ) {
throw new InvalidComparisonMethodException( $noDeclaredTypeError );
}

$typeName = $type->getName();
}
else {
/*
* PHP 7.0.
* Checking for `ReflectionType` will not throw an error on union types,
* but then again union types are not supported on PHP 7.0.
*/
if ( ( $type instanceof ReflectionType ) === false ) {
throw new InvalidComparisonMethodException( $noDeclaredTypeError );
}

$typeName = (string) $type;
if ( ( $type instanceof ReflectionNamedType ) === false ) {
throw new InvalidComparisonMethodException( $noDeclaredTypeError );
}

$typeName = $type->getName();

/*
* Validate that the $expected object complies with the declared parameter type.
*/
Expand Down
6 changes: 1 addition & 5 deletions src/Helpers/ResourceHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,11 @@ public static function isResourceStateReliable( $actual ) {
* correctly.
*
* Version ranges based on {@link https://3v4l.org/tc4fE}.
* 7.0.8 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.21, 7.4.0 - 7.4.9
* 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.21, 7.4.0 - 7.4.9
*
* @return bool
*/
public static function isIncompatiblePHPForLibXMLResources() {
if ( \PHP_VERSION_ID >= 70008 && \PHP_VERSION_ID < 70034 ) {
return true;
}

if ( \PHP_VERSION_ID >= 70100 && \PHP_VERSION_ID < 70134 ) {
return true;
}
Expand Down
8 changes: 3 additions & 5 deletions src/Polyfills/AssertContainsOnly.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,12 @@ final public static function assertContainsNotOnlyInt( $haystack, string $messag
* @return void
*/
final public static function assertContainsOnlyIterable( $haystack, string $message = '' ) {
if ( \function_exists( 'is_iterable' ) === true
&& \version_compare( Autoload::getPHPUnitVersion(), '7.1.0', '>=' )
) {
// PHP >= 7.1 with PHPUnit >= 7.1.0.
if ( \version_compare( Autoload::getPHPUnitVersion(), '7.1.0', '>=' ) ) {
// PHPUnit >= 7.1.0.
static::assertContainsOnly( 'iterable', $haystack, true, $message );
}
else {
// PHP < 7.1 or PHPUnit 6.x/7.0.0.
// PHPUnit 6.x/7.0.0.
$exporter = self::getPHPUnitExporterObjectForContainsOnly();
$msg = \sprintf( 'Failed asserting that %s contains only values of type "iterable".', $exporter->export( $haystack ) );

Expand Down
20 changes: 6 additions & 14 deletions tests/Polyfills/AssertObjectEqualsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionMessageMatches;
use Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ChildValueObject;
use Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObject;
use Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObjectNullableReturnType;
use Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObjectParamNotRequired;
use Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObjectUnion;
use Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObjectUnionReturnType;

Expand Down Expand Up @@ -237,13 +235,10 @@ public function testAssertObjectEqualsFailsOnNonNamedTypeReturnType() {
/**
* Verify that the assertObjectEquals() method throws an error when the declared return type is nullable.
*
* @requires PHP 7.1
*
* @return void
*/
#[RequiresPhp( '7.1' )]
public function testAssertObjectEqualsFailsOnNullableReturnType() {
$msg = 'Comparison method Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObjectNullableReturnType::equalsNullableReturnType() does not declare bool return type.';
$msg = 'Comparison method Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObject::equalsNullableReturnType() does not declare bool return type.';

$exception = self::COMPARATOR_EXCEPTION;
if ( \class_exists( ComparisonMethodDoesNotDeclareBoolReturnTypeException::class ) ) {
Expand All @@ -254,8 +249,8 @@ public function testAssertObjectEqualsFailsOnNullableReturnType() {
$this->expectException( $exception );
$this->expectExceptionMessage( $msg );

$expected = new ValueObjectNullableReturnType( 100 );
$actual = new ValueObjectNullableReturnType( 100 );
$expected = new ValueObject( 100 );
$actual = new ValueObject( 100 );
$this->assertObjectEquals( $expected, $actual, 'equalsNullableReturnType' );
}

Expand Down Expand Up @@ -306,13 +301,10 @@ public function testAssertObjectEqualsFailsOnMethodAllowsForMoreParams() {
/**
* Verify that the assertObjectEquals() method throws an error when the $method is not a required parameter.
*
* @requires PHP 7.1
*
* @return void
*/
#[RequiresPhp( '7.1' )]
public function testAssertObjectEqualsFailsOnMethodParamNotRequired() {
$msg = 'Comparison method Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObjectParamNotRequired::equalsParamNotRequired() does not declare exactly one parameter.';
$msg = 'Comparison method Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObject::equalsParamNotRequired() does not declare exactly one parameter.';

$exception = self::COMPARATOR_EXCEPTION;
if ( \class_exists( ComparisonMethodDoesNotDeclareExactlyOneParameterException::class ) ) {
Expand All @@ -323,8 +315,8 @@ public function testAssertObjectEqualsFailsOnMethodParamNotRequired() {
$this->expectException( $exception );
$this->expectExceptionMessage( $msg );

$expected = new ValueObjectParamNotRequired( 'test' );
$actual = new ValueObjectParamNotRequired( 'test' );
$expected = new ValueObject( 'test' );
$actual = new ValueObject( 'test' );
$this->assertObjectEquals( $expected, $actual, 'equalsParamNotRequired' );
}

Expand Down
20 changes: 6 additions & 14 deletions tests/Polyfills/AssertObjectNotEqualsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionMessageMatches;
use Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ChildValueObject;
use Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObject;
use Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObjectNullableReturnType;
use Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObjectParamNotRequired;
use Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObjectUnion;
use Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObjectUnionReturnType;

Expand Down Expand Up @@ -243,13 +241,10 @@ public function testAssertObjectNotEqualsFailsOnNonNamedTypeReturnType() {
/**
* Verify that the assertObjectNotEquals() method throws an error when the declared return type is nullable.
*
* @requires PHP 7.1
*
* @return void
*/
#[RequiresPhp( '7.1' )]
public function testAssertObjectNotEqualsFailsOnNullableReturnType() {
$msg = 'Comparison method Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObjectNullableReturnType::equalsNullableReturnType() does not declare bool return type.';
$msg = 'Comparison method Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObject::equalsNullableReturnType() does not declare bool return type.';

$exception = self::COMPARATOR_EXCEPTION;
if ( \class_exists( ComparisonMethodDoesNotDeclareBoolReturnTypeException::class )
Expand All @@ -262,8 +257,8 @@ public function testAssertObjectNotEqualsFailsOnNullableReturnType() {
$this->expectException( $exception );
$this->expectExceptionMessage( $msg );

$expected = new ValueObjectNullableReturnType( 100 );
$actual = new ValueObjectNullableReturnType( 250 );
$expected = new ValueObject( 100 );
$actual = new ValueObject( 250 );
$this->assertObjectNotEquals( $expected, $actual, 'equalsNullableReturnType' );
}

Expand Down Expand Up @@ -318,13 +313,10 @@ public function testAssertObjectNotEqualsFailsOnMethodAllowsForMoreParams() {
/**
* Verify that the assertObjectNotEquals() method throws an error when the $method is not a required parameter.
*
* @requires PHP 7.1
*
* @return void
*/
#[RequiresPhp( '7.1' )]
public function testAssertObjectNotEqualsFailsOnMethodParamNotRequired() {
$msg = 'Comparison method Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObjectParamNotRequired::equalsParamNotRequired() does not declare exactly one parameter.';
$msg = 'Comparison method Yoast\PHPUnitPolyfills\Tests\Polyfills\Fixtures\ValueObject::equalsParamNotRequired() does not declare exactly one parameter.';

$exception = self::COMPARATOR_EXCEPTION;
if ( \class_exists( ComparisonMethodDoesNotDeclareExactlyOneParameterException::class )
Expand All @@ -337,8 +329,8 @@ public function testAssertObjectNotEqualsFailsOnMethodParamNotRequired() {
$this->expectException( $exception );
$this->expectExceptionMessage( $msg );

$expected = new ValueObjectParamNotRequired( 'test' );
$actual = new ValueObjectParamNotRequired( 'different' );
$expected = new ValueObject( 'test' );
$actual = new ValueObject( 'different' );
$this->assertObjectNotEquals( $expected, $actual, 'equalsParamNotRequired' );
}

Expand Down
Loading
Loading