From 5c5dd40527855199503acb59dbc2a67a6e7ccab9 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Tue, 25 Mar 2014 15:11:26 +0100 Subject: [PATCH] Remove implementation of Predis\Command\Command::__toString(). Issue #151 pointed to a flaw in how command instances were converted to strings: we were simply truncating their arguments when exceeding a certain size as this was mostly intended for logging or debugging, but this approach breaks strings containing multibyte characters so we decided to drop this feature altogether for the sake of simplicity. It is still possible to replicate the same (and eventually improved) behavior externally by fetching ID and arguments of a command out of a command instance using the public methods made available by the Predis\Command\CommandInterface. --- CHANGELOG.md | 2 ++ lib/Predis/Command/Command.php | 32 ---------------------------- tests/Predis/Command/CommandTest.php | 32 ---------------------------- 3 files changed, 2 insertions(+), 64 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 447a3b96..f36fef2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -51,6 +51,8 @@ v1.0.0 (201x-xx-xx) - `Predis\Command\AbstractCommand` is now `Predis\Command\Command` - `Predis\Command\ScriptedCommand` is now `Predis\Command\ScriptCommand` +- Dropped `Predis\Command\Command::__toString()` (see issue #151). + - Renamed `Predis\Connection\ConnectionInterface::writeCommand()` into `writeRequest()` for consistency with its counterpart, `readResponse()`. diff --git a/lib/Predis/Command/Command.php b/lib/Predis/Command/Command.php index 09d24a42..40d9e434 100644 --- a/lib/Predis/Command/Command.php +++ b/lib/Predis/Command/Command.php @@ -94,38 +94,6 @@ abstract class Command implements CommandInterface return $data; } - /** - * Helper function used to reduce a list of arguments to a string. - * - * @param string $accumulator Temporary string. - * @param string $argument Current argument. - * @return string - */ - protected function toStringArgumentReducer($accumulator, $argument) - { - if (strlen($argument) > 32) { - $argument = substr($argument, 0, 32) . '[...]'; - } - - $accumulator .= " $argument"; - - return $accumulator; - } - - /** - * Returns a partial string representation of the command with its arguments. - * - * @return string - */ - public function __toString() - { - return array_reduce( - $this->getArguments(), - array($this, 'toStringArgumentReducer'), - $this->getId() - ); - } - /** * Normalizes the arguments array passed to a Redis command. * diff --git a/tests/Predis/Command/CommandTest.php b/tests/Predis/Command/CommandTest.php index d31f0647..f19610e9 100644 --- a/tests/Predis/Command/CommandTest.php +++ b/tests/Predis/Command/CommandTest.php @@ -117,38 +117,6 @@ class CommandTest extends PredisTestCase $this->assertNull($command->getHash()); } - /** - * @group disconnected - */ - public function testToString() - { - $expected = 'SET key value'; - $arguments = array('key', 'value'); - - $command = $this->getMockForAbstractClass('Predis\Command\Command'); - $command->expects($this->once())->method('getId')->will($this->returnValue('SET')); - - $command->setRawArguments($arguments); - - $this->assertEquals($expected, (string) $command); - } - - /** - * @group disconnected - */ - public function testToStringWithLongArguments() - { - $expected = 'SET key abcdefghijklmnopqrstuvwxyz012345[...]'; - $arguments = array('key', 'abcdefghijklmnopqrstuvwxyz0123456789'); - - $command = $this->getMockForAbstractClass('Predis\Command\Command'); - $command->expects($this->once())->method('getId')->will($this->returnValue('SET')); - - $command->setRawArguments($arguments); - - $this->assertEquals($expected, (string) $command); - } - /** * @group disconnected */