Skip to content

Commit 6b25f1e

Browse files
committed
test: add tests for context object properties and boolean false stringification
1 parent 368cd45 commit 6b25f1e

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

‎tests/system/Log/LoggerTest.php‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,4 +521,43 @@ public function __toString(): string
521521
$this->assertCount(1, $logs);
522522
$this->assertSame($expected, $logs[0]);
523523
}
524+
525+
public function testLogObjectContextLosesProperties(): void
526+
{
527+
$config = new LoggerConfig();
528+
$logger = new Logger($config);
529+
530+
Time::setTestNow('2023-11-25 12:00:00');
531+
532+
$user = new stdClass();
533+
$user->name = 'John';
534+
$user->role = 'admin';
535+
536+
$expected = 'DEBUG - ' . Time::now()->format('Y-m-d') . ' --> User: ' . print_r($user, true);
537+
538+
$logger->log('debug', 'User: {user}', ['user' => $user]);
539+
540+
$logs = TestHandler::getLogs();
541+
542+
$this->assertCount(1, $logs);
543+
$this->assertSame($expected, $logs[0]);
544+
}
545+
546+
public function testLogBooleanFalseIsLoggedAsEmptyString(): void
547+
{
548+
$config = new LoggerConfig();
549+
$logger = new Logger($config);
550+
551+
Time::setTestNow('2023-11-25 12:00:00');
552+
553+
$expected = 'DEBUG - ' . Time::now()->format('Y-m-d') . ' --> Active: false';
554+
555+
$logger->log('debug', 'Active: {status}', ['status' => false]);
556+
557+
$logs = TestHandler::getLogs();
558+
559+
$this->assertCount(1, $logs);
560+
$this->assertSame($expected, $logs[0]);
561+
}
524562
}
563+

0 commit comments

Comments
 (0)