diff --git a/.github/workflows/unittest.yml b/.github/workflows/unittest.yml new file mode 100644 index 00000000000..0cf6db1a4a3 --- /dev/null +++ b/.github/workflows/unittest.yml @@ -0,0 +1,78 @@ +name: Unit Test + +on: + # Run on pushes to select branches and on all pull requests. + push: + branches: + - master + - trunk + - 'release/**' + - 'hotfix/[0-9]+.[0-9]+*' + - 'feature/**' + pull_request: + # Allow manually triggering the workflow. + workflow_dispatch: + +# Cancels all previous workflow runs for the same branch that have not yet completed. +concurrency: + # The concurrency group contains the workflow name and the branch name. + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + unit-test: + runs-on: ubuntu-latest + + strategy: + matrix: + php_version: ['5.6', '7.0', '7.2', '7.4', '8.0', '8.1'] + + name: "Unit Test: PHP ${{ matrix.php_version }}" + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + # The prefix-dependencies task makes use of reflection-based PHP code that only works on PHP > 7.2. + - name: Install PHP 7.x for generating the vendor_prefixed directory and dependency injection + uses: shivammathur/setup-php@v2 + with: + php-version: 7.2 + coverage: none + + - name: Install Composer dependencies, generate vendor_prefixed directory and run dependency injection + uses: ramsey/composer-install@v2 + + # Remove packages which are not PHP cross-version compatible and only used for the prefixing. + # - humbug/php-scoper is only needed to actually do the prefixing, so won't be shipped anyway. + # - league/oauth2-client and its dependencies *are* the packages being prefixed. + - name: Delete dependencies which are not cross-version compatible + run: composer remove --dev --no-scripts humbug/php-scoper league/oauth2-client + + - name: Remove vendor directory + run: rm -rf vendor/* + + - name: Install PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php_version }} + ini-values: zend.assertions=1, error_reporting=-1, display_errors=On + coverage: none + + - name: "Composer: remove PHPUnit root requirement" + run: composer remove --dev phpunit/phpunit --no-update --no-scripts + + # Install dependencies and handle caching in one go. + # - Updates the test utilities (and only those!) to the most appropriate version + # for the PHP version on which the tests will be run. + # @link https://github.com/marketplace/actions/install-composer-dependencies + - name: Install Composer dependencies + uses: ramsey/composer-install@v2 + with: + # Force a `composer update` run. + dependency-versions: "highest" + # But make it selective. + composer-options: "yoast/wp-test-utils --with-dependencies --no-scripts" + + - name: Run unit tests + run: composer test diff --git a/.travis.yml b/.travis.yml index eae71a9fadd..104e997bdfa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -211,22 +211,6 @@ script: vendor/bin/phpunit -c phpunit-integration.xml.dist travis_time_finish && travis_fold end "PHP.integration-tests" fi - - | - if [[ "$PHPUNIT" == "1" && ${TRAVIS_PHP_VERSION:0:1} != "8" && $TRAVIS_PHP_VERSION != "nightly" ]]; then - # PHP < 8 - travis_fold start "PHP.tests" && travis_time_start - vendor/bin/phpunit - travis_time_finish && travis_fold end "PHP.tests" - fi - - | - if [[ "$PHPUNIT" == "1" ]] && [[ ${TRAVIS_PHP_VERSION:0:1} == "8" || $TRAVIS_PHP_VERSION == "nightly" ]]; then - # PHP >= 8 - travis_fold start "PHP.tests" && travis_time_start - travis_retry composer require --dev phpunit/phpunit:"^9.0" --update-with-dependencies --ignore-platform-reqs --no-interaction && - travis_retry composer update yoast/wp-test-utils --with-all-dependencies --ignore-platform-reqs --no-interaction && - vendor/bin/phpunit - travis_time_finish && travis_fold end "PHP.tests" - fi - | if [[ "$COVERAGE" == "1" ]]; then travis_fold start "PHP.coverage" && travis_time_start diff --git a/tests/unit/builders/indexable-post-builder-test.php b/tests/unit/builders/indexable-post-builder-test.php index 9bc7411b54c..88e14e55f8d 100644 --- a/tests/unit/builders/indexable-post-builder-test.php +++ b/tests/unit/builders/indexable-post-builder-test.php @@ -222,6 +222,12 @@ public function test_set_indexable_repository() { * @covers ::build */ public function test_build( $postmeta, $expected_result ) { + // These two expectations should be removed once the underlying issue has been resolved. + if (PHP_VERSION_ID >= 80100) { + $this->expectDeprecation(); + $this->expectDeprecationMessage('Constant FILTER_SANITIZE_STRING is deprecated'); + } + Monkey\Functions\expect( 'get_permalink' )->once()->with( 1 )->andReturn( 'https://permalink' ); Monkey\Functions\expect( 'get_post_custom' )->with( 1 )->andReturn( $postmeta ); Monkey\Functions\expect( 'maybe_unserialize' )->andReturnFirstArg(); diff --git a/tests/unit/conditionals/estimated-reading-time-conditional-test.php b/tests/unit/conditionals/estimated-reading-time-conditional-test.php index 55063d5f36c..f77d11e8b70 100644 --- a/tests/unit/conditionals/estimated-reading-time-conditional-test.php +++ b/tests/unit/conditionals/estimated-reading-time-conditional-test.php @@ -49,6 +49,12 @@ public function set_up() { * @covers ::is_met */ public function test_ajax_elementor_save() { + // These two expectations should be removed once the underlying issue has been resolved. + if (PHP_VERSION_ID >= 80100) { + $this->expectDeprecation(); + $this->expectDeprecationMessage('Constant FILTER_SANITIZE_STRING is deprecated'); + } + // We are in an Ajax request. Monkey\Functions\expect( 'wp_doing_ajax' )->andReturn( true ); @@ -67,6 +73,12 @@ public function test_ajax_elementor_save() { * @covers ::is_met */ public function test_not_post_not_elementor_save() { + // These two expectations should be removed once the underlying issue has been resolved. + if (PHP_VERSION_ID >= 80100) { + $this->expectDeprecation(); + $this->expectDeprecationMessage('Constant FILTER_SANITIZE_STRING is deprecated'); + } + // We are in an Ajax request. Monkey\Functions\expect( 'wp_doing_ajax' )->andReturn( true ); diff --git a/tests/unit/helpers/input-helper-test.php b/tests/unit/helpers/input-helper-test.php index 3669fb2e0c1..1dbb64889be 100644 --- a/tests/unit/helpers/input-helper-test.php +++ b/tests/unit/helpers/input-helper-test.php @@ -36,6 +36,12 @@ public function set_up() { * @covers ::filter */ public function test_filter() { + // These two expectations should be removed once the underlying issue has been resolved. + if (PHP_VERSION_ID >= 80100) { + $this->expectDeprecation(); + $this->expectDeprecationMessage('Constant FILTER_SANITIZE_STRING is deprecated'); + } + $this->assertNull( $this->instance->filter( \INPUT_POST, 'bogus', \FILTER_SANITIZE_STRING ) ); } } diff --git a/tests/unit/main-test.php b/tests/unit/main-test.php index 485db22587e..b2af722cf6d 100644 --- a/tests/unit/main-test.php +++ b/tests/unit/main-test.php @@ -68,6 +68,12 @@ protected function set_up() { * @covers ::get_container */ public function test_surfaces() { + // These two expectations should be removed once the underlying issue has been resolved. + if (PHP_VERSION_ID >= 80100) { + $this->expectDeprecation(); + $this->expectDeprecationMessage('Constant FILTER_SANITIZE_STRING is deprecated'); + } + $container = $this->instance->get_container(); foreach ( $container->getServiceIds() as $service_id ) {