diff --git a/src/Illuminate/Redis/Connections/Connection.php b/src/Illuminate/Redis/Connections/Connection.php index e3e55e94be33..69ed5c1a313d 100644 --- a/src/Illuminate/Redis/Connections/Connection.php +++ b/src/Illuminate/Redis/Connections/Connection.php @@ -118,12 +118,25 @@ public function command($method, array $parameters = []) $time = round((microtime(true) - $start) * 1000, 2); if (isset($this->events)) { - $this->event(new CommandExecuted($method, $parameters, $time, $this)); + $this->event(new CommandExecuted( + $method, $this->parseParametersForEvent($parameters), $time, $this + )); } return $result; } + /** + * Parse the command's parameters for event dispatching. + * + * @param array $parameters + * @return array + */ + protected function parseParametersForEvent(array $parameters) + { + return $parameters; + } + /** * Fire the given event if possible. * diff --git a/src/Illuminate/Redis/Connections/PredisConnection.php b/src/Illuminate/Redis/Connections/PredisConnection.php index f642dd622a9a..94f7cb41dac2 100644 --- a/src/Illuminate/Redis/Connections/PredisConnection.php +++ b/src/Illuminate/Redis/Connections/PredisConnection.php @@ -4,6 +4,7 @@ use Closure; use Illuminate\Contracts\Redis\Connection as ConnectionContract; +use Predis\Command\Argument\ArrayableArgument; /** * @mixin \Predis\Client @@ -50,4 +51,20 @@ public function createSubscription($channels, Closure $callback, $method = 'subs unset($loop); } + + /** + * Parse the command's parameters for event dispatching. + * + * @param array $parameters + * @return array + */ + protected function parseParametersForEvent(array $parameters) + { + return collect($parameters) + ->transform(function ($parameter) { + return $parameter instanceof ArrayableArgument + ? $parameter->toArray() + : $parameter; + })->all(); + } } diff --git a/tests/Integration/Redis/PredisConnectionTest.php b/tests/Integration/Redis/PredisConnectionTest.php new file mode 100644 index 000000000000..e25dbbc8fe4e --- /dev/null +++ b/tests/Integration/Redis/PredisConnectionTest.php @@ -0,0 +1,44 @@ +get('config')->set('database.redis.client', 'predis'); + } + + public function testPredisCanEmitEventWithArrayableArgumentObject() + { + if (! class_exists(SearchArguments::class)) { + return $this->markTestSkipped('Skipped tests on predis/predis dependency without '.SearchArguments::class); + } + + $event = Event::fake(); + + $command = 'ftSearch'; + $parameters = ['test', '*', (new SearchArguments())->dialect('3')->withScores()]; + + $predis = new PredisConnection($client = m::mock(Client::class)); + $predis->setEventDispatcher($event); + + $client->shouldReceive($command)->with(...$parameters)->andReturnTrue(); + + $this->assertTrue($predis->command($command, $parameters)); + + $event->assertDispatched(function (CommandExecuted $event) use ($command) { + return $event->connection instanceof PredisConnection + && $event->command === $command + && $event->parameters === ['test', '*', ['DIALECT', '3', 'WITHSCORES']]; + }); + } +}