'']); $query = new LoggedQuery(); $query->query = 'SELECT a FROM b where a = ? AND b = ? AND c = ?'; $query->params = ['string', '3', null]; Log::setConfig('queryLoggerTest', [ 'className' => 'Array', 'scopes' => ['queriesLog'], ]); Log::setConfig('queryLoggerTest2', [ 'className' => 'Array', 'scopes' => ['foo'], ]); $logger->log(LogLevel::DEBUG, $query, compact('query')); $this->assertCount(1, Log::engine('queryLoggerTest')->read()); $this->assertCount(0, Log::engine('queryLoggerTest2')->read()); } /** * Tests that passed Stringable also work. */ public function testLogFunctionStringable(): void { $this->skipIf(version_compare(PHP_VERSION, '8.0', '<'), 'Stringable exists since 8.0'); $logger = new QueryLogger(['connection' => '']); $stringable = new class implements \Stringable { public function __toString(): string { return 'FooBar'; } }; $logger->log(LogLevel::DEBUG, $stringable, ['query' => null]); } /** * Tests that the connection name is logged with the query. */ public function testLogConnection(): void { $logger = new QueryLogger(['connection' => 'test']); $query = new LoggedQuery(); $query->query = 'SELECT a'; Log::setConfig('queryLoggerTest', [ 'className' => 'Array', 'scopes' => ['queriesLog'], ]); $logger->log(LogLevel::DEBUG, '', compact('query')); $this->assertStringContainsString('connection=test duration=', current(Log::engine('queryLoggerTest')->read())); } }