wp-phpunit / issues

Central issues repository for wp-phpunit
0 stars 0 forks source link

WP PHPUnit, Travis CI and HHVM » "Use of undefined constant" errors #1

Closed remcotolsma closed 5 years ago

remcotolsma commented 6 years ago

I'm getting errors on Travis CI with HHVM, see for example:

Notice: Use of undefined constant WP_TESTS_DOMAIN - assumed 'WP_TESTS_DOMAIN' in /home/travis/build/wp-pay/core/vendor/wp-phpunit/wp-phpunit/includes/functions.php on line 10

Notice: Use of undefined constant WP_TESTS_DOMAIN - assumed 'WP_TESTS_DOMAIN' in /home/travis/build/wp-pay/core/vendor/wp-phpunit/wp-phpunit/includes/functions.php on line 14

Notice: Use of undefined constant ABSPATH - assumed 'ABSPATH' in /home/travis/build/wp-pay/core/vendor/wp-phpunit/wp-phpunit/includes/install.php on line 27

Fatal error: Uncaught Error: require_once(ABSPATH/wp-settings.php): File not found in /home/travis/build/wp-pay/core/vendor/wp-phpunit/wp-phpunit/includes/install.php:27

It seems like HHVM can't require the WP_PHPUNIT__TESTS_CONFIG file in https://github.com/wp-phpunit/wp-phpunit/blob/4.9.6/wp-tests-config.php#L11-L13.

First i thought it was a issue with the relative path in the phpunit.xml config file:

<env name="WP_PHPUNIT__TESTS_CONFIG" value="tests/wp-config.php" />

But an absolute path in the PHPUnit bootstrap file was also not working:

putenv( 'WP_PHPUNIT__TESTS_CONFIG=' . __DIR__ . '/wp-config.php' );

Maybe you can extend the example projects with HHVM support?

aaemnnosttv commented 6 years ago

Hey thanks for bringing this up; nice to see someone else using it too!

This has been quite strange to debug, but from the looks of things it seems like wp-phpunit's wp-tests-config.php is not loaded during the loading of wp-phpunit/includes/install.php.

I thought this might be from HHVM handling require differently somehow for performance, but even when changing this to a simple include it doesn't change the result.

The require_once call in install.php which loads the config file returns a 1 but doesn't load it. https://github.com/wp-phpunit/wp-phpunit/blob/873de1a437bed42a44a353d1fc1769189eced065/includes/install.php#L13

It definitely is not due to being unable to locate the user's test config file though; that would result in a different error anyways.

The only thing I can think of is that HHVM is not requiring the file since it has already been loaded in bootstrap.php even though install.php is called as a separate process. Maybe a bug with HHVM?

Have you been able to run the test suite on HHVM without wp-phpunit before? It seems like the WP core test suite would have the same problem, but they no longer include HHVM in their tests.

remcotolsma commented 6 years ago

Thanks, i did some local debugging on my Mac and it looks like it is related to this line: https://github.com/wp-phpunit/wp-phpunit/blob/4.9.6/includes/bootstrap.php#L68

system( WP_PHP_BINARY . ' ' . escapeshellarg( dirname( __FILE__ ) . '/install.php' ) . ' ' . escapeshellarg( $config_file_path ) . ' ' . $multisite, $retval );

The WP_PHP_BINARY is defined in wp-config.php:

But changing this to hhvm is not solving the issue.

If i do a var_dump( getenv( 'WP_PHPUNIT__TESTS_CONFIG' ) ); in wp-tests-config.php it will result in false if it runs install.php via the system function. So i think there are some issues with the environment variables.

But no problem, i also saw this article last weekend: https://kinsta.com/blog/hhvm-wordpress/. For now we will add HHVM to the allow_failures section in the Travis CI config file.

brew tap hhvm/hhvm
brew install hhvm
hhvm vendor/bin/phpunit

https://github.com/hhvm/homebrew-hhvm

apintocr commented 6 years ago

OFFTOPIC: @aaemnnosttv just wanted to drop you a note that I do also use this! Keep up the good work.

johnbillion commented 5 years ago

HHVM hasn't been supported by WordPress for a couple of years now: https://make.wordpress.org/core/2017/05/25/hhvm-no-longer-part-of-wordpress-cores-testing-infrastructure/

aaemnnosttv commented 5 years ago

Closing as a wontfix. Sorry HHVM!