Skip to content

Commit

Permalink
Drop support for PHPUnit < 7.5 [5]
Browse files Browse the repository at this point in the history
Remove in-code work-arounds which were in place to support PHPUnit < 7.5.0.
  • Loading branch information
jrfnl committed Jan 14, 2025
1 parent 7fff9a5 commit 01739dd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 82 deletions.
9 changes: 0 additions & 9 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ parameters:
ignoreErrors:
# Level 0
# This is part of the functionality of this library. Ignore.
-
message: '`^Call to an undefined static method Yoast\\PHPUnitPolyfills\\TestCases\\[X]?TestCase::assertInternalType\(\)\.$`'
count: 2
path: src/Polyfills/AssertIsList.php

-
message: '`^Call to an undefined method Yoast\\PHPUnitPolyfills\\TestCases\\[X]?TestCase::expectExceptionMessageRegExp\(\)\.$`'
count: 2
Expand All @@ -42,10 +37,6 @@ parameters:
message: "`^Call to function method_exists\\(\\) with 'PHPUnit\\W+Framework\\W+TestCase' and 'expectDeprecationMe[^']+' will always evaluate to true\\.$`"
count: 4
path: src/Polyfills/ExpectUserDeprecation.php
-
message: "`^Call to function method_exists\\(\\) with 'PHPUnit\\W+Framework\\W+Assert' and 'assertIsArray' will always evaluate to true\\.$`"
count: 2
path: src/Polyfills/AssertIsList.php

-
message: '`^Call to static method PHPUnit\\Framework\\Assert::assertIsArray\(\) with mixed and mixed will always evaluate to false\.$`'
Expand Down
68 changes: 2 additions & 66 deletions src/Polyfills/AssertContainsOnly.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
use PHPUnit\SebastianBergmann\Exporter\Exporter as Exporter_In_Phar_Old;
use PHPUnitPHAR\SebastianBergmann\Exporter\Exporter as Exporter_In_Phar;
use SebastianBergmann\Exporter\Exporter;
use Traversable;
use Yoast\PHPUnitPolyfills\Autoload;
use Yoast\PHPUnitPolyfills\Helpers\ResourceHelper;

/**
Expand Down Expand Up @@ -164,87 +162,25 @@ final public static function assertContainsNotOnlyInt( $haystack, string $messag
/**
* Asserts that $haystack only contains values of type iterable.
*
* {@internal Support for `iterable` was only added to the `IsType` constraint
* in PHPUnit 7.1.0, so this polyfill can't use a direct fall-through to the PHPUnit native
* functionality until the minimum supported PHPUnit version of this library would be PHPUnit 7.1.0.}
*
* @link https://github.com/sebastianbergmann/phpunit/pull/3035 PR which added support for `is_iterable`.
*
* @param iterable<mixed> $haystack The variable to test.
* @param string $message Optional failure message to display.
*
* @return void
*/
final public static function assertContainsOnlyIterable( $haystack, string $message = '' ) {
if ( \version_compare( Autoload::getPHPUnitVersion(), '7.1.0', '>=' ) ) {
// PHPUnit >= 7.1.0.
static::assertContainsOnly( 'iterable', $haystack, true, $message );
}
else {
// PHPUnit 6.x/7.0.0.
$exporter = self::getPHPUnitExporterObjectForContainsOnly();
$msg = \sprintf( 'Failed asserting that %s contains only values of type "iterable".', $exporter->export( $haystack ) );

if ( $message !== '' ) {
$msg = $message . \PHP_EOL . $msg;
}

$hasOnlyIterable = true;
foreach ( $haystack as $value ) {
if ( \is_array( $value ) || $value instanceof Traversable ) {
continue;
}

$hasOnlyIterable = false;
break;
}

static::assertTrue( $hasOnlyIterable, $msg );
}
static::assertContainsOnly( 'iterable', $haystack, true, $message );
}

/**
* Asserts that $haystack does not only contain values of type iterable.
*
* {@internal Support for `iterable` was only added to the `IsType` constraint
* in PHPUnit 7.1.0, so this polyfill can't use a direct fall-through to the PHPUnit native
* functionality until the minimum supported PHPUnit version of this library would be PHPUnit 7.1.0.}
*
* @link https://github.com/sebastianbergmann/phpunit/pull/3035 PR which added support for `is_iterable`.
*
* @param iterable<mixed> $haystack The variable to test.
* @param string $message Optional failure message to display.
*
* @return void
*/
final public static function assertContainsNotOnlyIterable( $haystack, string $message = '' ) {
if ( \function_exists( 'is_iterable' ) === true
&& \version_compare( Autoload::getPHPUnitVersion(), '7.1.0', '>=' )
) {
// PHP >= 7.1 with PHPUnit >= 7.1.0.
static::assertNotContainsOnly( 'iterable', $haystack, true, $message );
}
else {
// PHP < 7.1 or PHPUnit 6.x/7.0.0.
$exporter = self::getPHPUnitExporterObjectForContainsOnly();
$msg = \sprintf( 'Failed asserting that %s does not contain only values of type "iterable".', $exporter->export( $haystack ) );

if ( $message !== '' ) {
$msg = $message . \PHP_EOL . $msg;
}

$hasOnlyIterable = true;
foreach ( $haystack as $value ) {
if ( \is_array( $value ) || $value instanceof Traversable ) {
continue;
}

$hasOnlyIterable = false;
break;
}

static::assertFalse( $hasOnlyIterable, $msg );
}
static::assertNotContainsOnly( 'iterable', $haystack, true, $message );
}

/**
Expand Down
8 changes: 1 addition & 7 deletions src/Polyfills/AssertIsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Yoast\PHPUnitPolyfills\Polyfills;

use PHPUnit\Framework\Assert;
use ReflectionObject;

/**
Expand Down Expand Up @@ -31,12 +30,7 @@ final public static function assertIsList( $array, $message = '' ) {
}

if ( \is_array( $array ) === false ) {
if ( \method_exists( Assert::class, 'assertIsArray' ) ) {
static::assertIsArray( $array, $msg );
return;
}

static::assertInternalType( 'array', $array, $msg );
static::assertIsArray( $array, $msg );
return;
}

Expand Down

0 comments on commit 01739dd

Please sign in to comment.