Fix PHP-Scoper & PHPStan issues #6139
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PHP Unit Tests | |
| on: | |
| push: | |
| # Only run if PHP-related files changed. | |
| paths: | |
| - '**.php' | |
| - 'phpunit.xml.dist' | |
| - 'phpunit-multisite.xml.dist' | |
| - 'composer.json' | |
| - 'composer.lock' | |
| - 'tests/phpunit/**' | |
| - 'includes/data/**' | |
| - '.github/workflows/tests-unit-php.yml' | |
| branches: | |
| - main | |
| - release/* | |
| pull_request: | |
| # Only run if PHP-related files changed. | |
| paths: | |
| - '**.php' | |
| - 'phpunit.xml.dist' | |
| - 'phpunit-multisite.xml.dist' | |
| - 'composer.json' | |
| - 'composer.lock' | |
| - 'tests/phpunit/**' | |
| - 'includes/data/**' | |
| - '.github/workflows/tests-unit-php.yml' | |
| permissions: | |
| contents: read | |
| # Cancels all previous workflow runs for pull requests that have not completed. | |
| concurrency: | |
| # The concurrency group contains the workflow name and the (target) branch name. | |
| group: ${{ github.workflow }}-${{ github.head_ref || github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| unit-php: | |
| name: PHP ${{ matrix.php }} - WP ${{ matrix.wp }}${{ matrix.experimental && ' (experimental)' || '' }}${{ matrix.coverage && ' (with coverage)' || '' }}${{ matrix.random && ' (in random order)' || '' }} | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 20 | |
| services: | |
| mysql: | |
| image: mariadb:lts | |
| env: | |
| MARIADB_ALLOW_EMPTY_ROOT_PASSWORD: true | |
| MARIADB_DATABASE: wordpress_test | |
| MARIADB_MYSQL_LOCALHOST_USER: 1 | |
| MARIADB_MYSQL_LOCALHOST_GRANTS: USAGE | |
| ports: | |
| - 3306 | |
| options: --health-cmd="healthcheck.sh --su-mysql --connect --innodb_initialized" --health-interval=10s --health-timeout=5s --health-retries=3 | |
| continue-on-error: ${{ matrix.experimental }} | |
| strategy: | |
| matrix: | |
| php: ['8.4', '8.3', '8.2', '8.1', '8.0'] | |
| wp: ['latest'] | |
| coverage: [false] | |
| experimental: [false] | |
| include: | |
| - php: '8.5' | |
| wp: 'latest' | |
| coverage: true | |
| experimental: false | |
| - php: '8.5' | |
| wp: 'latest' | |
| random: true | |
| experimental: true | |
| - php: '7.4' | |
| wp: '6.6' | |
| experimental: false | |
| - php: '8.5' | |
| wp: 'trunk' | |
| experimental: true | |
| - php: 'nightly' | |
| wp: 'trunk' | |
| experimental: true | |
| steps: | |
| - name: Harden Runner | |
| uses: step-security/harden-runner@5ef0c079ce82195b2a36a210272d6b661572d83e | |
| with: | |
| disable-file-monitoring: true | |
| egress-policy: audit | |
| allowed-endpoints: > | |
| api.github.com:443 | |
| api.wordpress.org:80 | |
| cdn.ampproject.org:443 | |
| develop.svn.wordpress.org:443 | |
| example.com:443 | |
| github.com:443 | |
| objects.githubusercontent.com:443 | |
| packagist.org:443 | |
| raw.github.com:443 | |
| repo.packagist.org:443 | |
| wordpress.org:443 | |
| getcomposer.org:443 | |
| dl.cloudsmith.io:443 | |
| - name: Checkout | |
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd | |
| # PHP-Scoper only works on PHP 7.4+ and we need to prefix our dependencies to accurately test them. | |
| # So we temporarily switch PHP versions, do a full install and then remove the package. | |
| # Then switch back to the PHP version we want to test and delete the vendor directory. | |
| - name: Setup PHP 8.0 | |
| uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 | |
| with: | |
| php-version: latest | |
| tools: composer | |
| - name: Install PHP dependencies | |
| uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 | |
| with: | |
| composer-options: '--prefer-dist --no-progress --no-interaction' | |
| - name: Remove prefixed dependencies | |
| run: rm -rf vendor/* | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 | |
| with: | |
| php-version: ${{ matrix.php }} | |
| extensions: mysql | |
| coverage: ${{ matrix.coverage && 'xdebug' || 'none' }} | |
| tools: composer, cs2pr | |
| - name: Install PHP dependencies | |
| uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 | |
| with: | |
| composer-options: '--prefer-dist --no-progress --no-interaction --no-scripts' | |
| - name: Composer dump autoload | |
| run: composer dump-autoload --no-interaction | |
| - name: Shutdown default MySQL service | |
| run: sudo service mysql stop | |
| - name: Verify MariaDB connection | |
| run: | | |
| while ! mysqladmin ping -h"127.0.0.1" -P"${JOB_SERVICES_MYSQL_3307TH_PORTS}" --silent; do | |
| sleep 1 | |
| done | |
| env: | |
| JOB_SERVICES_MYSQL_3307TH_PORTS: ${{ job.services.mysql.ports[3306] }} | |
| - name: Install svn | |
| run: | | |
| sudo apt update -y --allow-releaseinfo-change | |
| sudo apt install -y subversion | |
| - name: Set up tests | |
| run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1:${JOB_SERVICES_MYSQL_PORTS_3306} ${{ matrix.wp }} true | |
| env: | |
| JOB_SERVICES_MYSQL_PORTS_3306: ${{ job.services.mysql.ports['3306'] }} | |
| - name: Set up problem matchers for PHPUnit | |
| run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" | |
| - name: Run tests | |
| run: | | |
| npm run test:php:unit | |
| npm run test:php:integration:single | |
| npm run test:php:integration:multisite | |
| if: ${{ ! matrix.coverage && ! matrix.random }} | |
| - name: Run tests with coverage | |
| run: | | |
| npm run test:php:unit -- --coverage-clover build/logs/php-coverage.xml | |
| npm run test:php:integration:single -- --coverage-clover build/logs/php-coverage-integration.xml | |
| npm run test:php:integration:multisite -- --coverage-clover build/logs/php-coverage-multisite.xml | |
| if: ${{ matrix.coverage && ! matrix.random }} | |
| - name: Run tests in random order | |
| run: | | |
| npm run test:php:unit -- --order-by random | |
| npm run test:php:integration:single -- --order-by random | |
| npm run test:php:integration:multisite -- --order-by random | |
| if: ${{ matrix.random }} | |
| - name: Upload code coverage report | |
| uses: codecov/codecov-action@671740ac38dd9b0130fbe1cec585b89eea48d3de | |
| with: | |
| files: build/logs/*.xml | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| if: ${{ matrix.coverage }} |