Skip to content

Commit 788359b

Browse files
blankartbfintal
andauthored
test: Added WordPress PHP Unit (#1187)
* WordPress PHP Unit * fix: changed wp versions * refactor * bump phpunit version * bump 8.0.0 to latest phpunit version * changed php 8.0.0 phpunit version to 7.5.20 * added name * Update .github/workflows/php-7.4.1.yml * Update .github/workflows/php-7.4.1.yml Co-authored-by: Benjamin Intal <[email protected]>
1 parent a679e1e commit 788359b

File tree

10 files changed

+509
-0
lines changed

10 files changed

+509
-0
lines changed

.github/workflows/php-5.6.39.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Unit Tests / PHP (v5.6.39)
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
12+
# Use Ubuntu 20.04.
13+
runs-on: ubuntu-20.04
14+
strategy:
15+
matrix:
16+
wp-versions: ['5.5.4', '5.6.3', '5.7.1']
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
21+
- name: Setup Node
22+
uses: actions/setup-node@v1
23+
with:
24+
node-version: 14.x
25+
26+
- name: Build Stackable Free Plugin
27+
run: |
28+
npm ci
29+
npm run build --if-present
30+
31+
- name: Setup MySQL
32+
uses: mirromutth/[email protected]
33+
with:
34+
mysql database: 'stackable' # Optional, default value is "test". The specified database which will be create
35+
mysql root password: 'root' # Required if "mysql user" is empty, default is empty. The root superuser password
36+
mysql version: '5.6'
37+
mysql user: 'root' # Required if "mysql root password" is empty, default is empty. The superuser for the specified database. Can use secrets, too
38+
mysql password: 'root' # Required if "mysql user" exists. The password for the "mysql user"
39+
40+
# Wait for MySQL server to initialize.
41+
- name: Wait for MySQL
42+
run: |
43+
while ! mysqladmin ping --host=127.0.0.1 --password=root --silent; do
44+
sleep 1
45+
done
46+
47+
# Change the PHP version to v5.6.39
48+
- name: Setup PHP v5.6.39
49+
uses: shivammathur/setup-php@v2
50+
with:
51+
php-version: '5.6.39'
52+
53+
# Check the current PHP version installed
54+
- name: Check PHP version
55+
run: php -v
56+
57+
- name: Install dependencies
58+
run: |
59+
composer require phpunit/phpunit:5.6.8 --dev
60+
composer require wp-phpunit/wp-phpunit:${{ matrix.wp-versions }} --dev
61+
composer require roots/wordpress:${{ matrix.wp-versions }} --dev
62+
composer install --prefer-dist --no-progress
63+
64+
# Run all tests.
65+
- name: Run test suite
66+
env:
67+
MYSQL_GITHUB_ACTION: true
68+
MYSQL_DATABASE: stackable
69+
MYSQL_USER: root
70+
MYSQL_PASSWORD: root
71+
MYSQL_ROOT_PASSWORD: root
72+
MYSQL_PORT: 3306
73+
run: composer run-script test

.github/workflows/php-7.3.5.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Unit Tests / PHP (v7.3.5)
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
12+
# Use Ubuntu 18.04.
13+
runs-on: ubuntu-18.04
14+
strategy:
15+
matrix:
16+
wp-versions: ['5.5.4', '5.6.3', '5.7.1']
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
21+
- name: Setup Node
22+
uses: actions/setup-node@v1
23+
with:
24+
node-version: 14.x
25+
26+
- name: Build Stackable Free Plugin
27+
run: |
28+
npm ci
29+
npm run build --if-present
30+
31+
- name: Setup MySQL
32+
uses: mirromutth/[email protected]
33+
with:
34+
mysql database: 'stackable' # Optional, default value is "test". The specified database which will be create
35+
mysql root password: 'root' # Required if "mysql user" is empty, default is empty. The root superuser password
36+
mysql version: '5.6'
37+
mysql user: 'root' # Required if "mysql root password" is empty, default is empty. The superuser for the specified database. Can use secrets, too
38+
mysql password: 'root' # Required if "mysql user" exists. The password for the "mysql user"
39+
40+
# Wait for MySQL server to initialize.
41+
- name: Wait for MySQL
42+
run: |
43+
while ! mysqladmin ping --host=127.0.0.1 --password=root --silent; do
44+
sleep 1
45+
done
46+
47+
# Change the PHP version to v7.3.5
48+
- name: Setup PHP v7.3.5
49+
uses: shivammathur/setup-php@v2
50+
with:
51+
php-version: '7.3.5'
52+
53+
# Check the current PHP version installed
54+
- name: Check PHP version
55+
run: php -v
56+
57+
# Install all dependencies from composer.json
58+
- name: Install dependencies
59+
run: |
60+
composer require phpunit/phpunit:5.6.8 --dev
61+
composer require wp-phpunit/wp-phpunit:${{ matrix.wp-versions }} --dev
62+
composer require roots/wordpress:${{ matrix.wp-versions }} --dev
63+
composer install --prefer-dist --no-progress
64+
65+
# Run all tests.
66+
- name: Run test suite
67+
env:
68+
MYSQL_GITHUB_ACTION: true
69+
MYSQL_DATABASE: stackable
70+
MYSQL_USER: root
71+
MYSQL_PASSWORD: root
72+
MYSQL_ROOT_PASSWORD: root
73+
MYSQL_PORT: 3306
74+
run: composer run-script test

.github/workflows/php-7.4.1.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: Unit Tests / PHP (v7.4.1)
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
12+
# Use Ubuntu 20.04.
13+
runs-on: ubuntu-20.04
14+
strategy:
15+
matrix:
16+
wp-versions: ['5.5.4', '5.6.3', '5.7.1']
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
21+
- name: Setup Node
22+
uses: actions/setup-node@v1
23+
with:
24+
node-version: 14.x
25+
26+
- name: Build Stackable Free Plugin
27+
run: |
28+
npm ci
29+
npm run build --if-present
30+
31+
- name: Setup MySQL
32+
uses: mirromutth/[email protected]
33+
with:
34+
mysql database: 'stackable' # Optional, default value is "test". The specified database which will be create
35+
mysql root password: 'root' # Required if "mysql user" is empty, default is empty. The root superuser password
36+
mysql user: 'root' # Required if "mysql root password" is empty, default is empty. The superuser for the specified database. Can use secrets, too
37+
mysql version: '5.6'
38+
mysql password: 'root' # Required if "mysql user" exists. The password for the "mysql user"
39+
40+
# Wait for MySQL server to initialize.
41+
- name: Wait for MySQL
42+
run: |
43+
while ! mysqladmin ping --host=127.0.0.1 --password=root --silent; do
44+
sleep 1
45+
done
46+
47+
# Change the PHP version to v7.4.1
48+
- name: Setup PHP v7.4.1
49+
uses: shivammathur/setup-php@v2
50+
with:
51+
php-version: '7.4.1'
52+
53+
# Check the current PHP version installed
54+
- name: Check PHP version
55+
run: php -v
56+
57+
# Install all dependencies from composer.json
58+
- name: Install dependencies
59+
run: |
60+
composer require wp-phpunit/wp-phpunit:${{ matrix.wp-versions }} --dev
61+
composer require roots/wordpress:${{ matrix.wp-versions }} --dev
62+
composer install --prefer-dist --no-progress
63+
64+
# Run all tests.
65+
- name: Run test suite
66+
env:
67+
MYSQL_GITHUB_ACTION: true
68+
MYSQL_DATABASE: stackable
69+
MYSQL_USER: root
70+
MYSQL_PASSWORD: root
71+
MYSQL_ROOT_PASSWORD: root
72+
MYSQL_PORT: 3306
73+
run: composer run-script test

.github/workflows/php-8.0.0.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Unit Tests / PHP (v8.0.0)
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-20.04
13+
strategy:
14+
matrix:
15+
wp-versions: ['5.5.4', '5.6.3', '5.7.1']
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: Setup Node
21+
uses: actions/setup-node@v1
22+
with:
23+
node-version: 14.x
24+
25+
- name: Build Stackable Free Plugin
26+
run: |
27+
npm ci
28+
npm run build --if-present
29+
30+
- name: Setup MySQL
31+
uses: mirromutth/[email protected]
32+
with:
33+
mysql database: 'stackable' # Optional, default value is "test". The specified database which will be create
34+
mysql root password: 'root' # Required if "mysql user" is empty, default is empty. The root superuser password
35+
mysql version: '5.6'
36+
mysql user: 'root' # Required if "mysql root password" is empty, default is empty. The superuser for the specified database. Can use secrets, too
37+
mysql password: 'root' # Required if "mysql user" exists. The password for the "mysql user"
38+
39+
- name: Wait for MySQL
40+
run: |
41+
while ! mysqladmin ping --host=127.0.0.1 --password=root --silent; do
42+
sleep 1
43+
done
44+
45+
# Change the PHP version to v8.0.0
46+
- name: Setup PHP v8.0.0
47+
uses: shivammathur/setup-php@v2
48+
with:
49+
php-version: '8.0.0'
50+
51+
- name: Check PHP version
52+
run: php -v
53+
54+
- name: Install dependencies
55+
run: |
56+
composer require phpunit/phpunit:7.5.20 --dev --ignore-platform-reqs
57+
composer require wp-phpunit/wp-phpunit:${{ matrix.wp-versions }} --dev --ignore-platform-reqs
58+
composer require roots/wordpress:${{ matrix.wp-versions }} --dev --ignore-platform-reqs
59+
composer install --prefer-dist --no-progress --ignore-platform-reqs
60+
61+
- name: Run test suite
62+
env:
63+
MYSQL_GITHUB_ACTION: true
64+
MYSQL_DATABASE: stackable
65+
MYSQL_USER: root
66+
MYSQL_PASSWORD: root
67+
MYSQL_ROOT_PASSWORD: root
68+
MYSQL_PORT: 3306
69+
run: composer run-script test

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,7 @@ dist/**
66
!dist/*.json
77
**/*__premium_only*
88
coverage
9+
10+
composer.lock
11+
/vendor
12+
/wordpress

composer.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "gambitph/stackable",
3+
"description": "Blocks for everyone",
4+
"license": "GPL-3.0-or-later",
5+
"type": "wordpress-plugin",
6+
"require-dev": {
7+
"phpunit/phpunit": "^6",
8+
"wp-phpunit/wp-phpunit": "5.7",
9+
"roots/wordpress": "5.7"
10+
},
11+
"scripts": {
12+
"test": [
13+
"phpunit tests"
14+
]
15+
}
16+
}

phpunit.xml.dist

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<phpunit
3+
bootstrap="tests/bootstrap.php"
4+
backupGlobals="false"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
>
10+
<testsuites>
11+
<testsuite name="Stackable PHPUnit">
12+
<directory>./tests/</directory>
13+
</testsuite>
14+
</testsuites>
15+
16+
<php>
17+
<env name="WP_PHPUNIT__TESTS_CONFIG" value="tests/wp-config.php" />
18+
</php>
19+
</phpunit>
20+

tests/bootstrap.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
/**
3+
* PHPUnit bootstrap file
4+
*/
5+
6+
// Composer autoloader must be loaded before WP_PHPUNIT__DIR will be available
7+
putenv( 'WP_PHPUNIT__TESTS_CONFIG=' . dirname( __DIR__ ) . '/tests/wp-config.php' );
8+
9+
require_once dirname( __DIR__ ) . '/vendor/autoload.php';
10+
11+
// Give access to tests_add_filter() function.
12+
require_once getenv( 'WP_PHPUNIT__DIR' ) . '/includes/functions.php';
13+
14+
tests_add_filter( 'muplugins_loaded', function() {
15+
if ( getenv( 'MYSQL_GITHUB_ACTION' ) ) {
16+
// Use the build folder to access Stackable.
17+
require dirname( __DIR__ ) . '/build/stackable/plugin.php';
18+
} else {
19+
// Otherwise, use the dev plugin.php file.
20+
require dirname( __DIR__ ) . '/plugin.php';
21+
}
22+
} );
23+
24+
// Start up the WP testing environment.
25+
require getenv( 'WP_PHPUNIT__DIR' ) . '/includes/bootstrap.php';

0 commit comments

Comments
 (0)