Skip to content

Commit

Permalink
Merge pull request #290 from lentex/feature/no-db-required
Browse files Browse the repository at this point in the history
Make DB connection optional
  • Loading branch information
freekmurze authored Jan 26, 2023
2 parents c61b10a + ffaa562 commit b1dfa5b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Watchers/DuplicateQueryWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public function register(): void

$this->enabled = $settings->send_duplicate_queries_to_ray;

if (! app()->bound('db')) {
return;
}

DB::listen(function (QueryExecuted $query) {
if (! $this->enabled()) {
return;
Expand Down
4 changes: 4 additions & 0 deletions src/Watchers/QueryWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public function register(): void

$this->enabled = $settings->send_queries_to_ray;

if (! app()->bound('db')) {
return;
}

DB::listen(function (QueryExecuted $query) {
if (! $this->enabled()) {
return;
Expand Down
4 changes: 4 additions & 0 deletions src/Watchers/SlowQueryWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public function register(): void
$this->enabled = $settings->send_slow_queries_to_ray ?? false;
$this->minimumTimeInMs = $settings->slow_query_threshold_in_ms ?? $this->minimumTimeInMs;

if (! app()->bound('db')) {
return;
}

DB::listen(function (QueryExecuted $query) {
if (! $this->enabled()) {
return;
Expand Down
12 changes: 12 additions & 0 deletions tests/RayTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\Log;
use Spatie\LaravelRay\Ray;
use Spatie\LaravelRay\RayServiceProvider;
Expand Down Expand Up @@ -151,3 +152,14 @@

expect(Ray::$projectName)->toEqual('my-project');
});

it('still boots and works although the DB facade has not been bound', function () {
unset($this->app['db']);
Facade::clearResolvedInstance('db');

(new RayServiceProvider($this->app))->boot();

ray('foo');

expect($this->client->sentRequests())->toHaveCount(1);
});

0 comments on commit b1dfa5b

Please sign in to comment.