mirror of
https://github.com/predis/predis.git
synced 2026-09-15 12:57:10 +00:00
Fixed bug with incorrect multiple words processing (#1325)
* Fixed bug with incorrect multiple words processing * Convert subcommand string to lower case * Update SubcommandStrategyResolver.php * Added test coverage * Codestyle fixes --------- Co-authored-by: Till Krüss <tillkruss@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
732abc88a2
commit
90da582efc
@@ -41,7 +41,7 @@ class FUNCTIONS extends RedisCommand
|
||||
|
||||
public function setArguments(array $arguments)
|
||||
{
|
||||
$strategy = $this->strategyResolver->resolve('functions', $arguments[0]);
|
||||
$strategy = $this->strategyResolver->resolve('functions', strtolower($arguments[0]));
|
||||
$arguments = $strategy->processArguments($arguments);
|
||||
|
||||
parent::setArguments($arguments);
|
||||
|
||||
@@ -18,13 +18,28 @@ class SubcommandStrategyResolver implements StrategyResolverInterface
|
||||
{
|
||||
private const CONTAINER_COMMANDS_NAMESPACE = 'Predis\Command\Strategy\ContainerCommands';
|
||||
|
||||
/**
|
||||
* @var ?string
|
||||
*/
|
||||
private $separator;
|
||||
|
||||
public function __construct(string $separator = null)
|
||||
{
|
||||
$this->separator = $separator;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function resolve(string $commandId, string $subcommandId): SubcommandStrategyInterface
|
||||
{
|
||||
$subcommandStrategyClass = ucfirst(strtolower($subcommandId)) . 'Strategy';
|
||||
$commandDirectoryName = ucfirst(strtolower($commandId));
|
||||
$subcommandStrategyClass = ucwords($subcommandId) . 'Strategy';
|
||||
$commandDirectoryName = ucwords($commandId);
|
||||
|
||||
if (!is_null($this->separator)) {
|
||||
$subcommandStrategyClass = str_replace($this->separator, '', $subcommandStrategyClass);
|
||||
$commandDirectoryName = str_replace($this->separator, '', $commandDirectoryName);
|
||||
}
|
||||
|
||||
if (class_exists(
|
||||
$containerCommandClass = self::CONTAINER_COMMANDS_NAMESPACE . '\\' . $commandDirectoryName . '\\' . $subcommandStrategyClass
|
||||
|
||||
@@ -19,23 +19,27 @@ use Predis\Command\Strategy\ContainerCommands\Functions\LoadStrategy;
|
||||
class SubcommandStrategyResolverTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var StrategyResolverInterface
|
||||
*/
|
||||
private $resolver;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resolver = new SubcommandStrategyResolver();
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
* @return void
|
||||
*/
|
||||
public function testResolveCorrectStrategy(): void
|
||||
{
|
||||
$resolver = new SubcommandStrategyResolver();
|
||||
$expectedStrategy = new LoadStrategy();
|
||||
|
||||
$this->assertEquals($expectedStrategy, $this->resolver->resolve('functions', 'load'));
|
||||
$this->assertEquals($expectedStrategy, $resolver->resolve('functions', 'load'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @group disconnected
|
||||
* @return void
|
||||
*/
|
||||
public function testResolveCorrectlyResolvesStrategyWithGivenWordSeparator(): void
|
||||
{
|
||||
$resolver = new SubcommandStrategyResolver('_');
|
||||
$expectedStrategy = new LoadStrategy();
|
||||
|
||||
$this->assertEquals($expectedStrategy, $resolver->resolve('functions_', 'load_'));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,9 +47,11 @@ class SubcommandStrategyResolverTest extends TestCase
|
||||
*/
|
||||
public function testResolveThrowsExceptionOnNonExistingStrategy(): void
|
||||
{
|
||||
$resolver = new SubcommandStrategyResolver();
|
||||
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('Non-existing container command given');
|
||||
|
||||
$this->resolver->resolve('foo', 'bar');
|
||||
$resolver->resolve('foo', 'bar');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user