Skip to content

Commit a726e2a

Browse files
PHPUnit scaffolding
1 parent a3e6776 commit a726e2a

16 files changed

+5206
-24916
lines changed

.env.testing

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# WP-Browser configuration
2+
# https://wpbrowser.wptestkit.dev/
3+
4+
# The location Composer installed johnpbloch/wordpress to
5+
WP_ROOT_FOLDER="wordpress"
6+
7+
TEST_DB_HOST="127.0.0.1"
8+
# This must match the .wp-env.json config
9+
TEST_DB_PORT="33306"
10+
TEST_DB_USER="root"
11+
TEST_DB_PASSWORD="password"
12+
13+
TEST_DB_NAME="wp-browser-tests"
14+
TEST_TABLE_PREFIX="wp_"
15+
16+
TEST_SITE_WP_DOMAIN="localhost:8888"
17+
TEST_SITE_ADMIN_EMAIL="[email protected]"

.gitattributes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/.env.testing export-ignore
2+
/.wp-env.json export-ignore
3+
/codeception.dist.yml export-ignore
4+
/package-lock.json export-ignore
5+
/package.json export-ignore
6+
/tests export-ignore
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Codecoverage-Main
2+
3+
# Runs PHPUnit unit and Codeception wp-browser wpunit tests, merges the code coverage, commits the html report to
4+
# GitHub Pages, generates a README badge with the coverage percentage.
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
13+
codecoverage-main:
14+
runs-on: ubuntu-latest
15+
16+
services:
17+
mysql:
18+
image: mysql:8.0
19+
env:
20+
MYSQL_ROOT_PASSWORD: password
21+
MYSQL_DATABASE: tests-wordpress
22+
ports:
23+
- 33306:3306
24+
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
25+
26+
strategy:
27+
matrix:
28+
php: [ '7.4' ]
29+
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v3
33+
34+
- name: Check does gh-pages branch need to be created
35+
run: |
36+
if [[ $(git branch -l gh-pages) == "" ]]; then
37+
gh_pages_branch_needed=true
38+
else
39+
gh_pages_branch_needed=false
40+
fi
41+
echo "GH_PAGES_BRANCH_NEEDED=$gh_pages_branch_needed" >> $GITHUB_ENV;
42+
mkdir gh-pages
43+
44+
- name: Maybe create gh-pages branch
45+
if: ${{ env.GH_PAGES_BRANCH_NEEDED }}
46+
uses: peaceiris/actions-gh-pages@v4
47+
with:
48+
github_token: ${{ secrets.GITHUB_TOKEN }}
49+
publish_dir: ./gh-pages
50+
force_orphan: true
51+
allow_empty_commit: true
52+
commit_message: "🤖 Creating gh-pages branch"
53+
54+
- name: Checkout GitHub Pages branch for code coverage report
55+
uses: actions/checkout@v3
56+
with:
57+
ref: gh-pages
58+
path: gh-pages
59+
60+
- name: Install PHP
61+
uses: shivammathur/[email protected]
62+
with:
63+
php-version: ${{ matrix.php }}
64+
coverage: xdebug
65+
tools: composer, jaschilz/php-coverage-badger
66+
extensions: zip
67+
68+
- name: Read .env.testing
69+
uses: c-py/action-dotenv-to-setenv@v2
70+
with:
71+
env-file: .env.testing
72+
73+
- name: Run composer install
74+
continue-on-error: true
75+
run: composer install -v
76+
77+
- name: Allow writing to wp-content
78+
run: sudo chmod -R a+w wp-content
79+
80+
- name: Clear previous code coverage
81+
run: |
82+
rm -rf gh-pages/phpunit || true;
83+
mkdir gh-pages/phpunit || true;
84+
85+
- name: Run tests
86+
run: XDEBUG_MODE=coverage composer test-coverage
87+
88+
- name: Merge code coverage
89+
run: vendor/bin/phpcov merge --clover gh-pages/phpunit/clover.xml --php gh-pages/phpunit/phpunit.cov --html gh-pages/phpunit/html/ tests/_output/;
90+
91+
# See: https://github.blog/2009-12-29-bypassing-jekyll-on-github-pages/
92+
- name: Add `.nojekyll` file so code coverage report successfully deploys to gh-pages
93+
working-directory: gh-pages/phpunit
94+
run: |
95+
touch .nojekyll
96+
git add -- .nojekyll *
97+
98+
- name: Update README badge
99+
run: php-coverage-badger gh-pages/phpunit/clover.xml gh-pages/phpunit/coverage.svg
100+
101+
- name: Commit code coverage to gh-pages
102+
uses: stefanzweifel/git-auto-commit-action@v5
103+
with:
104+
repository: gh-pages
105+
branch: gh-pages
106+
commit_message: "🤖 Save code coverage report to gh-pages" # TODO: include the percentage change in the message.
107+
commit_options: ""
108+
env:
109+
GITHUB_TOKEN: "${{ github.token }}"

.gitignore

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
node_modules
2-
vendor
31
.DS_Store
42
.vscode
3+
/node_modules
4+
/tests/_output
5+
/tests/_support/_generated
6+
/wordpress
7+
/wp-content
8+
node_modules
9+
vendor

.wp-env.json

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
{
2-
"config": {
3-
"WP_DEBUG": true,
4-
"WP_DEBUG_LOG": true,
5-
"WP_DEBUG_DISPLAY": true
6-
},
7-
"plugins": [
8-
"."
9-
],
10-
"port": 8880,
11-
"testsPort": 8881,
12-
"env": {
13-
"tests": {
14-
"config": {
15-
"WP_TESTS_DOMAIN": "localhost:8881",
16-
"WP_TESTS_EMAIL": "[email protected]",
17-
"WP_TESTS_TITLE": "WordPress Tests",
18-
"WP_TESTS_BINARY": "php"
19-
}
20-
}
2+
"config": {
3+
"WP_DEBUG": true,
4+
"WP_DEBUG_LOG": true,
5+
"WP_DEBUG_DISPLAY": true
6+
},
7+
"port": 8880,
8+
"testsPort": 8881,
9+
"env": {
10+
"tests": {
11+
"config": {
12+
"WP_TESTS_DOMAIN": "localhost:8881",
13+
"WP_TESTS_EMAIL": "[email protected]",
14+
"WP_TESTS_TITLE": "WordPress Tests",
15+
"WP_TESTS_BINARY": "php"
16+
},
17+
"mysqlPort": 33306
2118
}
22-
}
19+
},
20+
"core": "https://wordpress.org/wordpress-6.1.7.zip"
21+
}

codeception.dist.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
paths:
2+
tests: tests
3+
output: tests/_output
4+
data: tests/_data
5+
support: tests/_support
6+
envs: tests/_envs
7+
actor_suffix: Tester
8+
extensions:
9+
enabled:
10+
- Codeception\Extension\RunFailed
11+
commands:
12+
- Codeception\Command\GenerateWPUnit
13+
params:
14+
- .env.testing
15+
coverage:
16+
enabled: true
17+
include:
18+
- /includes/*
19+
# - /upgrades/*
20+
bootstrap: bootstrap.php

composer.json

Lines changed: 98 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,107 @@
11
{
2-
"name": "newfold-labs/wp-module-onboarding",
3-
"description": "Next-generation WordPress Onboarding for WordPress sites at Newfold Digital.",
4-
"type": "library",
5-
"license": "GPL-2.0-or-later",
6-
"authors": [
7-
{
8-
"name": "Dave Ryan",
9-
"email": "[email protected]"
10-
}
11-
],
12-
"autoload": {
13-
"psr-4": {
14-
"NewfoldLabs\\WP\\Module\\Onboarding\\": "includes/"
15-
},
16-
"files": [
17-
"bootstrap.php"
18-
]
19-
},
20-
"config": {
21-
"allow-plugins": {
22-
"dealerdirect/phpcodesniffer-composer-installer": true
23-
},
24-
"platform": {
25-
"php": "7.3.0"
26-
}
27-
},
28-
"repositories": [
2+
"name": "newfold-labs/wp-module-onboarding",
3+
"description": "Next-generation WordPress Onboarding for WordPress sites at Newfold Digital.",
4+
"type": "library",
5+
"license": "GPL-2.0-or-later",
6+
"authors": [
297
{
30-
"type": "composer",
31-
"url": "https://newfold-labs.github.io/satis/",
32-
"only": [
33-
"newfold-labs/*"
34-
]
8+
"name": "Dave Ryan",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"autoload": {
13+
"psr-4": {
14+
"NewfoldLabs\\WP\\Module\\Onboarding\\": "includes/"
3515
},
36-
{
16+
"files": [
17+
"bootstrap.php"
18+
]
19+
},
20+
"config": {
21+
"allow-plugins": {
22+
"dealerdirect/phpcodesniffer-composer-installer": true,
23+
"composer/installers": true,
24+
"johnpbloch/wordpress-core-installer": true
25+
},
26+
"platform": {
27+
"php": "7.3"
28+
}
29+
},
30+
"repositories": {
31+
"outlandishideas/wpackagist": {
32+
"type": "composer",
33+
"url": "https://wpackagist.org"
34+
},
35+
"0": {
36+
"type": "composer",
37+
"url": "https://newfold-labs.github.io/satis/",
38+
"only": [
39+
"newfold-labs/*"
40+
]
41+
},
42+
"1": {
3743
"type": "vcs",
3844
"url": "[email protected]:InstaWP/connect-helpers.git",
3945
"only": [
40-
"instawp/*"
46+
"instawp/*"
4147
]
4248
}
43-
],
44-
"require": {
45-
"mustache/mustache": "^2.14.2",
46-
"wp-cli/wp-config-transformer": "^1.4.1",
47-
"newfold-labs/wp-module-onboarding-data": "^1.2.6",
48-
"newfold-labs/wp-module-patterns": "^2.6",
49-
"newfold-labs/wp-module-facebook": "^1.0.9",
50-
"newfold-labs/wp-module-migration": "^1.0.12",
51-
"wp-forge/helpers": "^2.0"
52-
},
53-
"require-dev": {
54-
"wp-phpunit/wp-phpunit": "^6.6.2",
55-
"yoast/phpunit-polyfills": "^2.0.2",
56-
"newfold-labs/wp-php-standards": "^1.2.4",
57-
"wp-cli/i18n-command": "^2.6.3"
58-
},
59-
"scripts": {
60-
"fix": [
61-
"vendor/bin/phpcbf . --standard=phpcs.xml"
62-
],
63-
"i18n-pot": "vendor/bin/wp i18n make-pot . ./languages/wp-module-onboarding.pot --headers='{\"Report-Msgid-Bugs-To\":\"https://github.com/newfold-labs/wp-module-onboarding/issues\",\"POT-Creation-Date\":\"2024-11-18T07:59:34+00:00\"}' --exclude=assets,tests,src",
64-
"i18n-po": "vendor/bin/wp i18n update-po ./languages/wp-module-onboarding.pot ./languages",
65-
"i18n-mo": "vendor/bin/wp i18n make-mo ./languages",
66-
"i18n-php": "vendor/bin/wp i18n make-php ./languages",
67-
"i18n-json": "find ./languages -type f -name \"*.po\" -print0 | xargs -0 -I {} sh -c 'name=$(basename \"$1\" .po); npx po2json languages/\"$name\".po languages/\"$name\"-nfd-onboarding.json -f jed1.x' -- {}",
68-
"i18n": [
69-
"@i18n-pot",
70-
"@i18n-po",
71-
"@i18n-php",
72-
"@i18n-json"
73-
],
74-
"lint": [
75-
"vendor/bin/phpcs . --standard=phpcs.xml"
76-
]
77-
},
78-
"scripts-descriptions": {
79-
"lint": "Check files against coding standards.",
80-
"clean": "Automatically fix coding standards issues where possible.",
81-
"i18n": "Generate new language files.",
82-
"i18n-pot": "Generate a .pot file for translation.",
83-
"i18n-po": "Update existing .po files.",
84-
"i18n-mo": "Generate new language .mo files.",
85-
"i18n-json": "Generate new language .json files."
86-
}
49+
},
50+
"require": {
51+
"mustache/mustache": "^2.14.2",
52+
"wp-cli/wp-config-transformer": "^1.4.1",
53+
"newfold-labs/wp-module-onboarding-data": "^1.2.6",
54+
"newfold-labs/wp-module-patterns": "^2.6",
55+
"newfold-labs/wp-module-facebook": "^1.0.9",
56+
"newfold-labs/wp-module-migration": "^1.0.12",
57+
"wp-forge/helpers": "^2.0"
58+
},
59+
"require-dev": {
60+
"php": ">=7.3",
61+
"wp-phpunit/wp-phpunit": "^6.6.2",
62+
"yoast/phpunit-polyfills": "^2.0.2",
63+
"newfold-labs/wp-php-standards": "^1.2.4",
64+
"wp-cli/i18n-command": "^2.6.3",
65+
"johnpbloch/wordpress": "6.1.7",
66+
"lucatume/wp-browser": "*",
67+
"phpunit/phpcov": "*"
68+
},
69+
"scripts": {
70+
"fix": [
71+
"vendor/bin/phpcbf . --standard=phpcs.xml"
72+
],
73+
"i18n": [
74+
"@i18n-pot",
75+
"@i18n-po",
76+
"@i18n-php",
77+
"@i18n-json"
78+
],
79+
"i18n-json": "find ./languages -type f -name \"*.po\" -print0 | xargs -0 -I {} sh -c 'name=$(basename \"$1\" .po); npx po2json languages/\"$name\".po languages/\"$name\"-nfd-onboarding.json -f jed1.x' -- {}",
80+
"i18n-mo": "vendor/bin/wp i18n make-mo ./languages",
81+
"i18n-php": "vendor/bin/wp i18n make-php ./languages",
82+
"i18n-po": "vendor/bin/wp i18n update-po ./languages/wp-module-onboarding.pot ./languages",
83+
"i18n-pot": "vendor/bin/wp i18n make-pot . ./languages/wp-module-onboarding.pot --headers='{\"Report-Msgid-Bugs-To\":\"https://github.com/newfold-labs/wp-module-onboarding/issues\",\"POT-Creation-Date\":\"2024-11-18T07:59:34+00:00\"}' --exclude=assets,tests,src",
84+
"lint": [
85+
"vendor/bin/phpcs . --standard=phpcs.xml"
86+
],
87+
"test": [
88+
"codecept run wpunit"
89+
],
90+
"test-coverage": [
91+
"codecept run wpunit --coverage wpunit.cov",
92+
"phpcov merge --php tests/_output/merged.cov --html tests/_output/html tests/_output;",
93+
"echo \"open tests/_output/html/index.html\" to view the report"
94+
]
95+
},
96+
"scripts-descriptions": {
97+
"clean": "Automatically fix coding standards issues where possible.",
98+
"i18n": "Generate new language files.",
99+
"i18n-json": "Generate new language .json files.",
100+
"i18n-mo": "Generate new language .mo files.",
101+
"i18n-po": "Update existing .po files.",
102+
"i18n-pot": "Generate a .pot file for translation.",
103+
"lint": "Check files against coding standards.",
104+
"test": "Run tests.",
105+
"test-coverage": "Run tests with coverage, merge coverage and create HTML report."
106+
}
87107
}

0 commit comments

Comments
 (0)