File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -1548,6 +1548,22 @@ public function getQueryLog()
1548
1548
return $ this ->queryLog ;
1549
1549
}
1550
1550
1551
+ /**
1552
+ * Get the connection query log with embedded bindings.
1553
+ *
1554
+ * @return array
1555
+ */
1556
+ public function getRawQueryLog ()
1557
+ {
1558
+ return array_map (fn (array $ log ) => [
1559
+ 'raw_query ' => $ this ->queryGrammar ->substituteBindingsIntoRawSql (
1560
+ $ log ['query ' ],
1561
+ $ this ->prepareBindings ($ log ['bindings ' ])
1562
+ ),
1563
+ 'time ' => $ log ['time ' ],
1564
+ ], $ this ->getQueryLog ());
1565
+ }
1566
+
1551
1567
/**
1552
1568
* Clear the query log.
1553
1569
*
Original file line number Diff line number Diff line change 87
87
* @method static void unsetTransactionManager()
88
88
* @method static bool pretending()
89
89
* @method static array getQueryLog()
90
+ * @method static array getRawQueryLog()
90
91
* @method static void flushQueryLog()
91
92
* @method static void enableQueryLog()
92
93
* @method static void disableQueryLog()
Original file line number Diff line number Diff line change @@ -502,6 +502,32 @@ public function testSchemaBuilderCanBeCreated()
502
502
$ this ->assertSame ($ connection , $ schema ->getConnection ());
503
503
}
504
504
505
+ public function testGetRawQueryLog ()
506
+ {
507
+ $ mock = $ this ->getMockConnection (['getQueryLog ' ]);
508
+ $ mock ->expects ($ this ->once ())->method ('getQueryLog ' )->willReturn ([
509
+ [
510
+ 'query ' => 'select * from tbl where col = ? ' ,
511
+ 'bindings ' => [
512
+ 0 => 'foo ' ,
513
+ ],
514
+ 'time ' => 1.23 ,
515
+ ]
516
+ ]);
517
+
518
+ $ queryGrammar = $ this ->createMock (Grammar::class);
519
+ $ queryGrammar ->expects ($ this ->once ())
520
+ ->method ('substituteBindingsIntoRawSql ' )
521
+ ->with ('select * from tbl where col = ? ' , ['foo ' ])
522
+ ->willReturn ("select * from tbl where col = 'foo' " );
523
+ $ mock ->setQueryGrammar ($ queryGrammar );
524
+
525
+ $ log = $ mock ->getRawQueryLog ();
526
+
527
+ $ this ->assertEquals ("select * from tbl where col = 'foo' " , $ log [0 ]['raw_query ' ]);
528
+ $ this ->assertEquals (1.23 , $ log [0 ]['time ' ]);
529
+ }
530
+
505
531
protected function getMockConnection ($ methods = [], $ pdo = null )
506
532
{
507
533
$ pdo = $ pdo ?: new DatabaseConnectionTestMockPDO ;
You can’t perform that action at this time.
0 commit comments