Chore: Upgrade PHPUnit to 12, modernize tests, refresh Rector sets#248
Chore: Upgrade PHPUnit to 12, modernize tests, refresh Rector sets#248
Conversation
- Bump phpunit/phpunit ^9.5 -> ^12.0, phpstan/phpstan ^2.0 -> ^2.1, rector/rector ^2.0 -> ^2.4. - Migrate phpunit.xml to the PHPUnit 12 schema; exclude the BaseTest trait and the misnamed UtopiaFPMRequestTest mock helper from the unit suite. - Add PHPUnit 10/11/12, code-quality, and annotations-to-attributes sets to rector.php; drop three skip entries rector reported as unregistered; skip AssertEmptyNullableObjectToAssertInstanceofRector since it weakens assertNull. - Apply rector: declare(strict_types=1) in tests, final test classes, generator data provider, and assertEquals -> assertSame where types are inferable. - Manual cleanup: assertEquals(null|true|false, x) -> specific methods; fix RequestTest::testCanRemoveHeaders which relied on null == '' loose equality (getHeader returns string); replace closure-vs-closure assertEquals in RouteTest::testCanSetAndGetAction with assertInstanceOf(Closure::class, ...). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
k6 benchmark
|
Greptile SummaryThis PR upgrades PHPUnit 9 → 12, PHPStan 2.0 → 2.1, and Rector 2.0 → 2.4, then applies the resulting automated and manual test modernisation:
Confidence Score: 4/5Safe to merge after addressing the dead-assignment bug in testCanAddCookie that leaves cookie case-normalisation completely untested. One P1 finding: the cookie case-insensitive test block in ResponseTest.php mutates throwaway array copies instead of asserting, meaning the case-normalisation path is never exercised. The remaining findings are P2 style (assertEquals → assertSame completeness in HttpTest and the e2e suite). tests/ResponseTest.php — testCanAddCookie dead-assignment block (lines 70–73) Important Files Changed
|
The CI e2e-swoole job failed because appwrite/base:0.5.0 ships PHP 8.2.6, but PHPUnit 12 requires PHP >= 8.3. Bumping to 1.2.0 (PHP 8.5.4, swoole included) matches the library's >=8.3 floor and the host test runtime. Drop the now-redundant curl_close() call in tests/e2e/Client.php — PHP 8.5 deprecates it (the handle is released on last reference since 8.0 anyway). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
PHPUnit 12 requires a <source> section for coverage to run; without it the runner emits "No filter is configured, code coverage will not be processed" and CI's --coverage-* flags exit non-zero. Point coverage at ./src. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- phpunit.xml: add xmlns:xsi and xsi:noNamespaceSchemaLocation pointing at vendor/phpunit/phpunit/phpunit.xsd so PHPUnit 12 (and IDE tooling) get XML schema validation. - HttpTest: swap reversed assertEquals(actual, expected) pairs in testCanSetRoute, testCanMatchRoute, and testCanMatchFreshRoute to the expected-first convention, and promote them to assertSame — setRoute and match return the exact Route instance, so identity is the precise check and the diff on failure reads correctly. - ResponseTest: promote fluent-interface assertions on addHeader / addCookie to assertSame for the same reason. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Summary
phpunit/phpunit^9.5 → ^12.0,phpstan/phpstan^2.0 → ^2.1,rector/rector^2.0 → ^2.4 (all pulling the current latest).AssertEmptyNullableObjectToAssertInstanceofRectorwhich weakensassertNull.declare(strict_types=1)to tests, finalizes test classes, converts the@dataProviderto a generator,assertEquals→assertSamewhere inferable) and sweep remainingassertEquals(null|true|false, …)and literal-expected cases manually.phpunit.xmlto the PHPUnit 12 schema and exclude theBaseTesttrait file and the misnamedUtopiaFPMRequestTestmock helper from the unit suite (both previously produced runner warnings).Noteworthy fixes surfaced by stricter assertions
RequestTest::testCanRemoveHeadersassertedassertEquals(null, getHeader(...)), which only passed vianull == ''loose equality —getHeaderis typedstring. NowassertSame('', …).RouteTest::testCanSetAndGetActioncompared two different closures withassertEquals— replaced withassertInstanceOf(\Closure::class, …), which is what the test actually meant.Test plan
composer analyze(PHPStan level 7) cleancomposer refactor:check(Rector dry-run) cleancomposer format:check(Pint) cleanvendor/bin/phpunit --testsuite unit— 84 tests, 248 assertions, all passe2e-fpm,e2e-swoole) — require docker fixtures, not run locally; CI should exercise them🤖 Generated with Claude Code