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/README.md b/README.md index 26353127f24..3dc048244c7 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![CS](https://github.com/Yoast/wordpress-seo/actions/workflows/cs.yml/badge.svg)](https://github.com/Yoast/wordpress-seo/actions/workflows/cs.yml) [![Lint](https://github.com/Yoast/wordpress-seo/actions/workflows/lint.yml/badge.svg)](https://github.com/Yoast/wordpress-seo/actions/workflows/lint.yml) [![JS](https://github.com/Yoast/wordpress-seo/actions/workflows/js.yml/badge.svg)](https://github.com/Yoast/wordpress-seo/actions/workflows/js.yml) +[![Unit Tests](https://github.com/Yoast/wordpress-seo/actions/workflows/unittest.yml/badge.svg)](https://github.com/Yoast/wordpress-seo/actions/workflows/unittest.yml) [![Build Status](https://api.travis-ci.com/Yoast/wordpress-seo.svg?branch=master)](https://travis-ci.com/Yoast/wordpress-seo) [![Stable Version](https://poser.pugx.org/yoast/wordpress-seo/v/stable.svg)](https://packagist.org/packages/yoast/wordpress-seo) [![License](https://poser.pugx.org/yoast/wordpress-seo/license.svg)](https://packagist.org/packages/yoast/wordpress-seo)