-
Notifications
You must be signed in to change notification settings - Fork 179
153 lines (132 loc) · 4.62 KB
/
tests-unit-php.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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'
jobs:
unit-php:
name: 'PHP ${{ matrix.php }} - WP ${{ matrix.wp }}'
runs-on: ubuntu-latest
timeout-minutes: 60
services:
mysql:
image: mariadb:latest
env:
MYSQL_ALLOW_EMPTY_PASSWORD: true
MYSQL_ROOT_PASSWORD:
MYSQL_DATABASE: wordpress_test
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
continue-on-error: ${{ matrix.experimental == true }}
strategy:
matrix:
php: ['7.0', '5.6']
wp: ['latest']
coverage: [false]
include:
- php: '7.4'
wp: 'latest'
coverage: true
- php: '5.6'
wp: '5.3'
- php: '8.0'
wp: 'latest'
- php: '7.4'
wp: 'trunk'
experimental: true
steps:
- name: Cancel previous
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}
- name: Checkout
uses: actions/checkout@v2
- name: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Setup Composer cache
uses: pat-s/[email protected]
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
${{ runner.os }}-
# PHP-Scoper only works on PHP 7.2+ 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 7.4
uses: shivammathur/setup-php@v2
with:
php-version: 7.4
tools: composer
- name: Install prefixed dependencies
run: |
composer install --prefer-dist --no-suggest --no-progress --no-interaction
rm -rf vendor/*
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mysql
coverage: xdebug
tools: composer, cs2pr
- name: Install dependencies
run: |
composer install --prefer-dist --no-suggest --no-progress --no-interaction --no-scripts
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.ports[3306] }}" --silent; do
sleep 1
done
- 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
# 1. Installs PHPUnit 7.5 and patches it to run on PHP 8.
# 2. Dumps autoloader so mcaskill/composer-plugin-exclude-files is triggered.
- name: Update PHPUnit
run: |
composer require --dev --ignore-platform-reqs --no-interaction --no-scripts --update-with-all-dependencies phpunit/phpunit:^7.5
git apply patches/composer.patch
composer dump-autoload --no-interaction
if: ${{ matrix.php == '8.0' }}
- name: Run tests
run: |
npm run test:php
npm run test:php:multisite
if: ${{ ! matrix.coverage }}
- name: Run tests with coverage
run: |
npm run test:php -- --coverage-clover build/logs/php-coverage.xml
npm run test:php -- --coverage-clover build/logs/php-coverage-multisite.xml -c phpunit-multisite.xml.dist
if: ${{ matrix.coverage }}
- name: Upload code coverage report
uses: codecov/codecov-action@v1
with:
file: build/logs/*.xml
if: ${{ matrix.coverage }}