|
| 1 | +name: PHP Unit Tests |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + # Only run if PHP-related files changed. |
| 6 | + paths: |
| 7 | + - '**.php' |
| 8 | + - 'phpunit.xml.dist' |
| 9 | + - 'phpunit-multisite.xml.dist' |
| 10 | + - 'composer.json' |
| 11 | + - 'composer.lock' |
| 12 | + - 'tests/**' |
| 13 | + branches: |
| 14 | + - master |
| 15 | + - release/* |
| 16 | + pull_request: |
| 17 | + # Only run if PHP-related files changed. |
| 18 | + paths: |
| 19 | + - '**.php' |
| 20 | + - 'phpunit.xml.dist' |
| 21 | + - 'phpunit-multisite.xml.dist' |
| 22 | + - 'composer.json' |
| 23 | + - 'composer.lock' |
| 24 | + - 'tests/**' |
| 25 | + - '.github/workflows/tests-unit-php.yml' |
| 26 | + |
| 27 | +jobs: |
| 28 | + unit-php: |
| 29 | + name: 'PHP ${{ matrix.php }} - WP ${{ matrix.wp }}' |
| 30 | + runs-on: ubuntu-latest |
| 31 | + timeout-minutes: 60 |
| 32 | + services: |
| 33 | + mysql: |
| 34 | + image: mariadb:latest |
| 35 | + env: |
| 36 | + MYSQL_ALLOW_EMPTY_PASSWORD: true |
| 37 | + MYSQL_ROOT_PASSWORD: |
| 38 | + MYSQL_DATABASE: wordpress_test |
| 39 | + ports: |
| 40 | + - 3306 |
| 41 | + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 |
| 42 | + continue-on-error: ${{ matrix.experimental == true }} |
| 43 | + strategy: |
| 44 | + matrix: |
| 45 | + php: ['7.0', '7.4'] |
| 46 | + wp: ['latest'] |
| 47 | + include: |
| 48 | + - php: '7.4' |
| 49 | + wp: 'trunk' |
| 50 | + experimental: true |
| 51 | + |
| 52 | + steps: |
| 53 | + - name: Checkout |
| 54 | + uses: actions/checkout@v2 |
| 55 | + |
| 56 | + - name: Get Composer cache directory |
| 57 | + id: composer-cache |
| 58 | + run: echo "::set-output name=dir::$(composer config cache-files-dir)" |
| 59 | + |
| 60 | + - name: Setup Composer cache |
| 61 | + |
| 62 | + with: |
| 63 | + path: ${{ steps.composer-cache.outputs.dir }} |
| 64 | + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} |
| 65 | + restore-keys: | |
| 66 | + ${{ runner.os }}-composer- |
| 67 | + ${{ runner.os }}- |
| 68 | +
|
| 69 | + # PHP-Scoper only works on PHP 7.2+ and we need to prefix our dependencies to accurately test them. |
| 70 | + # So we temporarily switch PHP versions, do a full install and then remove the package. |
| 71 | + # Then switch back to the PHP version we want to test and delete the vendor directory. |
| 72 | + |
| 73 | + - name: Setup PHP 7.4 |
| 74 | + uses: shivammathur/setup-php@v2 |
| 75 | + with: |
| 76 | + php-version: 7.4 |
| 77 | + tools: composer |
| 78 | + |
| 79 | + - name: Install prefixed dependencies |
| 80 | + run: | |
| 81 | + composer install --prefer-dist --no-suggest --no-progress --no-interaction |
| 82 | + rm -rf vendor/* |
| 83 | +
|
| 84 | + - name: Setup PHP |
| 85 | + uses: shivammathur/setup-php@v2 |
| 86 | + with: |
| 87 | + php-version: ${{ matrix.php }} |
| 88 | + extensions: mysql |
| 89 | + tools: composer, cs2pr |
| 90 | + |
| 91 | + - name: Install dependencies |
| 92 | + run: | |
| 93 | + composer install --prefer-dist --no-suggest --no-progress --no-interaction --no-scripts |
| 94 | + composer dump-autoload --no-interaction |
| 95 | +
|
| 96 | + - name: Shutdown default MySQL service |
| 97 | + run: sudo service mysql stop |
| 98 | + |
| 99 | + - name: Verify MariaDB connection |
| 100 | + run: | |
| 101 | + while ! mysqladmin ping -h"127.0.0.1" -P"${{ job.services.mysql.ports[3306] }}" --silent; do |
| 102 | + sleep 1 |
| 103 | + done |
| 104 | +
|
| 105 | + - name: Set up tests |
| 106 | + run: bash bin/install-wp-tests.sh wordpress_test root '' 127.0.0.1:${{ job.services.mysql.ports['3306'] }} ${{ matrix.wp }} true |
| 107 | + |
| 108 | + # 1. Installs PHPUnit 7.5 and patches it to run on PHP 8. |
| 109 | + # 2. Dumps autoloader so mcaskill/composer-plugin-exclude-files is triggered. |
| 110 | + - name: Update PHPUnit |
| 111 | + run: | |
| 112 | + composer require --dev --ignore-platform-reqs --no-interaction --no-scripts --update-with-all-dependencies phpunit/phpunit:^7.5 |
| 113 | + git apply patches/composer.patch |
| 114 | + composer dump-autoload --no-interaction |
| 115 | + if: ${{ matrix.php == '8.0' }} |
| 116 | + |
| 117 | + - name: Run tests |
| 118 | + run: | |
| 119 | + npm run test:php |
| 120 | + npm run test:php:multisite |
0 commit comments