Skip to content

Commit da494da

Browse files
committed
test: fix determinism of CacheTest
1 parent efe179f commit da494da

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

tests/system/Router/Attributes/CacheTest.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use CodeIgniter\Test\Mock\MockAppConfig;
2323
use Config\Services;
2424
use PHPUnit\Framework\Attributes\Group;
25+
use PHPUnit\Framework\MockObject\MockObject;
2526

2627
/**
2728
* @internal
@@ -33,16 +34,17 @@ protected function setUp(): void
3334
{
3435
parent::setUp();
3536

36-
// Clear cache before each test
3737
cache()->clean();
38-
38+
Services::resetSingle('response');
3939
Time::setTestNow('2026-01-10 12:00:00');
4040
}
4141

4242
protected function tearDown(): void
4343
{
4444
parent::tearDown();
4545

46+
cache()->clean();
47+
Services::resetSingle('response');
4648
Time::setTestNow();
4749
}
4850

@@ -215,11 +217,17 @@ private function createMockRequest(string $method, string $path, string $query =
215217

216218
$request = $this->getMockBuilder(IncomingRequest::class)
217219
->setConstructorArgs([$config, $uri, null, $userAgent])
218-
->onlyMethods(['isCLI'])
220+
->onlyMethods(['isCLI', 'withMethod', 'getMethod'])
219221
->getMock();
220222
$request->method('isCLI')->willReturn(false);
221-
$request->setMethod($method);
223+
$request->method('withMethod')->willReturnCallback(
224+
static function (string $method) use ($request): MockObject&IncomingRequest {
225+
$request->method('getMethod')->willReturn($method);
226+
227+
return $request;
228+
},
229+
);
222230

223-
return $request;
231+
return $request->withMethod($method);
224232
}
225233
}

0 commit comments

Comments
 (0)