File tree Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Expand file tree Collapse file tree 2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -143,16 +143,20 @@ public function enableQueryLog()
143143 {
144144 parent ::enableQueryLog ();
145145
146- $ this ->commandSubscriber = new CommandSubscriber ($ this );
147- $ this ->connection ->addSubscriber ($ this ->commandSubscriber );
146+ if (! $ this ->commandSubscriber ) {
147+ $ this ->commandSubscriber = new CommandSubscriber ($ this );
148+ $ this ->connection ->addSubscriber ($ this ->commandSubscriber );
149+ }
148150 }
149151
150152 public function disableQueryLog ()
151153 {
152- parent ::disableQueryLog (); // TODO: Change the autogenerated stub
154+ parent ::disableQueryLog ();
153155
154- $ this ->connection ->removeSubscriber ($ this ->commandSubscriber );
155- $ this ->commandSubscriber = null ;
156+ if ($ this ->commandSubscriber ) {
157+ $ this ->connection ->removeSubscriber ($ this ->commandSubscriber );
158+ $ this ->commandSubscriber = null ;
159+ }
156160 }
157161
158162 protected function withFreshQueryLog ($ callback )
Original file line number Diff line number Diff line change @@ -287,9 +287,19 @@ public function testDisableQueryLog()
287287 DB ::table ('items ' )->get ();
288288 $ this ->assertCount (1 , DB ::getQueryLog ());
289289
290+ // Enable twice should only log once
291+ DB ::enableQueryLog ();
292+ DB ::table ('items ' )->get ();
293+ $ this ->assertCount (2 , DB ::getQueryLog ());
294+
290295 DB ::disableQueryLog ();
291296 DB ::table ('items ' )->get ();
292- $ this ->assertCount (1 , DB ::getQueryLog ());
297+ $ this ->assertCount (2 , DB ::getQueryLog ());
298+
299+ // Disable twice should not log
300+ DB ::disableQueryLog ();
301+ DB ::table ('items ' )->get ();
302+ $ this ->assertCount (2 , DB ::getQueryLog ());
293303 }
294304
295305 public function testSchemaBuilder ()
You can’t perform that action at this time.
0 commit comments