@@ -37,7 +37,7 @@ function setConfig(string|array $key, mixed $value =null)
3737}
3838
3939it ('creates directory if it does not exist for 1st query ' , function () {
40- $ query = new SqlQuery (1 , 'test ' , 5.41 , ' test ' );
40+ $ query = SqlQuery:: make (1 , 'test ' , 5.41 );
4141 setConfig ('queries.enabled ' , false );
4242 expect ($ this ->directory )->not ()->toBeDirectory ();
4343 $ this ->writer ->writeQuery ($ query );
@@ -46,7 +46,7 @@ function setConfig(string|array $key, mixed $value =null)
4646});
4747
4848it ('does not create directory if it does not exist for 2nd query ' , function () {
49- $ query = new SqlQuery (2 , 'test ' , 5.41 , ' test ' );
49+ $ query = SqlQuery:: make (2 , 'test ' , 5.41 );
5050 setConfig ('queries.enabled ' , false );
5151 expect ($ this ->directory )->not ()->toBeDirectory ();
5252 $ this ->writer ->writeQuery ($ query );
@@ -58,7 +58,7 @@ function setConfig(string|array $key, mixed $value =null)
5858 $ expectedContent = "-- header \nSample log line \n" ;
5959 $ expectedFileName = $ this ->now ->format ('Y-m ' ).'-log.sql ' ;
6060
61- $ query = new SqlQuery (1 , 'test ' , 5.41 , ' test ' );
61+ $ query = SqlQuery:: make (1 , 'test ' , 5.41 );
6262 $ this ->formatter ->shouldReceive ('getLine ' )->once ()->with ($ query )->andReturn ($ lineContent );
6363 $ this ->formatter ->shouldReceive ('getHeader ' )->once ()->withNoArgs ()->andReturn ('-- header ' );
6464
@@ -81,7 +81,7 @@ function setConfig(string|array $key, mixed $value =null)
8181 $ lineContent = 'Sample log line ' ;
8282 $ expectedContent = $ initialContent ."-- header \nSample log line \n" ;
8383
84- $ query = new SqlQuery (1 , 'test ' , 5.41 , ' test ' );
84+ $ query = SqlQuery:: make (1 , 'test ' , 5.41 );
8585 $ this ->formatter ->shouldReceive ('getLine ' )->once ()->with ($ query )->andReturn ($ lineContent );
8686 $ this ->formatter ->shouldReceive ('getHeader ' )->once ()->withNoArgs ()->andReturn ('-- header ' );
8787 setConfig ('queries.include_pattern ' , '#.*#i ' );
@@ -102,7 +102,7 @@ function setConfig(string|array $key, mixed $value =null)
102102 $ lineContent = 'Sample log line ' ;
103103 $ expectedContent = "-- header \nSample log line \n" ;
104104
105- $ query = new SqlQuery (1 , 'test ' , 5.41 , ' test ' );
105+ $ query = SqlQuery:: make (1 , 'test ' , 5.41 );
106106 $ this ->formatter ->shouldReceive ('getLine ' )->once ()->with ($ query )->andReturn ($ lineContent );
107107 $ this ->formatter ->shouldReceive ('getHeader ' )->once ()->withNoArgs ()->andReturn ('-- header ' );
108108 setConfig ([
@@ -126,8 +126,8 @@ function setConfig(string|array $key, mixed $value =null)
126126 $ lineContent = 'Sample log line ' ;
127127 $ expectedContent = "-- header \n$ lineContent \n$ lineContent \n" ;
128128
129- $ query1 = new SqlQuery (1 , 'test ' , 5.41 , ' test ' );
130- $ query2 = new SqlQuery (2 , 'test ' , 5.41 , ' test ' );
129+ $ query1 = SqlQuery:: make (1 , 'test ' , 5.41 );
130+ $ query2 = SqlQuery:: make (2 , 'test ' , 5.41 );
131131 $ this ->formatter ->shouldReceive ('getLine ' )->twice ()->andReturn ($ lineContent );
132132 $ this ->formatter ->shouldReceive ('getHeader ' )->once ()->withNoArgs ()->andReturn ('-- header ' );
133133 setConfig ([
@@ -148,7 +148,7 @@ function setConfig(string|array $key, mixed $value =null)
148148 $ lineContent = 'Sample log line ' ;
149149 $ expectedContent = "\n$ lineContent \n" ;
150150
151- $ query = new SqlQuery (1 , 'select * FROM test ' , 5.41 , ' select * FROM test ' );
151+ $ query = SqlQuery:: make (1 , 'select * FROM test ' , 5.41 );
152152 $ this ->formatter ->shouldReceive ('getLine ' )->once ()->with ($ query )->andReturn ($ lineContent );
153153 $ this ->formatter ->shouldReceive ('getHeader ' )->once ()->withNoArgs ()->andReturn ('' );
154154 setConfig ('queries.include_pattern ' , '#^SELECT .*$#i ' );
@@ -161,7 +161,7 @@ function setConfig(string|array $key, mixed $value =null)
161161});
162162
163163it ('doesnt save select query to file when pattern set to insert or update queries ' , function () {
164- $ query = new SqlQuery (1 , 'select * FROM test ' , 5.41 , ' select * FROM test ' );
164+ $ query = SqlQuery:: make (1 , 'select * FROM test ' , 5.41 );
165165 setConfig ('queries.include_pattern ' , '#^(?:UPDATE|INSERT) .*$#i ' );
166166 $ this ->writer ->writeQuery ($ query );
167167 expect ($ this ->directory )->toBeFile ()
@@ -173,7 +173,7 @@ function setConfig(string|array $key, mixed $value =null)
173173 $ lineContent = 'Sample log line ' ;
174174 $ expectedContent = "\n$ lineContent \n" ;
175175
176- $ query = new SqlQuery (1 , 'INSERT INTO test(one, two, three) values(?, ?, ?) ' , 5.41 , ' INSERT INTO test(one, two, three) values(?, ?, ?) ' );
176+ $ query = SqlQuery:: make (1 , 'INSERT INTO test(one, two, three) values(?, ?, ?) ' , 5.41 );
177177 $ this ->formatter ->shouldReceive ('getLine ' )->once ()->with ($ query )->andReturn ($ lineContent );
178178 $ this ->formatter ->shouldReceive ('getHeader ' )->once ()->withNoArgs ()->andReturn ('' );
179179 setConfig ('queries.include_pattern ' , '#^(?:UPDATE|INSERT) .*$#i ' );
@@ -190,7 +190,7 @@ function setConfig(string|array $key, mixed $value =null)
190190 $ lineContent = 'Sample log line ' ;
191191 $ expectedContent = "\n$ lineContent \n" ;
192192
193- $ query = new SqlQuery (1 , 'UPDATE test SET x = 2 WHERE id = 3 ' , 5.41 , ' UPDATE test SET x = 2 WHERE id = 3 ' );
193+ $ query = SqlQuery:: make (1 , 'UPDATE test SET x = 2 WHERE id = 3 ' , 5.41 );
194194 $ this ->formatter ->shouldReceive ('getLine ' )->once ()->with ($ query )->andReturn ($ lineContent );
195195 $ this ->formatter ->shouldReceive ('getHeader ' )->once ()->withNoArgs ()->andReturn ('' );
196196 setConfig ('queries.include_pattern ' , '#^(?:UPDATE test SET x = \d |INSERT ).*$#i ' );
@@ -203,8 +203,8 @@ function setConfig(string|array $key, mixed $value =null)
203203});
204204
205205it ('only logs slow queries ' , function () {
206- $ query1 = new SqlQuery (1 , 'test1 ' , 5.41 , ' test1 ' );
207- $ query2 = new SqlQuery (2 , 'test2 ' , 500.5 , ' test2 ' );
206+ $ query1 = SqlQuery:: make (1 , 'test1 ' , 5.41 );
207+ $ query2 = SqlQuery:: make (2 , 'test2 ' , 500.5 );
208208
209209 setConfig ('queries.min_exec_time ' , 500 );
210210
@@ -221,9 +221,9 @@ function setConfig(string|array $key, mixed $value =null)
221221});
222222
223223it ('respects query patterns ' , function () {
224- $ query1 = new SqlQuery (1 , 'select foo from bar ' , 5.41 , ' select foo from bar ' );
225- $ query2 = new SqlQuery (2 , 'update bar set foo = 1 ' , 3.55 , ' update bar set foo = 1 ' );
226- $ query3 = new SqlQuery (3 , "update bar set last_visit = '2021-06-03 10:26:00' " , 3.22 , " update bar set last_visit = '2021-06-03 10:26:00' " );
224+ $ query1 = SqlQuery:: make (1 , 'select foo from bar ' , 5.41 );
225+ $ query2 = SqlQuery:: make (2 , 'update bar set foo = 1 ' , 3.55 );
226+ $ query3 = SqlQuery:: make (3 , "update bar set last_visit = '2021-06-03 10:26:00' " , 3.22 );
227227
228228 setConfig ([
229229 'queries.include_pattern ' => '/^(?!SELECT).*$/i ' ,
@@ -244,7 +244,7 @@ function setConfig(string|array $key, mixed $value =null)
244244});
245245
246246it ('respects the report pattern from the config to determine if a query should be reported ' , function (string $ query , bool $ report ) {
247- expect ($ this ->writer ->shouldReportSqlQuery (new SqlQuery (1 , $ query , 1 , $ query )))->toBe ($ report );
247+ expect ($ this ->writer ->shouldReportSqlQuery (SqlQuery:: make (1 , $ query , 1 )))->toBe ($ report );
248248})->with ([
249249 ['select * from users ' , false ],
250250 ['delete from users ' , true ],
@@ -253,7 +253,7 @@ function setConfig(string|array $key, mixed $value =null)
253253it ('can provide a callback to the writer to determine if a query should be reported ' , function (string $ query , bool $ report ) {
254254 config (['sql-reporter.queries.report_pattern ' => null ]);
255255 Writer::shouldReportQuery (fn (SqlQuery $ query ) => ! str_contains ($ query ->rawQuery , 'sessions ' ));
256- expect ($ this ->writer ->shouldReportSqlQuery (new SqlQuery (1 , $ query , 1 , $ query )))->toBe ($ report );
256+ expect ($ this ->writer ->shouldReportSqlQuery (SqlQuery:: make (1 , $ query , 1 )))->toBe ($ report );
257257})->with ([
258258 ['delete from sessions ' , false ],
259259 ['delete from users ' , true ],
@@ -262,7 +262,7 @@ function setConfig(string|array $key, mixed $value =null)
262262it ('can combine the report pattern config and the callback to determine if a query should be reported ' , function (string $ query , bool $ report ) {
263263 config (['sql-reporter.queries.report_pattern ' => '/^DELETE.*$/i ' ]);
264264 Writer::shouldReportQuery (fn (SqlQuery $ query ) => ! str_contains ($ query ->rawQuery , 'sessions ' ));
265- expect ($ this ->writer ->shouldReportSqlQuery (new SqlQuery (1 , $ query , 1 , $ query )))->toBe ($ report );
265+ expect ($ this ->writer ->shouldReportSqlQuery (SqlQuery:: make (1 , $ query , 1 )))->toBe ($ report );
266266})->with ([
267267 ['select * from users ' , false ],
268268 ['delete from sessions ' , false ],
@@ -272,8 +272,8 @@ function setConfig(string|array $key, mixed $value =null)
272272it ('dispatches an event when there are queries to report ' , function () {
273273 Event::fake ();
274274
275- $ query1 = new SqlQuery (1 , 'select * from users ' , 5.41 , ' select * from users ' );
276- $ query2 = new SqlQuery (2 , 'delete from users ' , 5.41 , ' delete from users ' );
275+ $ query1 = SqlQuery:: make (1 , 'select * from users ' , 5.41 );
276+ $ query2 = SqlQuery:: make (2 , 'delete from users ' , 5.41 );
277277
278278 $ expectedFileName = $ this ->now ->format ('Y-m ' ).'-log.sql ' ;
279279 $ lineContent1 = 'Sample log line 1 ' ;
0 commit comments