Repository navigation
Description
Describe the bug
Hi everyone. I have a checkout of the gutenberg repository and try to get the php tests up and running by calling npm run test-php. I have initially called npm install and use the local environment setup.
When the script is executed it first calls the composer docker image and installs all needed dependencies. Then the linting is checked successfully. In the next step the unit tests are executed and the script fails with errors. Here is the complete cmdline output of the run:
peterv@developer ~/github/WordPress/gutenberg (master)$ npm run test-php
> gutenberg@8.4.0 test-php /home/peterv/github/WordPress/gutenberg
> npm run lint-php && npm run test-unit-php
> gutenberg@8.4.0 prelint-php /home/peterv/github/WordPress/gutenberg
> npm run wp-env run composer install -- --no-interaction
> gutenberg@8.4.0 wp-env /home/peterv/github/WordPress/gutenberg
> packages/env/bin/wp-env "run" "composer" "install" "--no-interaction"
ℹ Starting 'install' on the composer container.
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Package operations: 7 installs, 0 updates, 0 removals
- Installing composer/installers (v1.9.0): Downloading (100%)
- Installing squizlabs/php_codesniffer (3.5.5): Downloading (100%)
- Installing dealerdirect/phpcodesniffer-composer-installer (v0.6.2): Downloading (100%)
- Installing phpcompatibility/php-compatibility (9.3.5): Downloading (100%)
- Installing sirbrillig/phpcs-variable-analysis (v2.8.1): Downloading (100%)
- Installing wp-coding-standards/wpcs (2.2.1): Downloading (100%)
- Installing wp-phpunit/wp-phpunit (5.4.1): Downloading (100%)
phpcompatibility/php-compatibility suggests installing roave/security-advisories (dev-master || Helps prevent installing dependencies with known security issues.)
Generating autoload files
PHP CodeSniffer Config installed_paths set to ../../phpcompatibility/php-compatibility,../../sirbrillig/phpcs-variable-analysis,../../wp-coding-standards/wpcs
✔ Ran `install` in 'composer'. (in 14s 277ms)
> gutenberg@8.4.0 lint-php /home/peterv/github/WordPress/gutenberg
> npm run wp-env run composer run-script lint
> gutenberg@8.4.0 wp-env /home/peterv/github/WordPress/gutenberg
> packages/env/bin/wp-env "run" "composer" "run-script" "lint"
ℹ Starting 'run-script lint' on the composer container.
> phpcs --standard=phpcs.xml.dist
............................................................ 60 / 125 (48%)
............................................................ 120 / 125 (96%)
..... 125 / 125 (100%)
Time: 11.95 secs; Memory: 28MB
✔ Ran `run-script lint` in 'composer'. (in 15s 314ms)
> gutenberg@8.4.0 test-unit-php /home/peterv/github/WordPress/gutenberg
> wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose'
ℹ Starting 'phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose' on the phpunit container.
Starting 236e4b524a9888feecd0f29f560d6626_mysql_1 ... done
Starting 236e4b524a9888feecd0f29f560d6626_tests-wordpress_1 ... done
Warning: Use of undefined constant WP_TESTS_DOMAIN - assumed 'WP_TESTS_DOMAIN' (this will throw an Error in a future version of PHP) in /var/www/html/wp-content/plugins/gutenberg/vendor/wp-phpunit/wp-phpunit/includes/functions.php on line 26
Warning: Use of undefined constant WP_TESTS_DOMAIN - assumed 'WP_TESTS_DOMAIN' (this will throw an Error in a future version of PHP) in /var/www/html/wp-content/plugins/gutenberg/vendor/wp-phpunit/wp-phpunit/includes/functions.php on line 30
Warning: Use of undefined constant ABSPATH - assumed 'ABSPATH' (this will throw an Error in a future version of PHP) in /var/www/html/wp-content/plugins/gutenberg/vendor/wp-phpunit/wp-phpunit/includes/mock-mailer.php on line 2
Warning: require_once(ABSPATH/wp-includes/class-phpmailer.php): failed to open stream: No such file or directory in /var/www/html/wp-content/plugins/gutenberg/vendor/wp-phpunit/wp-phpunit/includes/mock-mailer.php on line 2
Fatal error: require_once(): Failed opening required 'ABSPATH/wp-includes/class-phpmailer.php' (include_path='.:/usr/local/lib/php') in /var/www/html/wp-content/plugins/gutenberg/vendor/wp-phpunit/wp-phpunit/includes/mock-mailer.php on line 2
✖ Command failed with exit code 255
Command failed with exit code 255
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gutenberg@8.4.0 test-unit-php: `wp-env run phpunit 'phpunit -c /var/www/html/wp-content/plugins/gutenberg/phpunit.xml.dist --verbose'`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gutenberg@8.4.0 test-unit-php script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/peterv/.npm/_logs/2020-07-02T10_31_02_834Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! gutenberg@8.4.0 test-php: `npm run lint-php && npm run test-unit-php`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the gutenberg@8.4.0 test-php script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/peterv/.npm/_logs/2020-07-02T10_31_02_901Z-debug.log
To reproduce
- (on linux mashine) checkout the gutenberg repository from github
- run:
npm install - run:
npm run build - run:
npm run test-php
Expected behavior
I guess the tests should be performed without exception :-)
Versions:
- OS: debian stretch (ok, not the actual stable, might this be a problem?)
- gutenberg repository: commit 9eeed8a (HEAD -> master, origin/master, origin/HEAD)
- docker: Docker version 19.03.3, build a872fc2f86
- docker-compose: docker-compose version 1.26.0, build d4451659
- git: git version 2.20.1
- npm: 6.12.0
- node: v12.13.0
Additional context
Maybe I am missing something here, I do not know. I followed the description on this page: https://developer.wordpress.org/block-editor/contributors/develop/testing-overview/
I debugged into the php code and could get forward by defining the missing constants in the related php scripts, but failed then at a later state in the code again.
Activity
earnjam commentedon Jul 8, 2020
Just ran into this exact issue myself. Was thinking about trying to set up
@wordpress/envto run the PHPUnit tests for a plugin, but couldn't get it working. Then went back to Gutenberg to see how it was done here and realizednpm run test-unit-phpit isn't working here either! 🙃earnjam commentedon Jul 8, 2020
So I think I've found the culprit. This issue appears to occur when you also have
wp-envinstalled globally. Thetest-unit-phpcommand callswp-env run phpunit.It seems when I change it to
npm run wp-env run phpunitthen it will work as long as I've already runnpm run wp-env startat least once before.noahtallen commentedon Jul 8, 2020
Another note is that you need to have run
wp-env startlocally before running the PHP unit tests. I've added a note to the docs about this in the PR, and I think we should consider running wp-env start as the first step in the test-php code :)noahtallen commentedon Jul 8, 2020
The reason is that wp-env start calls the wp installation code which sets the needed wp-config constants.
pvogel2 commentedon Jul 9, 2020
Hi, thanks @earnjam
I could reproduce this behaviour by tweeking the package.json as you described. Then the tests are performed sucessfully. And thx to @noahtallen for working on a sollution.
earnjam commentedon Jul 9, 2020
@pvogel2 We drilled into the problem a bit more and realized that you don't have to change anything if you just run
npm run wp-env startfirst.The environment seemed like it was working fine independent of the testing, but my problem is I had run
wp-env startwithout thenpm runbefore it. So that set up the site outside the repo in the global context. Then when runningnpm run test-unit-phpit was using the localwp-envscript which was using a different set of containers that hadn't been provisioned yet.@noahtallen is working on a PR that updates the documentation to reflect that required step and also exploring some changes to automatically run
startif needed.pvogel2 commentedon Jul 9, 2020
OK, I get it now :-) . You are right. Without tweeking tests are also running when the environment ist started before. 👍 Can not beleave that I did not try this out :-)