diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 79a6024..3621d3d 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -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 @@ -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\.$`' diff --git a/src/Polyfills/AssertContainsOnly.php b/src/Polyfills/AssertContainsOnly.php index b8478ed..8208ed7 100644 --- a/src/Polyfills/AssertContainsOnly.php +++ b/src/Polyfills/AssertContainsOnly.php @@ -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; /** @@ -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 $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 $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 ); } /** diff --git a/src/Polyfills/AssertIsList.php b/src/Polyfills/AssertIsList.php index f1e55e8..89824e0 100644 --- a/src/Polyfills/AssertIsList.php +++ b/src/Polyfills/AssertIsList.php @@ -2,7 +2,6 @@ namespace Yoast\PHPUnitPolyfills\Polyfills; -use PHPUnit\Framework\Assert; use ReflectionObject; /** @@ -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; }