Add GitHub Actions workflow for PHP unit tests (#197) #10
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: | |
| branches: | |
| - trunk | |
| paths: | |
| - '**.php' | |
| - composer.json | |
| - composer.lock | |
| - phpunit.xml.dist | |
| - tests/** | |
| - .github/workflows/php-unit-tests.yml | |
| pull_request: | |
| paths: | |
| - '**.php' | |
| - composer.json | |
| - composer.lock | |
| - phpunit.xml.dist | |
| - tests/** | |
| - .github/workflows/php-unit-tests.yml | |
| workflow_dispatch: | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| UnitTests: | |
| name: PHP unit tests - PHP ${{ matrix.php }}, WP ${{ matrix.wp-version }} | |
| runs-on: ubuntu-latest | |
| env: | |
| WP_CORE_DIR: '/tmp/wordpress/src' | |
| WP_TESTS_DIR: '/tmp/wordpress/tests/phpunit' | |
| strategy: | |
| matrix: | |
| php: ['7.4', '8.0', '8.2', '8.4'] | |
| wp-version: ['latest'] | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: ${{ matrix.php }} | |
| extensions: mbstring, intl, mysql | |
| coverage: none | |
| tools: composer | |
| - name: Setup MySQL | |
| uses: mirromutth/mysql-action@v1.1 | |
| with: | |
| mysql version: '8.0' | |
| mysql database: 'wordpress_test' | |
| mysql root password: 'root' | |
| - name: Install Composer dependencies | |
| run: composer install --prefer-dist --no-progress | |
| - name: Install SVN (used for installing WP versions) | |
| run: sudo apt-get update && sudo apt-get install -y subversion | |
| - name: Install WP tests | |
| run: echo "y" | bash bin/install-wp-tests.sh wordpress_test root root 127.0.0.1 ${{ matrix.wp-version }} | |
| - name: Install WooCommerce | |
| run: | | |
| mkdir -p /tmp/wordpress/src/wp-content/plugins | |
| cd /tmp/wordpress/src/wp-content/plugins | |
| wget https://downloads.wordpress.org/plugin/woocommerce.latest-stable.zip | |
| unzip -q woocommerce.latest-stable.zip | |
| rm woocommerce.latest-stable.zip | |
| - name: Run PHP unit tests | |
| run: composer test-unit |