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

Run wp-env start before PHP unit tests in package scripts #23797

Merged
merged 11 commits into from
Aug 5, 2020
5 changes: 3 additions & 2 deletions docs/contributors/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
2 changes: 2 additions & 0 deletions docs/contributors/testing-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand All @@ -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",
Expand Down
5 changes: 3 additions & 2 deletions packages/env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/env/lib/wordpress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down