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

Utilize WordPress PHPUnit Test Library Included By wp-env #41852

Merged
merged 8 commits into from
Jul 15, 2022
Merged

Utilize WordPress PHPUnit Test Library Included By wp-env #41852

merged 8 commits into from
Jul 15, 2022

Conversation

ObliviousHarmony
Copy link
Contributor

@ObliviousHarmony ObliviousHarmony commented Jun 22, 2022

What?

This makes the appropriate changes to move us away from needing wp-phpunit/wp-phpunit. In the process, I also found that Yoast/PHPUnit-Polyfills was not being fully utilized. One of the changes was to change methods like setUp() to set_up() to prevent PHP 8 compatibility issues.

In addition, as per #39863, the phpunit container does not work on M1 chips. This pull request replaces the usage of the phpunit container with direct usage of vendor/bin/phpunit from Gutenberg.

Closes #39863.

Why?

#41780 made it so that there's a version of WordPress' PHPUnit test files available within the wp-env container. We should dogfood this implementation and use the test files here.

How?

This pull request makes a few changes to methods in order to be compatible with Yoast/PHPUnit-Polyfills:

* `setUp()` -> `set_up()`
* `tearDown()` -> `tear_down()`
* `setUpBeforeClass()` -> `set_up_before_class()`
* `setUpAfterClass()` -> `set_up_after_class()`

This also removes the wp-phpunit/wp-phpunit dependency since it's no longer necessary.

We also add the wptests_ database table prefix as we are running the test suite in the tests-wordpress container rather than the phpunit container.

Testing Instructions

  1. Make sure CI passes because it's using the same test script.
  2. Run npm run test-unit-php and verify that it passes.
  3. Run npm run test-unit-php-multisite and verify that it passes.
  4. Play around with different WordPress versions (it looks like we're not compatible as far back as we claim!)

@@ -31,8 +31,7 @@
"phpcompatibility/php-compatibility": "^9.3",
"wp-coding-standards/wpcs": "^2.2",
"sirbrillig/phpcs-variable-analysis": "^2.8",
"wp-phpunit/wp-phpunit": "^5.4",
"phpunit/phpunit": "^8.5",
"phpunit/phpunit": "^6.5",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I chose 6.5 here because of the stated requirements for the minimum PHP version. I wanted a version that was compatible with more versions of PHP.

We're going to be running PHPUnit tests
using the in-container test files. We will
no longer need `wp-phpunit/wp-phpunit`.
In order to work on PHP 8, we must use the methods
for setUp(), tearDown(), setUpBeforeClass(), tearDownAfterClass().
This commit replaces those with polyfill versions.
This commit replaces the `run phpunit` unit test scripts
with ones that run using the project's PHPUnit.
@ObliviousHarmony ObliviousHarmony marked this pull request as ready for review July 15, 2022 20:27
package.json Outdated Show resolved Hide resolved
phpunit.xml.dist Outdated Show resolved Hide resolved
phpunit/multisite.xml Outdated Show resolved Hide resolved
@noahtallen noahtallen added [Type] Bug An existing feature does not function as intended [Tool] Env /packages/env labels Jul 15, 2022
Rather than being heavy-handed and disabling the
strict handling of tests that do nothing, we should
mark those tests as incomplete.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Tool] Env /packages/env [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PHPUnit Container Not Working on M1
2 participants