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

PHP Notice: Constant ABSPATH already defined when setup using WP-CLI on VVV #125

Closed
dingo-d opened this issue Aug 20, 2018 · 2 comments
Closed

Comments

@dingo-d
Copy link

dingo-d commented Aug 20, 2018

I've set up the plugin test using scaffold in WP-CLI. In my plugin the plugin structure is

my-plugin/
  |
  - bin
      install-wp-tests.sh
  |
  - tests
     bootstrap.php
  ...

I've installed everyting I need with Composer.

The install script installs the test WordPress in some temporary folder on my Mac /var/folders/xj/asdq3e232ad.../T/wordpress

When I run the tests without adding the WP_Mock in my bootstrap the phpunit works fine. But when I add

// First we need to load the composer autoloader so we can use WP Mock
require_once dirname( dirname( __FILE__ ) ) . '/vendor/autoload.php';

// Now call the bootstrap method of WP Mock
\WP_Mock::bootstrap();

I get an error

PHP Notice:  Constant ABSPATH already defined in /Users/dingo-d/vagrant-local/www/wordpress-develop/tests/phpunit/wp-tests-config.php on line 4
PHP Stack trace:
PHP   1. {main}() /usr/local/bin/phpunit:0
PHP   2. PHPUnit\TextUI\Command::main() /usr/local/bin/phpunit:569
PHP   3. PHPUnit\TextUI\Command->run() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:148
PHP   4. PHPUnit\TextUI\Command->handleArguments() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:159
PHP   5. PHPUnit\TextUI\Command->handleBootstrap() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:788
PHP   6. PHPUnit\Util\Fileloader::checkAndLoad() phar:///usr/local/bin/phpunit/phpunit/TextUI/Command.php:991
PHP   7. PHPUnit\Util\Fileloader::load() phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php:48
PHP   8. include_once() phar:///usr/local/bin/phpunit/phpunit/Util/Fileloader.php:64
PHP   9. require() /Users/dingo-d/vagrant-local/www/my-projects/my-plugin/public_html/wp-content/plugins/developer-portal/tests/bootstrap.php:48
PHP  10. require_once() /Users/dingo-d/vagrant-local/www/wordpress-develop/tests/phpunit/includes/bootstrap.php:31
PHP  11. define() /Users/dingo-d/vagrant-local/www/wordpress-develop/tests/phpunit/wp-tests-config.php:4

For local environment I'm using VVV.

I'm unsure how is VVV affecting the unit tests. Should I remove wordpress-develop from it and it should work?

EDIT:

Deleted the wordpress-develop and when running

bash bin/install-wp-tests.sh wordpress_test root '' localhost latest

and then running phpunit I still get the same error.

@johnpbloch
Copy link
Contributor

WP_Mock is incompatible with the core test framework (what you get when you scaffold a plugin). #49 is currently open requesting the ability to use both in the same test suite, but the conclusion seems to be that you need separate test suites to make it work. #114 is also under discussion, which would get around the problem by at least making it easier to get a plugin set up correctly with WP_Mock instead of the WP core framework.

@dingo-d
Copy link
Author

dingo-d commented Aug 20, 2018

Oh, I see. Thanks for the explanation! :)

@dingo-d dingo-d closed this as completed Aug 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants