Skip to content

Commit a820445

Browse files
committed
test: make time testable.
1 parent 591e8fa commit a820445

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

tests/_support/Log/Handlers/TestHandler.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ public function __construct(array $config)
3737
{
3838
parent::__construct($config);
3939

40-
Time::setTestNow('2023-11-25 12:00:00');
41-
4240
$this->handles = $config['handles'] ?? [];
4341
$this->destination = $this->path . 'log-' . Time::now()->format('Y-m-d') . '.' . $this->fileExtension;
4442

@@ -56,9 +54,7 @@ public function __construct(array $config)
5654
*/
5755
public function handle($level, $message): bool
5856
{
59-
Time::setTestNow('2023-11-25 12:00:00');
60-
61-
$date = Time::now()->format('Y-m-d');
57+
$date = Time::now()->format($this->dateFormat);
6258

6359
self::$logs[] = strtoupper($level) . ' - ' . $date . ' --> ' . $message;
6460

tests/system/HTTP/RedirectExceptionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ protected function setUp(): void
3333
Services::injectMock('logger', new Logger(new LoggerConfig()));
3434
}
3535

36+
protected function tearDown(): void
37+
{
38+
parent::tearDown();
39+
40+
// Reset the current time.
41+
Time::setTestNow();
42+
}
43+
3644
public function testResponse(): void
3745
{
3846
$response = (new RedirectException(

0 commit comments

Comments
 (0)