Skip to content

Commit

Permalink
Tools: Try adding infrastructure for PHPUnit tests (#299)
Browse files Browse the repository at this point in the history
* Add PHPUnit bootstrapping

* Install deps correctly.

* Fix composer deps

* Setup wp-env too

* Update to gutenberg bootstrap

* Add phpunit deps

* Set the WP_RUN_CORE_TESTS constant so that we can test the wp_environment_type

* Force phpunits config file not to be forced to local environment, to allow testing.

* Attempt to work around phpunit-wp-config.php permissions

* Revert "Attempt to work around phpunit-wp-config.php permissions"

This reverts commit 9897577.

* Attempt to workaround wp-env permissions and limitations.

* Simplify the phpunit bootstrapping

* Move @wordpress/env to a devDep

* Update WP version for unit test install

* Use the files from wp-env if available

* Set a null `WP_ENVIRONMENT_TYPE` for the test environment

* Update workflow to use yarn, cache yarn deps, remove `WP_ENVIRONMENT_TYPE` workaround

* Update test test to passing tests only

* Update testing branch name

* Fix workflow file indentation

Co-authored-by: Dion Hulse <[email protected]>
Co-authored-by: Dion Hulse <[email protected]>
Co-authored-by: Dion Hulse <[email protected]>
  • Loading branch information
4 people authored Nov 4, 2022
1 parent 7186a8a commit fbe5b96
Show file tree
Hide file tree
Showing 8 changed files with 2,060 additions and 79 deletions.
38 changes: 38 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: CI

on:
push:
branches: [ trunk, try/phpunit-tests ]
pull_request:
branches: [ trunk ]

workflow_dispatch:

jobs:
run-tests:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # v3.0.2

- name: Install NodeJS
uses: actions/setup-node@eeb10cff27034e7acf239c5d29f62154018672fd # v3.3.0
with:
node-version-file: '.nvmrc'
cache: yarn

- name: Install dependencies & setup configs
run: |
yarn setup:tools
- name: Install dependencies
run: |
yarn
composer install
yarn build
yarn wp-env start
- name: Run PHP unit tests
run: |
yarn test:php
18 changes: 18 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"core": "WordPress/WordPress#master",
"mappings": {
"wp-content/mu-plugins": "./mu-plugins"
},
"env": {
"tests": {
"config": {
"WP_ENVIRONMENT_TYPE": false
},
"mappings": {
"vendor": "./vendor",
"phpunit": "./phpunit",
"phpunit.xml.dist": "./phpunit.xml.dist"
}
}
}
}
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
"url": "[email protected]:WordPress/wporg-repo-tools.git"
}
],
"require": {
"composer/installers": "~1.0"
},
"require-dev": {
"composer/installers": "~1.0",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
"phpcompatibility/phpcompatibility-wp": "*",
"phpunit/phpunit": "^9.5",
"wp-coding-standards/wpcs": "2.*",
"wporg/wporg-repo-tools": "dev-trunk"
"wp-phpunit/wp-phpunit": "~6.0",
"wporg/wporg-repo-tools": "dev-trunk",
"yoast/phpunit-polyfills": "^1.0"
},
"config": {
"allow-plugins": {
Expand Down
Loading

0 comments on commit fbe5b96

Please sign in to comment.