Repository navigation
test: convert the suite to Pest 5 - #84
Merged
Merged
Conversation
Every test file is now a closure-based Pest spec except two kept as PHPUnit classes, because they need #[RunInSeparateProcess] and Pest refuses process isolation: AcfFieldKeyResolverResolveTest (a Brain Monkey expectation on acf_get_field() defines it for the rest of the process) and HasLoggerTest (the same, for wp_log()). Pest runs both. tests/Pest.php binds the whole Unit directory to TsmlForUnity\Tests\TestCase: every file extended it before, so there is no pure-PHP split here. tests/bootstrap.php defines PHPUNIT_COMPOSER_INSTALL when missing, which Pest's launcher does not and the separate-process children need. The conversion is one-to-one: 719 tests before and after, same datasets (providers inlined with ->with()), same covers() targets. Helpers became file-level functions; names that recurred across files got file-specific ones, as did the POST_ID constants, since every spec shares one namespace. Assertion placeholders (assertTrue(true)) are gone; their messages are kept as comments, and the 12 tests that then had no assertion use ->throwsNoExceptions(). A property named $options was renamed: it collides with a typed property on Pest's own test case. composer test, test:unit and test:coverage now run pest.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Converts the test suite from PHPUnit classes to Pest 5 closure specs. One test per original test method, so the count is unchanged.
What changed
pestphp/pest ^5.2in require-dev, andpestphp/pest-pluginallowed.composer test,test:unitandtest:coveragenow runpest. CI'scomposer test -- --coverage-clover ...works as it is.tests/Pest.phpbinds the wholeUnitdirectory toTsmlForUnity\Tests\TestCase(wp-mocks). Every file extended it before, so unlike Scrutiny and Trusted there's no pure-PHP split.tests/bootstrap.phpdefinesPHPUNIT_COMPOSER_INSTALLwhen it's missing. Pest's launcher doesn't define it, and the separate-process children need it to load Composer.declare(strict_types=1), namespaces and comments are preserved.setUp/tearDownbecamebeforeEach/afterEach.#[CoversClass]becamecovers(): 66 targets before, 66 after.->with([...]).expectExceptionbecame->throws().expect()chains.test()where they needed the test case.TsmlForUnity\Tests\Unit, so helper names that recurred across files got file-specific ones (stubGroupPostTypeGuard,stubMemberPostTypeGuard, …), as did the twoPOST_IDconstants.expect()is now called asFunctions\expect(), so it doesn't shadow Pest's.assertTrue(true)placeholders are gone and their messages are kept as comments. The 12 tests that were left with no assertion use->throwsNoExceptions(). The rest carry a counted mock or Mockery expectation.Kept as PHPUnit classes
Both need
#[RunInSeparateProcess], and Pest refuses process isolation. Pest runs them as they are.AcfFieldKeyResolverResolveTest: an expectation onacf_get_field()defines it for the rest of the process, which would breakAcfFieldKeyResolverTest's ACF-absent branch.HasLoggerTest: the same problem, forwp_log().Things that bit
$optionscollides with a typed?TestCaseOptions $optionsproperty on Pest's own test case (from pest-plugin-arch), and every test in the file fails with a TypeError. It's renamed to$storedOptions.@-suppressed warnings that PHPUnit doesn't count.TsmlMeetingFactoryMetaTest's@unserialize()stubs showed as 2 "warnings" on a green run (exit 0). They now go through aquietUnserialize()helper with a scoped error handler.Before / after (local, PHP 8.5, pcov)
mainexpect()chains)The two lines lost are the
if (!defined('ABSPATH'))guards inTsmlPasswordCredentialTableandTsmlMember.covers()loads a class during collection, before coverage starts. That's expected, and Pest has no way around it.The 19 deprecations and 293 PHPUnit notices ("with*() without expects()", mocks without expectations) are pre-existing and unchanged.
PHPCS, PHPStan,
composer validate,composer audit --lockedandcomposer build:productionall pass locally.composer.lockalso movesbleeding-deacons/unity(the../unitypath repository) fromdev-feat/php-84-wp-711todev-main, because the lock records whichever branch the sibling checkout is on.mainis what CI checks out.