Skip to content

Commit d1eced0

Browse files
loks0nclaude
andauthored
Chore: Upgrade PHPUnit to 12, modernize tests, refresh Rector sets (#248)
* Chore: Upgrade PHPUnit to 12, modernize tests, refresh Rector sets - 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> * Chore: Bump swoole test image to appwrite/base:1.2.0 (PHP 8.5) 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> * Chore: Declare coverage source in phpunit.xml 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> * Chore: Add PHPUnit schema reference, tighten Route/Response assertions - 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> --------- Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 938e3bc commit d1eced0

13 files changed

Lines changed: 571 additions & 625 deletions

Dockerfile.swoole

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN composer install --ignore-platform-reqs --optimize-autoloader \
1313
--no-plugins --no-scripts --prefer-dist \
1414
`if [ "$TESTING" != "true" ]; then echo "--no-dev"; fi`
1515

16-
FROM appwrite/base:0.5.0 AS final
16+
FROM appwrite/base:1.2.0 AS final
1717
LABEL maintainer="team@appwrite.io"
1818

1919
WORKDIR /usr/src/code

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
"require-dev": {
5555
"doctrine/instantiator": "^1.5",
5656
"laravel/pint": "1.*",
57-
"phpstan/phpstan": "^2.0",
58-
"phpunit/phpunit": "^9.5.25",
59-
"rector/rector": "^2.0",
57+
"phpstan/phpstan": "^2.1",
58+
"phpunit/phpunit": "^12.0",
59+
"rector/rector": "^2.4",
6060
"swoole/ide-helper": "4.8.3"
6161
}
6262
}

composer.lock

Lines changed: 331 additions & 388 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
<phpunit
2-
backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false"
11-
>
12-
<testsuites>
13-
<testsuite name="unit">
14-
<directory>./tests</directory>
15-
<exclude>./tests/e2e</exclude>
16-
</testsuite>
17-
<testsuite name="e2e-fpm">
18-
<file>./tests/e2e/ResponseFPMTest.php</file>
19-
</testsuite>
20-
<testsuite name="e2e-swoole">
21-
<file>./tests/e2e/ResponseSwooleTest.php</file>
22-
</testsuite>
23-
</testsuites>
1+
<?xml version="1.0"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<testsuites>
4+
<testsuite name="unit">
5+
<directory>./tests</directory>
6+
<exclude>./tests/e2e</exclude>
7+
<exclude>./tests/BaseTest.php</exclude>
8+
<exclude>./tests/UtopiaFPMRequestTest.php</exclude>
9+
</testsuite>
10+
<testsuite name="e2e-fpm">
11+
<file>./tests/e2e/ResponseFPMTest.php</file>
12+
</testsuite>
13+
<testsuite name="e2e-swoole">
14+
<file>./tests/e2e/ResponseSwooleTest.php</file>
15+
</testsuite>
16+
</testsuites>
17+
<source>
18+
<include>
19+
<directory>./src</directory>
20+
</include>
21+
</source>
2422
</phpunit>

rector.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@
1616
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
1717
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
1818
use Rector\Php82\Rector\Class_\ReadOnlyClassRector;
19+
use Rector\PHPUnit\CodeQuality\Rector\MethodCall\AssertEmptyNullableObjectToAssertInstanceofRector;
20+
use Rector\PHPUnit\Set\PHPUnitSetList;
1921
use Rector\Set\ValueObject\LevelSetList;
2022
use Rector\Set\ValueObject\SetList;
21-
use Rector\TypeDeclaration\Rector\ClassMethod\ParamTypeByParentCallTypeRector;
22-
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromAssignsRector;
23-
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;
2423

2524
return RectorConfig::configure()
2625
->withPaths([
@@ -34,6 +33,11 @@
3433
SetList::DEAD_CODE,
3534
SetList::EARLY_RETURN,
3635
SetList::INSTANCEOF,
36+
PHPUnitSetList::PHPUNIT_100,
37+
PHPUnitSetList::PHPUNIT_110,
38+
PHPUnitSetList::PHPUNIT_120,
39+
PHPUnitSetList::PHPUNIT_CODE_QUALITY,
40+
PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES,
3741
])
3842
->withImportNames(importShortClasses: false, removeUnusedImports: true)
3943
->withSkip([
@@ -45,11 +49,6 @@
4549
ExplicitBoolCompareRector::class,
4650
SimplifyEmptyCheckOnEmptyArrayRector::class,
4751

48-
// Can throw TypeError on previously-working callers (library is public API)
49-
TypedPropertyFromAssignsRector::class,
50-
TypedPropertyFromStrictConstructorRector::class,
51-
ParamTypeByParentCallTypeRector::class,
52-
5352
// Different distribution and failure mode than rand()
5453
RandomFunctionRector::class,
5554

@@ -68,4 +67,7 @@
6867

6968
// Throws TypeError when args are objects/arrays — review per-call
7069
NullToStrictStringFuncCallArgRector::class,
70+
71+
// Weakens `assertNull` to `assertNotInstanceOf` — keep the stricter assertion
72+
AssertEmptyNullableObjectToAssertInstanceofRector::class,
7173
]);

tests/BaseTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,39 @@ trait BaseTest
99
public function testResponse(): void
1010
{
1111
$response = $this->client->call(Client::METHOD_GET, '/');
12-
$this->assertEquals('Hello World!', $response['body']);
12+
$this->assertSame('Hello World!', $response['body']);
1313
}
1414

1515
public function testResponseValue(): void
1616
{
1717
$response = $this->client->call(Client::METHOD_GET, '/value/123');
18-
$this->assertEquals('123', $response['body']);
18+
$this->assertSame('123', $response['body']);
1919
}
2020

2121
public function testChunkResponse(): void
2222
{
2323
$response = $this->client->call(Client::METHOD_GET, '/chunked');
24-
$this->assertEquals('Hello World!', $response['body']);
24+
$this->assertSame('Hello World!', $response['body']);
2525
}
2626

2727
public function testRedirect(): void
2828
{
2929
$response = $this->client->call(Client::METHOD_GET, '/redirect');
30-
$this->assertEquals('Hello World!', $response['body']);
30+
$this->assertSame('Hello World!', $response['body']);
3131
}
3232

3333
public function testFile(): void
3434
{
3535
$response = $this->client->call(Client::METHOD_GET, '/humans.txt');
36-
$this->assertEquals(204, $response['headers']['status-code']);
36+
$this->assertSame(204, $response['headers']['status-code']);
3737
}
3838

3939
public function testSetCookie(): void
4040
{
4141
$response = $this->client->call(Client::METHOD_GET, '/set-cookie');
42-
$this->assertEquals(200, $response['headers']['status-code']);
43-
$this->assertEquals('value1', $response['cookies']['key1']);
44-
$this->assertEquals('value2', $response['cookies']['key2']);
42+
$this->assertSame(200, $response['headers']['status-code']);
43+
$this->assertSame('value1', $response['cookies']['key1']);
44+
$this->assertSame('value2', $response['cookies']['key2']);
4545
}
4646

4747
public function testAliases(): void
@@ -50,8 +50,8 @@ public function testAliases(): void
5050

5151
foreach ($paths as $path) {
5252
$response = $this->client->call(Client::METHOD_GET, $path);
53-
$this->assertEquals(200, $response['headers']['status-code']);
54-
$this->assertEquals('Aliased!', $response['body']);
53+
$this->assertSame(200, $response['headers']['status-code']);
54+
$this->assertSame('Aliased!', $response['body']);
5555
}
5656
}
5757
}

0 commit comments

Comments
 (0)