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

Compare with default wp-env where everything is bundled #2

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kasparsd
Copy link
Contributor

@kasparsd kasparsd commented Jan 13, 2025

This is a diff to illustrate the suggested default setup using only the bundled WP core, PHPunit testing library, etc.

Issues

  1. Code editors no longer have access to WP core files so no autocomplete, debug breakpoints, etc.

  2. The bundled phpunit is not functional:

    • The wp-env environment doesn't include yoast/phpunit-polyfills so that has to be required at the project level. Requiring this package also pulls in a version of phpunit which conflicts with the bundled phpunit at /home/USERNAME/.composer/vendor/phpunit/...

    • The bundled phpunit is useless due to the above. Each project must call their local vendor/bin/phpunit to run the tests. What's the purpose of the bundled phpunit if it can't be used at all?

  3. A different version of WP PHPunit library is pulled with every version of WP core defined in .wp-env.json which leads to unexpected testing behaviour.

@@ -34,6 +34,6 @@
"format:docs": "wp-scripts lint-md-docs --fix",
"test": "npm-run-all2 test:*",
"test:workspaces": "npm run test --workspaces --if-present",
"test:phpunit": "wp-env run tests-cli composer test"
"test:phpunit": "wp-env run tests-cli --env-cwd=tools phpunit"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the bundled phpunit simply fails:

An error occurred inside PHPUnit.

Message:  Call to undefined method PHPUnit\Framework\TestSuite::empty()
Location: /home/USERNAME/.composer/vendor/phpunit/phpunit/src/TextUI/Configuration/Xml/TestSuiteMapper.php:48

#0 /home/USERNAME/.composer/vendor/phpunit/phpunit/src/TextUI/Configuration/TestSuiteBuilder.php(75): 
...

if ( is_readable( $wp_env_tests_dir . '/wp-tests-config.php' ) ) {
putenv( sprintf( 'WP_PHPUNIT__TESTS_CONFIG=%s/wp-tests-config.php', $wp_env_tests_dir ) );
}
$wp_tests_dir = getenv( 'WP_TESTS_DIR' );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we rely on the bundled WP PHPUnit testing library instead of pulling in a known version from https://github.com/wp-phpunit/docs

This will change with every version of WP core we require in wp-env.json which could lead to breaking changes.

@@ -7,7 +7,6 @@
"request": "launch",
"port": 9003,
"pathMappings": {
"/var/www/html": "${workspaceFolder}/wordpress",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDEs no longer have access to WP core files for autocomplete and debugging.

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

Successfully merging this pull request may close these issues.

1 participant