Skip to content

test-php execution fails (at least) on linux #23642

Closed

Description

@pvogel2

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

  1. (on linux mashine) checkout the gutenberg repository from github
  2. run: npm install
  3. run: npm run build
  4. 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

  1. added
    [Tool] Env
    Needs Technical Feedback
    on Jul 3, 2020
  2. earnjam commented on Jul 8, 2020

    @earnjam
    Contributor

    Just ran into this exact issue myself. Was thinking about trying to set up @wordpress/env to 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 realized npm run test-unit-php it isn't working here either! 🙃

  3. earnjam commented on Jul 8, 2020

    @earnjam
    Contributor

    So I think I've found the culprit. This issue appears to occur when you also have wp-env installed globally. The test-unit-php command calls wp-env run phpunit.

    It seems when I change it to npm run wp-env run phpunit then it will work as long as I've already run npm run wp-env start at least once before.

  4. added
    [Status] In Progress
    on Jul 8, 2020
  5. noahtallen commented on Jul 8, 2020

    @noahtallen
    Member

    Another note is that you need to have run wp-env start locally 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 :)

  6. noahtallen commented on Jul 8, 2020

    @noahtallen
    Member

    The reason is that wp-env start calls the wp installation code which sets the needed wp-config constants.

  7. pvogel2 commented on Jul 9, 2020

    @pvogel2
    ContributorAuthor

    Hi, thanks @earnjam

    So I think I've found the culprit. This issue appears to occur when you also have wp-env installed globally. The test-unit-php command calls wp-env run phpunit.

    It seems when I change it to npm run wp-env run phpunit then it will work as long as I've already run npm run wp-env start at least once before.

    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.

  8. earnjam commented on Jul 9, 2020

    @earnjam
    Contributor

    @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 start first.

    The environment seemed like it was working fine independent of the testing, but my problem is I had run wp-env start without the npm run before it. So that set up the site outside the repo in the global context. Then when running npm run test-unit-php it was using the local wp-env script 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 start if needed.

  9. pvogel2 commented on Jul 9, 2020

    @pvogel2
    ContributorAuthor

    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 :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Needs Technical Feedback[Status] In Progress[Tool] Env

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions