Change method to undefine commands in factory.

The previous implementation was not good because we were exposing in the
public API an internal implementation detail of the base factory class,
furthermore it made Predis\Command\Factory::define() confusing. Having a
separate method to undefine commands in the factory is self-explanatory.

We also changed `Predis\Configuration\Option\Commands` accordingly when
a dictionary of $commandID => $classCommand is passed to the "commands"
client option and $classCommand is NULL.

A few minor changes (mostly cosmetic or documentation) were applied too.

From feedback to PR #644.
This commit is contained in:
Daniele Alessandri
2020-08-21 13:30:23 +02:00
parent d4bcf912f4
commit f06a41cfdc
6 changed files with 78 additions and 21 deletions
+1 -1
View File
@@ -702,7 +702,7 @@ class ClientTest extends PredisTestCase
public function testThrowsExceptionOnNonRegisteredRedisCommand()
{
$this->expectException('Predis\ClientException');
$this->expectExceptionMessage("Command 'INVALIDCOMMAND' is not a registered Redis command");
$this->expectExceptionMessage("Command `INVALIDCOMMAND` is not a registered Redis command");
$client = new Client();
$client->invalidCommand();
+4 -4
View File
@@ -102,7 +102,7 @@ class RedisFactoryTest extends PredisTestCase
$this->assertTrue($factory->supportsCommand('PING'));
$this->assertSame('Predis\Command\Redis\PING', $factory->getCommandClass('PING'));
$factory->defineCommand('PING', null);
$factory->undefineCommand('PING');
$this->assertFalse($factory->supportsCommand('PING'));
$this->assertNull($factory->getCommandClass('PING'));
@@ -121,7 +121,7 @@ class RedisFactoryTest extends PredisTestCase
$this->assertTrue($factory->supportsCommand('MOCK'));
$this->assertSame($commandClass, $factory->getCommandClass('MOCK'));
$factory->defineCommand('MOCK', null);
$factory->undefineCommand('MOCK');
$this->assertFalse($factory->supportsCommand('MOCK'));
$this->assertNull($factory->getCommandClass('MOCK'));
@@ -133,7 +133,7 @@ class RedisFactoryTest extends PredisTestCase
public function testDefineInvalidCommand()
{
$this->expectException('InvalidArgumentException');
$this->expectExceptionMessage("The class 'stdClass' is not a valid command class.");
$this->expectExceptionMessage("Class stdClass must implement Predis\Command\CommandInterface");
$factory = new RedisFactory();
@@ -175,7 +175,7 @@ class RedisFactoryTest extends PredisTestCase
public function testCreateUndefinedCommand()
{
$this->expectException('Predis\ClientException');
$this->expectExceptionMessage("Command 'UNKNOWN' is not a registered Redis command.");
$this->expectExceptionMessage("Command `UNKNOWN` is not a registered Redis command.");
$factory = new RedisFactory();
@@ -101,6 +101,29 @@ class CommandsTest extends PredisTestCase
$this->assertSame('Predis\Command\RawCommand', $commands->getCommandClass('BAR'));
}
/**
* @group disconnected
*/
public function testAcceptsDictionaryOfCommandsWithNullsToUndefineCommandsAsValue()
{
$option = new Commands();
$options = $this->getMockBuilder('Predis\Configuration\OptionsInterface')->getMock();
$input = array(
'ECHO' => null,
'EVAL' => null,
'FOO' => null,
);
$commands = $option->filter($options, $input);
$this->assertInstanceOf('Predis\Command\FactoryInterface', $commands);
$this->assertNull($commands->getCommandClass('ECHO'));
$this->assertNull($commands->getCommandClass('EVAL'));
$this->assertNull($commands->getCommandClass('FOO'));
}
/**
* @group disconnected
*/