Skip to content

test: convert the suite to Pest 5 - #84

Merged
crazeydave merged 1 commit into
mainfrom
test/pest-5
Sep 24, 2026
Merged

crazeydave merged 1 commit into
mainfrom
test/pest-5

Conversation

@crazeydave

Copy link
Copy Markdown
Contributor

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.2 in require-dev, and pestphp/pest-plugin allowed. composer test, test:unit and test:coverage now run pest. CI's composer test -- --coverage-clover ... works as it is.
  • tests/Pest.php binds the whole Unit directory to TsmlForUnity\Tests\TestCase (wp-mocks). Every file extended it before, so unlike Scrutiny and Trusted there's no pure-PHP split.
  • tests/bootstrap.php defines PHPUNIT_COMPOSER_INSTALL when it's missing. Pest's launcher doesn't define it, and the separate-process children need it to load Composer.
  • 64 test files converted with a one-off AST-driven script that splices the original source text. Pest Drift wasn't used. declare(strict_types=1), namespaces and comments are preserved.
    • setUp/tearDown became beforeEach/afterEach.
    • #[CoversClass] became covers(): 66 targets before, 66 after.
    • Data providers were inlined as ->with([...]).
    • expectException became ->throws().
    • Assertions became expect() chains.
    • Helpers became file-level functions, using test() where they needed the test case.
  • Every spec shares the namespace TsmlForUnity\Tests\Unit, so helper names that recurred across files got file-specific ones (stubGroupPostTypeGuard, stubMemberPostTypeGuard, …), as did the two POST_ID constants.
  • Brain Monkey's expect() is now called as Functions\expect(), so it doesn't shadow Pest's.
  • The 38 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 on acf_get_field() defines it for the rest of the process, which would break AcfFieldKeyResolverTest's ACF-absent branch.
  • HasLoggerTest: the same problem, for wp_log().

Things that bit

  • A test property named $options collides with a typed ?TestCaseOptions $options property 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.
  • Pest's printer lists @-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 a quietUnserialize() helper with a scoped error handler.

Before / after (local, PHP 8.5, pcov)

PHPUnit on main Pest on this branch
Tests 719 719 (700 passed plus 19 with the pre-existing PHPUnit deprecations)
Assertions 2118 2082 (the 38 removed placeholders, net of the new expect() chains)
Skipped / risky / warnings 0 / 0 / 0 0 / 0 / 0
Lines covered 3001 / 3214 (93.37%) 2999 / 3214 (93.31%)

The two lines lost are the if (!defined('ABSPATH')) guards in TsmlPasswordCredentialTable and TsmlMember. 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 --locked and composer build:production all pass locally.

composer.lock also moves bleeding-deacons/unity (the ../unity path repository) from dev-feat/php-84-wp-711 to dev-main, because the lock records whichever branch the sibling checkout is on. main is what CI checks out.

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.
@coderabbitai

coderabbitai Bot commented Sep 24, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 5350b5a0-a606-4fb7-9f20-588ef6620693


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@crazeydave
crazeydave merged commit 04f59a1 into main Sep 24, 2026
6 checks passed
@crazeydave
crazeydave deleted the test/pest-5 branch September 24, 2026 03:02
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