File tree Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Expand file tree Collapse file tree 2 files changed +10
-12
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace YorCreative \QueryWatcher ;
4
4
5
+ use Illuminate \Support \Facades \Config ;
5
6
use Illuminate \Support \Facades \DB ;
6
7
use YorCreative \QueryWatcher \Events \QueryEvent ;
7
8
@@ -12,19 +13,20 @@ class QueryWatcher
12
13
*/
13
14
public static function listen (): void
14
15
{
15
- if (config ('querywatcher.enabled ' )) {
16
- DB ::enableQueryLog ();
17
-
16
+ ! self ::isQueryWatcherEnabled () ?:
18
17
DB ::listen (function ($ query ) {
19
18
$ time_exceeds_ms_enabled = self ::timeExceedsMsEnabled ();
20
19
21
- if (isset ($ time_exceeds_ms_enabled )
22
- && self ::getTimeExceedsMs () < $ query ->time
23
- || ! isset ($ time_exceeds_ms_enabled )) {
20
+ if ($ time_exceeds_ms_enabled && self ::getTimeExceedsMs () < $ query ->time
21
+ || ! $ time_exceeds_ms_enabled ) {
24
22
event (new QueryEvent ($ query ));
25
23
}
26
24
});
27
- }
25
+ }
26
+
27
+ public static function isQueryWatcherEnabled ()
28
+ {
29
+ return Config::get ('querywatcher.enabled ' ) ?? false ;
28
30
}
29
31
30
32
/**
Original file line number Diff line number Diff line change @@ -17,18 +17,14 @@ class CaptureQueryTest extends TestCase
17
17
*/
18
18
public function it_can_capture_a_query ()
19
19
{
20
- $ this ->markTestSkipped ('Uncomment for local development testing. Fails Github Pipeline Test. ' );
21
-
22
20
HTTP ::fake ();
23
21
24
22
(new Test ())
25
23
->newQuery ()
26
24
->get ();
27
25
28
26
$ this ->assertEventBroadcasted (
29
- 'query.event ' ,
30
- 'private-query.event. ' .config ('querywatcher.token ' ),
31
- 1
27
+ 'query.event '
32
28
);
33
29
}
34
30
You can’t perform that action at this time.
0 commit comments