From 9bbfc36e898fc6c8f8224d053354ac97e03e96f1 Mon Sep 17 00:00:00 2001 From: Noah Allen Date: Wed, 5 Aug 2020 16:16:50 -0700 Subject: [PATCH] Run wp-env start before PHP unit tests in package scripts (#23797) * Improve test-php documentation * Run wp-env start before running phpunit tests * Remove references to npx wp-env in favor of npm run wp-env * Chmod phpunit config file to fix linux permissions --- docs/contributors/getting-started.md | 5 +++-- docs/contributors/testing-overview.md | 2 ++ package.json | 6 ++++-- packages/env/README.md | 5 +++-- packages/env/lib/wordpress.js | 2 +- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/docs/contributors/getting-started.md b/docs/contributors/getting-started.md index fc8645f78c7fd..a6362e2886fbb 100644 --- a/docs/contributors/getting-started.md +++ b/docs/contributors/getting-started.md @@ -36,7 +36,8 @@ To install Docker Compose, [follow their instructions here](https://docs.docker. Once Docker is installed and running, run this script to install WordPress, and build your local environment: ```bash -npx wp-env start +# Note: prefixing with "npm run" will resolve npm from the local Gutenberg source code, rather than a global install which may be out of date. +npm run wp-env start ``` ### Step 2: Accessing and Configuring the Local WordPress Install @@ -46,7 +47,7 @@ npx wp-env start The WordPress installation should now be available at `http://localhost:8888` (**Username**: `admin`, **Password**: `password`). If this port is in use, you can override it using the `WP_ENV_PORT` environment variable. For more information, consult the `wp-env` [README](https://github.com/WordPress/gutenberg/blob/master/packages/env/README.md). -To shut down this local WordPress instance run `npx wp-env stop`. To start it back up again, run `npx wp-env start` again. +To shut down this local WordPress instance run `npm run wp-env stop`. To start it back up again, run `npm run wp-env start` again. #### Toggling Debug Systems diff --git a/docs/contributors/testing-overview.md b/docs/contributors/testing-overview.md index d02d4cd15a657..7170cb20ec522 100644 --- a/docs/contributors/testing-overview.md +++ b/docs/contributors/testing-overview.md @@ -459,6 +459,8 @@ Tests for PHP use [PHPUnit](https://phpunit.de/) as the testing framework. If yo npm run test-php ``` +_Note: The phpunit commands require `wp-env` to be running and composer dependencies to be installed. The package script will start wp-env for you if it is not already running._ + Code style in PHP is enforced using [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer). It is recommended that you install PHP_CodeSniffer and the [WordPress Coding Standards for PHP_CodeSniffer](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#installation) ruleset using [Composer](https://getcomposer.org/). With Composer installed, run `composer install` from the project directory to install dependencies. The above `npm run test-php` will execute both unit tests and code linting. Code linting can be verified independently by running `npm run lint-php`. To run unit tests only, without the linter, use `npm run test-unit-php` instead. diff --git a/package.json b/package.json index 962eb596afbd0..e5bb48ee5ae6a 100644 --- a/package.json +++ b/package.json @@ -225,8 +225,8 @@ "lint": "concurrently \"npm run lint-lockfile\" \"npm run lint-js\" \"npm run lint-pkg-json\" \"npm run lint-css\"", "lint-js": "wp-scripts lint-js", "lint-js:fix": "npm run lint-js -- --fix", - "prelint-php": "npm run wp-env run composer install -- --no-interaction", - "lint-php": "npm run wp-env run composer run-script lint", + "prelint-php": "wp-env run composer 'install --no-interaction'", + "lint-php": "wp-env run composer run-script lint", "lint-pkg-json": "wp-scripts lint-pkg-json . 'packages/*/package.json'", "lint-lockfile": "node ./bin/validate-package-lock.js", "lint-css": "wp-scripts lint-style '**/*.scss'", @@ -251,7 +251,9 @@ "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", + "pretest-unit-php": "wp-env start", "test-unit-php": "wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose'", + "pretest-unit-php-multisite": "wp-env start", "test-unit-php-multisite": "wp-env run phpunit 'WP_MULTISITE=1 phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit/multisite.xml --verbose'", "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 ../../node_modules/.bin/jest --runInBand --config ./jest.config.js", diff --git a/packages/env/README.md b/packages/env/README.md index 4eb9d65287dbe..28c61f1bb6d40 100644 --- a/packages/env/README.md +++ b/packages/env/README.md @@ -51,13 +51,14 @@ Then modify your package.json and add an extra command to npm `scripts` (https:/ When installing `wp-env` in this way, all `wp-env` commands detailed in these docs must be prefixed with `npm run`, for example: ```sh -$ npm run wp-env start +# You must add another dash to pass the "update" flag to wp-env +$ npm run wp-env start -- --update ``` instead of: ```sh -$ wp-env start +$ wp-env start --update ``` ## Usage diff --git a/packages/env/lib/wordpress.js b/packages/env/lib/wordpress.js index 385b8911a4eea..1c8fe2bf26176 100644 --- a/packages/env/lib/wordpress.js +++ b/packages/env/lib/wordpress.js @@ -130,7 +130,7 @@ async function configureWordPress( environment, config, spinner ) { [ 'sh', '-c', - 'sed "/^require.*wp-settings.php/d" /var/www/html/wp-config.php > /var/www/html/phpunit-wp-config.php', + 'sed "/^require.*wp-settings.php/d" /var/www/html/wp-config.php > /var/www/html/phpunit-wp-config.php && chmod 777 /var/www/html/phpunit-wp-config.php', ], { config: config.dockerComposeConfigPath,