Skip to content

Commit

Permalink
Merge pull request #313 from Yoast/feature/integration-tests
Browse files Browse the repository at this point in the history
Introduce integration tests and run them in GH actions
  • Loading branch information
jrfnl authored Oct 4, 2023
2 parents 000aff6 + 4c62e97 commit 4642e1c
Show file tree
Hide file tree
Showing 39 changed files with 525 additions and 69 deletions.
33 changes: 17 additions & 16 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
# https://www.reddit.com/r/PHP/comments/2jzp6k/i_dont_need_your_tests_in_my_production
# https://blog.madewithlove.be/post/gitattributes/
#
/.cache export-ignore
/.github export-ignore
/config export-ignore
/svn-assets export-ignore
/tests export-ignore
.babelrc export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.phpcs.xml.dist export-ignore
CHANGELOG export-ignore
Gruntfile.js export-ignore
LICENSE export-ignore
package.json export-ignore
phpunit.xml.dist export-ignore
README.md export-ignore
/.cache export-ignore
/.github export-ignore
/config export-ignore
/svn-assets export-ignore
/tests export-ignore
.babelrc export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.phpcs.xml.dist export-ignore
CHANGELOG export-ignore
Gruntfile.js export-ignore
LICENSE export-ignore
package.json export-ignore
phpunit.xml.dist export-ignore
phpunit-wp.xml.dist export-ignore
README.md export-ignore

#
# Auto detect text files and perform LF normalization
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/cs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ on:
- 'LICENSE'
- 'package.json'
- 'phpunit.xml.dist'
- 'phpunit-wp.xml.dist'
- 'yarn.lock'
- '.github/dependabot.yml'
- '.github/workflows/deploy.yml'
Expand All @@ -42,6 +43,7 @@ on:
- 'LICENSE'
- 'package.json'
- 'phpunit.xml.dist'
- 'phpunit-wp.xml.dist'
- 'yarn.lock'
- '.github/dependabot.yml'
- '.github/workflows/deploy.yml'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ on:
- '.phpcs.xml.dist'
- 'phpcs.xml.dist'
- 'phpunit.xml.dist'
- 'phpunit-wp.xml.dist'
- 'yarn.lock'
- '.github/dependabot.yml'
- '.github/workflows/cs.yml'
Expand All @@ -50,6 +51,7 @@ on:
- '.phpcs.xml.dist'
- 'phpcs.xml.dist'
- 'phpunit.xml.dist'
- 'phpunit-wp.xml.dist'
- 'yarn.lock'
- '.github/dependabot.yml'
- '.github/workflows/cs.yml'
Expand Down
126 changes: 126 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ on:
- '.github/workflows/deploy.yml'
- '.github/workflows/lint.yml'
- 'config/**'
- '!config/scripts/install-wp-tests.sh'
- 'css/**'
- 'js/**'
pull_request:
Expand All @@ -54,6 +55,7 @@ on:
- '.github/workflows/deploy.yml'
- '.github/workflows/lint.yml'
- 'config/**'
- '!config/scripts/install-wp-tests.sh'
- 'css/**'
- 'js/**'
# Allow manually triggering the workflow.
Expand Down Expand Up @@ -131,6 +133,130 @@ jobs:
COVERALLS_FLAG_NAME: php-${{ matrix.php_version }}
run: php-coveralls -v -x build/logs/clover.xml

integration-test:
runs-on: ubuntu-latest

strategy:
matrix:
include:
- php_version: "7.2"
wp_version: "6.2"
multisite: true
coverage: true

- php_version: "7.3"
wp_version: "trunk"
multisite: true
coverage: false

- php_version: "7.4"
wp_version: "latest"
multisite: false
coverage: false

- php_version: "8.0"
wp_version: "6.2"
multisite: false
coverage: false

- php_version: "8.1"
wp_version: "latest"
multisite: true
coverage: false

- php_version: "8.2"
wp_version: "6.3"
multisite: true
coverage: true

name: "Integration Test: PHP ${{ matrix.php_version }} | WP ${{ matrix.wp_version }}${{ matrix.multisite == true && ' (+ ms)' || '' }}"

# Allow builds to fail on as-of-yet unreleased WordPress versions.
continue-on-error: ${{ matrix.wp_version == 'trunk' }}

services:
mysql:
# Use MySQL 5.6 for PHP 7.2, use MySQL 5.7 for PHP 7.3 < 7.4, otherwise MySQL 8.0.
# Also see: https://core.trac.wordpress.org/ticket/52496
image: mysql:${{ ( matrix.php_version == '7.2' && '5.6' ) || ( matrix.php_version < '7.4' && '5.7' ) || '8.0' }}
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=10s --health-retries=10

steps:
- name: Checkout code
uses: actions/checkout@v3

- 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: ${{ matrix.coverage == true && 'xdebug' || 'none' }}

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-composer-dependencies
- name: Install Composer dependencies
uses: ramsey/composer-install@v2
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")

- name: Install WP
shell: bash
run: config/scripts/install-wp-tests.sh wordpress_test root '' 127.0.0.1:3306 ${{ matrix.wp_version }}

- name: Run integration tests - single site
if: ${{ matrix.coverage == false }}
run: composer integration-test

- name: Run integration tests - multisite
if: ${{ matrix.multisite == true && matrix.coverage == false }}
run: composer integration-test
env:
WP_MULTISITE: 1

- name: Run integration tests with code coverage - single site
if: ${{ matrix.coverage == true }}
run: composer integration-coverage

- name: Run integration tests with code coverage - multisite
if: ${{ matrix.multisite == true && matrix.coverage == true }}
run: composer integration-coverage -- --coverage-clover build/logs/clover-integration-ms.xml
env:
WP_MULTISITE: 1

# PHP Coveralls doesn't fully support PHP 8.x yet, so switch the PHP version.
- name: Switch to PHP 7.4
if: ${{ success() && matrix.coverage == true && startsWith( matrix.php_version, '8' ) }}
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
coverage: none

# Global install is used to prevent a conflict with the local composer.lock in PHP 8.0+.
- name: Install Coveralls
if: ${{ success() && matrix.coverage == true }}
run: composer global require php-coveralls/php-coveralls:"^2.5.3" --no-interaction

- name: Upload coverage results to Coveralls
if: ${{ success() && matrix.coverage == true }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: intgr-php-${{ matrix.php_version }}-wp-${{ matrix.wp_version }}
run: php-coveralls -v -x build/logs/clover-integration.xml

- name: Upload coverage results to Coveralls - multisite
if: ${{ success() && matrix.multisite == true && matrix.coverage == true }}
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
COVERALLS_PARALLEL: true
COVERALLS_FLAG_NAME: intgr-php-${{ matrix.php_version }}-wp-${{ matrix.wp_version }}-ms
run: php-coveralls -v -x build/logs/clover-integration-ms.xml

coveralls-finish:
needs: unit
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ composer.lock
phpcs.xml
.cache/phpcs.cache
phpunit.xml
phpunit-integration.xml
phpunit-wp.xml
.phpunit.result.cache

############
Expand Down
4 changes: 2 additions & 2 deletions .phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

<!-- TEST CODE -->

<!-- Valid usage: For testing purposes, some non-prefixed globals are being created, which is fine. -->
<!-- Valid usage: For testing purposes, some non-prefixed global constants are being created, which is fine. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound">
<exclude-pattern>/tests/*\.php$</exclude-pattern>
</rule>
Expand All @@ -118,7 +118,7 @@
<exclude-pattern>/tests/*</exclude-pattern>
</rule>

<!-- These tests are not run within the context of a WP install, so overwritting globals is fine. -->
<!-- These tests are not run within the context of a WP install, so overwriting globals is fine. -->
<rule ref="WordPress.WP.GlobalVariablesOverride">
<exclude-pattern>/tests/*</exclude-pattern>
</rule>
Expand Down
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
],
"coverage": [
"@php ./vendor/phpunit/phpunit/phpunit"
],
"integration-test": [
"@php ./vendor/phpunit/phpunit/phpunit -c phpunit-wp.xml.dist --no-coverage"
],
"integration-coverage": [
"@php ./vendor/phpunit/phpunit/phpunit -c phpunit-wp.xml.dist"
]
},
"config": {
Expand Down
Loading

0 comments on commit 4642e1c

Please sign in to comment.