Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wp-env: Add phpunit support #20090

Merged
merged 9 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,12 @@ jobs:
- npm run test-unit:native -- --ci --maxWorkers=2 --cacheDirectory="$HOME/.jest-cache"

- name: PHP unit tests
env: WP_ENV_TESTS_PORT=8887 # TODO: Remove tests port when scripts/env is replaced with wp-env.
script:
- npm run test-php && npm run test-unit-php-multisite

- name: PHP unit tests (PHP 5.6)
env: LOCAL_PHP=5.6-fpm
noahtallen marked this conversation as resolved.
Show resolved Hide resolved
env: LOCAL_PHP=5.6-fpm WP_ENV_TESTS_PORT=8887 # TODO: Remove tests port when scripts/env is replaced with wp-env.
script:
- npm run test-php && npm run test-unit-php-multisite

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"squizlabs/php_codesniffer": "^3.5",
"phpcompatibility/php-compatibility": "^9.3",
"wp-coding-standards/wpcs": "^2.2",
"sirbrillig/phpcs-variable-analysis": "^2.8"
"sirbrillig/phpcs-variable-analysis": "^2.8",
"wp-phpunit/wp-phpunit": "^5.4"
},
"require": {
"composer/installers": "~1.0"
Expand Down
47 changes: 45 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@
"test-unit:debug": "wp-scripts --inspect-brk test-unit-js --runInBand --no-cache --verbose --config test/unit/jest.config.js ",
"test-unit:update": "npm run test-unit -- --updateSnapshot",
"test-unit:watch": "npm run test-unit -- --watch",
"test-unit-php": "wp-scripts env test-php",
"test-unit-php-multisite": "cross-env WP_MULTISITE=1 wp-scripts env test-php",
"test-unit-php": "wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist'",
"test-unit-php-multisite": "wp-env run phpunit 'WP_MULTISITE=1 phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist'",
"test-unit:native": "cd test/native/ && cross-env NODE_ENV=test jest --config ./jest.config.js",
"test-unit:native:debug": "cd test/native/ && node --inspect-brk ../../node_modules/.bin/jest --runInBand --verbose --config ./jest.config.js",
"prestorybook:build": "npm run build:packages",
Expand Down
1 change: 1 addition & 0 deletions packages/env/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### New Feature

- Expose Docker service for running phpunit commands.
- You may now mount local directories to any location within the WordPress install. For example, you may specify `"wp-content/mu-plugins": "./path/to/mu-plugins"` to add mu-plugins.

## 1.1.0 (2020-04-01)
Expand Down
15 changes: 14 additions & 1 deletion packages/env/lib/build-docker-compose-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ module.exports = function buildDockerComposeConfig( config ) {
user: cliUser,
},
'tests-cli': {
depends_on: [ 'wordpress' ],
depends_on: [ 'tests-wordpress' ],
image: 'wordpress:cli',
volumes: testsMounts,
user: cliUser,
Expand All @@ -142,11 +142,24 @@ module.exports = function buildDockerComposeConfig( config ) {
image: 'composer',
volumes: [ `${ config.configDirectoryPath }:/app` ],
},
phpunit: {
image: 'wordpressdevelop/phpunit',
depends_on: [ 'tests-wordpress' ],
volumes: [
...testsMounts,
'phpunit-uploads:/var/www/html/wp-content/uploads',
],
environment: {
LOCAL_DIR: 'html',
WP_PHPUNIT__TESTS_CONFIG: '/var/www/html/wp-config.php',
},
},
},
volumes: {
...( ! config.coreSource && { wordpress: {} } ),
...( ! config.coreSource && { 'tests-wordpress': {} } ),
mysql: {},
'phpunit-uploads': {},
},
};
};
6 changes: 5 additions & 1 deletion packages/env/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ module.exports = {
themes: [],
port: 8888,
testsPort: 8889,
config: { WP_DEBUG: true, SCRIPT_DEBUG: true },
config: {
WP_DEBUG: true,
SCRIPT_DEBUG: true,
WP_TESTS_DOMAIN: 'example.org',
},
mappings: {},
},
config,
Expand Down
8 changes: 8 additions & 0 deletions phpunit/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
* @package Gutenberg
*/

// Require composer dependencies.
require_once dirname( dirname( __FILE__ ) ) . '/vendor/autoload.php';

// If we're running in WP's build directory, ensure that WP knows that, too.
if ( 'build' === getenv( 'LOCAL_DIR' ) ) {
define( 'WP_RUN_CORE_TESTS', true );
Expand All @@ -14,6 +17,11 @@
// Try the WP_TESTS_DIR environment variable first.
$_tests_dir = getenv( 'WP_TESTS_DIR' );

// Next, try the WP_PHPUNIT composer package.
if ( ! $_tests_dir ) {
$_tests_dir = getenv( 'WP_PHPUNIT__DIR' );
}

// See if we're installed inside an existing WP dev instance.
if ( ! $_tests_dir ) {
$_try_tests_dir = dirname( __FILE__ ) . '/../../../../../tests/phpunit';
Expand Down