ソースを参照

Fix up bug detected by Psalm - add test

mscherer 3 年 前
コミット
053e300558
1 ファイル変更20 行追加1 行削除
  1. 20 1
      tests/TestCase/Database/Log/QueryLoggerTest.php

+ 20 - 1
tests/TestCase/Database/Log/QueryLoggerTest.php

@@ -56,13 +56,32 @@ class QueryLoggerTest extends TestCase
             'className' => 'Array',
             'scopes' => ['foo'],
         ]);
-        $logger->log(LogLevel::DEBUG, (string)$query, compact('query'));
+        $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