diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 86261de..4666c00 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -92,11 +92,15 @@ jobs: - name: "Lint PHP files against parse errors - PHP < 7.0" if: ${{ matrix.phpunit == 'auto' && matrix.php < 7.0 }} - run: composer lint-lt71 + run: composer lint-lt70 - - name: "Lint PHP files against parse errors - PHP >= 7.0" - if: ${{ matrix.phpunit == 'auto' && matrix.php >= 7.0 }} - run: composer lint + - name: "Lint PHP files against parse errors - PHP 7.x" + if: ${{ matrix.phpunit == 'auto' && startsWith( matrix.php, '7' ) }} + run: composer lint7 + + - name: "Lint PHP files against parse errors - PHP >= 8.0" + if: ${{ matrix.phpunit == 'auto' && matrix.php >= 8.0 }} + run: composer lint-gte80 - name: Run the unit tests run: composer test diff --git a/.phpcs.xml.dist b/.phpcs.xml.dist index dd6e745..8223ff4 100644 --- a/.phpcs.xml.dist +++ b/.phpcs.xml.dist @@ -50,6 +50,10 @@ + + + + @@ -81,6 +85,13 @@ ############################################################################# --> + + + /src/Exceptions/*Error\.php$ + + /src/Helpers/ResourceHelper\.php$ diff --git a/composer.json b/composer.json index e339d9f..9d0e049 100644 --- a/composer.json +++ b/composer.json @@ -46,12 +46,15 @@ } }, "scripts": { - "lint": [ - "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git" + "lint7": [ + "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git --exclude src/Exceptions/Error.php --exclude src/Exceptions/TypeError.php" ], - "lint-lt71": [ + "lint-lt70": [ "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git --exclude src/TestCases/TestCasePHPUnitGte8.php --exclude src/TestListeners/TestListenerDefaultImplementationPHPUnitGte7.php" ], + "lint-gte80": [ + "@php ./vendor/php-parallel-lint/php-parallel-lint/parallel-lint . -e php --exclude vendor --exclude .git" + ], "check-cs": [ "@php ./vendor/squizlabs/php_codesniffer/bin/phpcs --runtime-set testVersion 5.4-" ], diff --git a/phpunitpolyfills-autoload.php b/phpunitpolyfills-autoload.php index 851188c..5376f7a 100644 --- a/phpunitpolyfills-autoload.php +++ b/phpunitpolyfills-autoload.php @@ -19,6 +19,27 @@ class Autoload { * @return bool */ public static function load( $className ) { + /* + * Polyfill two PHP 7.0 classes. + * The autoloader will only be called for these if these classes don't already + * exist in PHP natively. + */ + if ( $className === 'Error' || $className === 'TypeError' ) { + $file = \realpath( + __DIR__ . \DIRECTORY_SEPARATOR + . 'src' . \DIRECTORY_SEPARATOR + . 'Exceptions' . \DIRECTORY_SEPARATOR + . $className . '.php' + ); + + if ( \file_exists( $file ) === true ) { + require_once $file; + return true; + } + + return false; + } + // Only load classes belonging to this library. if ( \stripos( $className, 'Yoast\PHPUnitPolyfills' ) !== 0 ) { return false; diff --git a/src/Exceptions/Error.php b/src/Exceptions/Error.php new file mode 100644 index 0000000..6a44e67 --- /dev/null +++ b/src/Exceptions/Error.php @@ -0,0 +1,8 @@ +