Skip to content

Commit

Permalink
Dont register redis watcher if the redis service is not bound into th…
Browse files Browse the repository at this point in the history
…e container.
  • Loading branch information
mad-briller committed Oct 6, 2022
1 parent 345af51 commit a6fee2f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Watchers/RedisWatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions tests/Watchers/RedisWatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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);
}
}

0 comments on commit a6fee2f

Please sign in to comment.