You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into a weird problem in my pest implementation for WordPress integration testing, where I'm dependent on two different base test classes for unit and integration tests.
When running the tests, it looks like the pest will enter all the test files regardless of which group is called.
The minimum reproducible example with just pest looks like this:
vendor/bin/pest --group=unit
/Users/deniszoljom/Projects/Personal/pest-playground/tests/Unit/UnitTest.php:3:
string(9) "unit test"
/Users/deniszoljom/Projects/Personal/pest-playground/tests/Integration/IntegrationTest.php:3:
string(16) "integration test"
PASS Tests\Unit\UnitTest
✓ example unit test
Tests: 1 passed
Time: 0.01s
As you can see, in both cases the var_dump is called from both files.
Why is this a problem?
If I have an inaccessible class that acts as a base test class for my Integration tests (inaccessible meaning if the bootstrap.php file isn't including it), the unit tests will fail with TestCaseClassOrTraitNotFound exception.
You can check my repo to see what I'm talking about.
For unit tests, I am using the Yoast\WPTestUtils\BrainMonkey\TestCase class, which is autoloaded. But for integration tests, I am using the Yoast\WPTestUtils\WPIntegration\TestCase class, which (because of how WordPress is wired) isn't autoloaded via composer, and is only included if the bootstrap.php file includes it (and bootstrap file only includes it for integration tests, as I don't need WordPress for the unit tests of course).
I'm using pest v1.22.3, tested on MacOS (Laravel Valet) on PHP 7.4.30.
Is this a bug or a feature? And can it be fixed so that group only ever loads the files from a specific group?
Because if not, I'll have to limit my package to only offer the integration tests functionality, and that's a bit limiting :/
EDIT:
I tried just removing the grouping limitation from the bootstrap file, but in this case my unit tests will always use the integration test case. If I manually try to use the unit base test case in the file itself I get
Test case `Yoast\WPTestUtils\BrainMonkey\TestCase` can not be used. The folder `/Users/deniszoljom/Projects/Personal/wp-pest-playground/tests/Unit/ExampleTest.php` already uses the test case `Yoast\WPTestUtils\BrainMonkey\TestCase`
Which means that integration base test case will always be used, and that's not ok...
The text was updated successfully, but these errors were encountered:
I ran into a weird problem in my pest implementation for WordPress integration testing, where I'm dependent on two different base test classes for unit and integration tests.
When running the tests, it looks like the pest will enter all the test files regardless of which group is called.
The minimum reproducible example with just pest looks like this:
phpunit.xml
:Pest.php
:I have two folders inside the
tests
folder calledUnit
andIntegration
and I've just placed some two dummy testsIntegrationTest.php
:UnitTest.php
When I run the tests using
--group
option I get the followingAnd for unit test
As you can see, in both cases the
var_dump
is called from both files.Why is this a problem?
If I have an inaccessible class that acts as a base test class for my Integration tests (inaccessible meaning if the
bootstrap.php
file isn't including it), the unit tests will fail withTestCaseClassOrTraitNotFound
exception.You can check my repo to see what I'm talking about.
For unit tests, I am using the
Yoast\WPTestUtils\BrainMonkey\TestCase
class, which is autoloaded. But for integration tests, I am using theYoast\WPTestUtils\WPIntegration\TestCase
class, which (because of how WordPress is wired) isn't autoloaded via composer, and is only included if thebootstrap.php
file includes it (and bootstrap file only includes it for integration tests, as I don't need WordPress for the unit tests of course).Related issue in my repo is this one.
I'm using pest v1.22.3, tested on MacOS (Laravel Valet) on PHP 7.4.30.
Is this a bug or a feature? And can it be fixed so that group only ever loads the files from a specific group?
Because if not, I'll have to limit my package to only offer the integration tests functionality, and that's a bit limiting :/
EDIT:
I tried just removing the grouping limitation from the bootstrap file, but in this case my unit tests will always use the integration test case. If I manually try to use the unit base test case in the file itself I get
Which means that integration base test case will always be used, and that's not ok...
The text was updated successfully, but these errors were encountered: