dingo-d / wp-pest

A package that will add WordPress integration test suite with Pest
MIT License
119 stars 5 forks source link

Support for Roots' Bedrock #30

Open mikedamoiseau opened 10 months ago

mikedamoiseau commented 10 months ago

Describe your feature request

Setup the Pest plugin on a Bedrock WordPress using the command line vendor/bin/wp-pest setup plugin --plugin-slug=mop-buzzwoo.php seems to work (except it is creating a new wp-content instead of using the app folder).

The slug of the plugin is mop-buzzwoo.php.

Once running the command line vendor/bin/pest --group=integration, I have the following error:

Installing...
Running as single site... To run multisite, use -c tests/phpunit/multisite.xml
PHPUnit 9.6.13 by Sebastian Bergmann and contributors.

Error in bootstrap script: Whoops\Exception\ErrorException:
require(/var/www/html/mop-buzzwoo.php): Failed to open stream: No such file or directory
#0 /var/www/html/tests/bootstrap.php(50): Whoops\Run->handleError()
#1 /var/www/html/tests/bootstrap.php(50): require()
#2 /var/www/html/wp/src/wp-includes/class-wp-hook.php(310): _manually_load_plugin()
#3 /var/www/html/wp/src/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters()
#4 /var/www/html/wp/src/wp-includes/plugin.php(517): WP_Hook->do_action()
#5 /var/www/html/wp/src/wp-settings.php(427): do_action()
#6 /var/www/html/wp/tests/phpunit/includes/bootstrap.php(305): require_once('...')
#7 /var/www/html/vendor/yoast/wp-test-utils/src/WPIntegration/bootstrap-functions.php(172): require_once('...')
#8 /var/www/html/vendor/yoast/wp-test-utils/src/WPIntegration/bootstrap-functions.php(130): Yoast\WPTestUtils\WPIntegration\load_wp_test_bootstrap()
#9 /var/www/html/tests/bootstrap.php(61): Yoast\WPTestUtils\WPIntegration\bootstrap_it()
#10 /var/www/html/vendor/phpunit/phpunit/src/Util/FileLoader.php(66): include_once('...')
#11 /var/www/html/vendor/phpunit/phpunit/src/Util/FileLoader.php(49): PHPUnit\Util\FileLoader::load()
#12 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Command.php(565): PHPUnit\Util\FileLoader::checkAndLoad()
#13 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Command.php(345): PHPUnit\TextUI\Command->handleBootstrap()
#14 /var/www/html/vendor/pestphp/pest/src/Console/Command.php(62): PHPUnit\TextUI\Command->handleArguments()
#15 /var/www/html/vendor/phpunit/phpunit/src/TextUI/Command.php(112): Pest\Console\Command->handleArguments()
#16 /var/www/html/vendor/pestphp/pest/src/Console/Command.php(119): PHPUnit\TextUI\Command->run()
#17 /var/www/html/vendor/pestphp/pest/bin/pest(62): Pest\Console\Command->run()
#18 /var/www/html/vendor/pestphp/pest/bin/pest(63): {closure}()
#19 /var/www/html/vendor/bin/pest(119): include('...')
#20 {main}

Describe the solution you'd like

A nice support for Roots' Bedrock boilerplate would be amazing šŸ˜

I am not expecting any short term support, just wanted to let others know.

Please confirm that you have searched existing issues and discussions about this feature.

Yes

dingo-d commented 10 months ago

Will add it on my to-do list, but I'd like to get the Pest v2 support first, which is currently blocked by WP Core not supporting PHPUnit 10.

If you'd like you can try to submit a PR. I reckon the solution should be something along the lines of investigating where the WP Core should be installed in a Bedrock boilerplate for the tests to work properly.

dingo-d commented 9 months ago

I've started to work on Bedrock support, but I got the following errors which I'll have to debug:

> @php vendor/bin/pest --group=unit --configuration web/app/themes/twentytwentyfour/phpunit.xml

   Error

  Class "WP_UnitTestCase" not found

  at vendor/yoast/wp-test-utils/src/WPIntegration/TestCaseOnlyObjectPropertyPolyfill.php:39
     35ā–•  * the WordPress version the tests are being run on.
     36ā–•  *
     37ā–•  * @since 1.2.0
     38ā–•  */
  āžœ  39ā–• abstract class TestCase extends WP_UnitTestCase {
     40ā–•
     41ā–•    use AssertObjectProperty;
     42ā–•    use ExpectOutputHelper;
     43ā–• }

      +2 vendor frames
  3   [internal]:0
      Composer\Autoload\ClassLoader::loadClass("Yoast\WPTestUtils\WPIntegration\TestCase")

      +3 vendor frames
  7   web/app/themes/twentytwentyfour/tests/Integration/ExampleTest.php:12
      uses("Yoast\WPTestUtils\WPIntegration\TestCase")
Script @php vendor/bin/pest --group=unit --configuration web/app/themes/twentytwentyfour/phpunit.xml handling the test:unit event returned with error code 1

for unit tests, and for the integration tests I get:

> @php vendor/bin/pest --group=integration --configuration web/app/themes/twentytwentyfour/phpunit.xml

ERROR: The WordPress native unit test bootstrap file could not be found. Please set either the WP_TESTS_DIR or the WP_DEVELOP_DIR environment variable, either in your OS or in a custom phpunit.xml file.
Script @php vendor/bin/pest --group=integration --configuration web/app/themes/twentytwentyfour/phpunit.xml handling the test:integration event returned with error code 1

This last one is weird, as I do have WP_TESTS_DIR in the phpunit.xml file. Maybe there are some issues with folders, need to check this out.