diff --git a/src/Watchers/RedisWatcher.php b/src/Watchers/RedisWatcher.php index d4dc915b7..310103a9d 100644 --- a/src/Watchers/RedisWatcher.php +++ b/src/Watchers/RedisWatcher.php @@ -16,6 +16,10 @@ class RedisWatcher extends Watcher */ public function register($app) { + if (! $app->bound('redis')) { + return; + } + $app['events']->listen(CommandExecuted::class, [$this, 'recordCommand']); foreach ((array) $app['redis']->connections() as $connection) { diff --git a/tests/Watchers/RedisWatcherTest.php b/tests/Watchers/RedisWatcherTest.php index edbf98677..c55c4f80d 100644 --- a/tests/Watchers/RedisWatcherTest.php +++ b/tests/Watchers/RedisWatcherTest.php @@ -2,10 +2,12 @@ namespace Laravel\Telescope\Tests\Watchers; +use Illuminate\Contracts\Foundation\Application; use Illuminate\Support\Facades\Redis; use Laravel\Telescope\EntryType; use Laravel\Telescope\Tests\FeatureTestCase; use Laravel\Telescope\Watchers\RedisWatcher; +use Mockery; class RedisWatcherTest extends FeatureTestCase { @@ -36,4 +38,22 @@ public function test_redis_watcher_registers_entries() $this->assertSame('get telescope:test', $entry->content['command']); $this->assertSame('default', $entry->content['connection']); } + + public function test_does_not_register_when_redis_unbound() + { + $app = Mockery::mock(Application::class); + + $app->makePartial(); + + $app->expects('bound') + ->with('redis') + ->andReturn(false); + + $app->shouldNotReceive('make') + ->with('redis'); + + $watcher = new RedisWatcher([]); + + $watcher->register($app); + } }