diff --git a/src/Client.php b/src/Client.php index 1636cc6f..32b9b708 100644 --- a/src/Client.php +++ b/src/Client.php @@ -16,9 +16,9 @@ use ArrayIterator; use InvalidArgumentException; use IteratorAggregate; use Predis\Command\CommandInterface; +use Predis\Command\Container\ContainerFactory; +use Predis\Command\Container\ContainerInterface; use Predis\Command\RawCommand; -use Predis\Command\Redis\Container\ContainerFactory; -use Predis\Command\Redis\Container\ContainerInterface; use Predis\Command\ScriptCommand; use Predis\Configuration\Options; use Predis\Configuration\OptionsInterface; @@ -346,29 +346,29 @@ class Client implements ClientInterface, IteratorAggregate } /** - * @param $name + * @param string $name * @return ContainerInterface */ - public function __get($name) + public function __get(string $name) { return ContainerFactory::create($this, $name); } /** - * @param $name - * @param $value + * @param string $name + * @param mixed $value * @return mixed */ - public function __set($name, $value) + public function __set(string $name, $value) { throw new RuntimeException('Not allowed'); } /** - * @param $name + * @param string $name * @return mixed */ - public function __isset($name) + public function __isset(string $name) { throw new RuntimeException('Not allowed'); } diff --git a/src/ClientContextInterface.php b/src/ClientContextInterface.php index 0de20a32..95f1590e 100644 --- a/src/ClientContextInterface.php +++ b/src/ClientContextInterface.php @@ -178,7 +178,9 @@ use Predis\Command\Redis\Container\Search\FTCURSOR; * @method $this jsonforget(string $key, string $path = '$') * @method $this jsonget(string $key, string $indent = '', string $newline = '', string $space = '', string ...$paths) * @method $this jsonnumincrby(string $key, string $path, int $value) + * @method $this jsonmerge(string $key, string $path, string $value) * @method $this jsonmget(array $keys, string $path) + * @method $this jsonmset(string ...$keyPathValue) * @method $this jsonobjkeys(string $key, string $path = '$') * @method $this jsonobjlen(string $key, string $path = '$') * @method $this jsonresp(string $key, string $path = '$') diff --git a/src/ClientInterface.php b/src/ClientInterface.php index e46209df..924db1ec 100644 --- a/src/ClientInterface.php +++ b/src/ClientInterface.php @@ -187,7 +187,9 @@ use Predis\Response\Status; * @method int jsonforget(string $key, string $path = '$') * @method string jsonget(string $key, string $indent = '', string $newline = '', string $space = '', string ...$paths) * @method string jsonnumincrby(string $key, string $path, int $value) + * @method Status jsonmerge(string $key, string $path, string $value) * @method array jsonmget(array $keys, string $path) + * @method Status jsonmset(string ...$keyPathValue) * @method array jsonobjkeys(string $key, string $path = '$') * @method array jsonobjlen(string $key, string $path = '$') * @method array jsonresp(string $key, string $path = '$') diff --git a/src/Command/Redis/Container/ACL.php b/src/Command/Container/ACL.php similarity index 93% rename from src/Command/Redis/Container/ACL.php rename to src/Command/Container/ACL.php index 2699d37e..25f86cc3 100644 --- a/src/Command/Redis/Container/ACL.php +++ b/src/Command/Container/ACL.php @@ -10,7 +10,7 @@ * file that was distributed with this source code. */ -namespace Predis\Command\Redis\Container; +namespace Predis\Command\Container; use Predis\Response\Status; diff --git a/src/Command/Redis/Container/AbstractContainer.php b/src/Command/Container/AbstractContainer.php similarity index 95% rename from src/Command/Redis/Container/AbstractContainer.php rename to src/Command/Container/AbstractContainer.php index 6ba86d0f..950346ba 100644 --- a/src/Command/Redis/Container/AbstractContainer.php +++ b/src/Command/Container/AbstractContainer.php @@ -10,7 +10,7 @@ * file that was distributed with this source code. */ -namespace Predis\Command\Redis\Container; +namespace Predis\Command\Container; use Predis\ClientInterface; diff --git a/src/Command/Redis/Container/ContainerFactory.php b/src/Command/Container/ContainerFactory.php similarity index 93% rename from src/Command/Redis/Container/ContainerFactory.php rename to src/Command/Container/ContainerFactory.php index 79d3de09..68f39a33 100644 --- a/src/Command/Redis/Container/ContainerFactory.php +++ b/src/Command/Container/ContainerFactory.php @@ -10,7 +10,7 @@ * file that was distributed with this source code. */ -namespace Predis\Command\Redis\Container; +namespace Predis\Command\Container; use Predis\ClientConfiguration; use Predis\ClientInterface; @@ -18,7 +18,7 @@ use UnexpectedValueException; class ContainerFactory { - private const CONTAINER_NAMESPACE = "Predis\Command\Redis\Container"; + private const CONTAINER_NAMESPACE = "Predis\Command\Container"; /** * Mappings for class names that corresponds to PHP reserved words. @@ -26,7 +26,7 @@ class ContainerFactory * @var array */ private static $specialMappings = [ - 'FUNCTION' => FunctionContainer::class, + 'FUNCTION' => FUNCTIONS::class, ]; /** diff --git a/src/Command/Redis/Container/ContainerInterface.php b/src/Command/Container/ContainerInterface.php similarity index 78% rename from src/Command/Redis/Container/ContainerInterface.php rename to src/Command/Container/ContainerInterface.php index ce3989b5..b4e1b0e6 100644 --- a/src/Command/Redis/Container/ContainerInterface.php +++ b/src/Command/Container/ContainerInterface.php @@ -10,7 +10,7 @@ * file that was distributed with this source code. */ -namespace Predis\Command\Redis\Container; +namespace Predis\Command\Container; interface ContainerInterface { @@ -18,11 +18,11 @@ interface ContainerInterface * Creates Redis container command with subcommand as virtual method name * and sends a request to the server. * - * @param $subcommandID - * @param $arguments + * @param string $subcommandID + * @param array $arguments * @return mixed */ - public function __call($subcommandID, $arguments); + public function __call(string $subcommandID, array $arguments); /** * Returns containerCommandId of specific container command. diff --git a/src/Command/Redis/Container/FunctionContainer.php b/src/Command/Container/FUNCTIONS.php similarity index 84% rename from src/Command/Redis/Container/FunctionContainer.php rename to src/Command/Container/FUNCTIONS.php index d757a44f..5b5c7860 100644 --- a/src/Command/Redis/Container/FunctionContainer.php +++ b/src/Command/Container/FUNCTIONS.php @@ -10,7 +10,7 @@ * file that was distributed with this source code. */ -namespace Predis\Command\Redis\Container; +namespace Predis\Command\Container; use Predis\Response\Status; @@ -18,7 +18,7 @@ use Predis\Response\Status; * @method string load(string $functionCode, bool $replace = 'false') * @method Status delete(string $libraryName) */ -class FunctionContainer extends AbstractContainer +class FUNCTIONS extends AbstractContainer { public function getContainerCommandId(): string { diff --git a/src/Command/Redis/Container/Json/JSONDEBUG.php b/src/Command/Container/Json/JSONDEBUG.php similarity index 82% rename from src/Command/Redis/Container/Json/JSONDEBUG.php rename to src/Command/Container/Json/JSONDEBUG.php index b20baca0..0bf4e862 100644 --- a/src/Command/Redis/Container/Json/JSONDEBUG.php +++ b/src/Command/Container/Json/JSONDEBUG.php @@ -10,9 +10,9 @@ * file that was distributed with this source code. */ -namespace Predis\Command\Redis\Container\Json; +namespace Predis\Command\Container\Json; -use Predis\Command\Redis\Container\AbstractContainer; +use Predis\Command\Container\AbstractContainer; /** * @method array memory(string $key, string $path) diff --git a/src/Command/Redis/Container/Search/FTCONFIG.php b/src/Command/Container/Search/FTCONFIG.php similarity index 84% rename from src/Command/Redis/Container/Search/FTCONFIG.php rename to src/Command/Container/Search/FTCONFIG.php index 9e80b8c5..5f718d3d 100644 --- a/src/Command/Redis/Container/Search/FTCONFIG.php +++ b/src/Command/Container/Search/FTCONFIG.php @@ -10,9 +10,9 @@ * file that was distributed with this source code. */ -namespace Predis\Command\Redis\Container\Search; +namespace Predis\Command\Container\Search; -use Predis\Command\Redis\Container\AbstractContainer; +use Predis\Command\Container\AbstractContainer; use Predis\Response\Status; /** diff --git a/src/Command/Redis/Container/Search/FTCURSOR.php b/src/Command/Container/Search/FTCURSOR.php similarity index 85% rename from src/Command/Redis/Container/Search/FTCURSOR.php rename to src/Command/Container/Search/FTCURSOR.php index 4d47c9c0..1cd4fa87 100644 --- a/src/Command/Redis/Container/Search/FTCURSOR.php +++ b/src/Command/Container/Search/FTCURSOR.php @@ -10,10 +10,10 @@ * file that was distributed with this source code. */ -namespace Predis\Command\Redis\Container\Search; +namespace Predis\Command\Container\Search; use Predis\Command\Argument\Search\CursorArguments; -use Predis\Command\Redis\Container\AbstractContainer; +use Predis\Command\Container\AbstractContainer; use Predis\Response\Status; /** diff --git a/src/Command/Redis/Json/JSONMERGE.php b/src/Command/Redis/Json/JSONMERGE.php new file mode 100644 index 00000000..a1322283 --- /dev/null +++ b/src/Command/Redis/Json/JSONMERGE.php @@ -0,0 +1,29 @@ + $argumentsLength || - !is_array($arguments[static::$keysArgumentPositionOffset]) + static::$keysArgumentPositionOffset > $argumentsLength + || !is_array($arguments[static::$keysArgumentPositionOffset]) ) { throw new UnexpectedValueException('Wrong keys argument type or position offset'); } diff --git a/src/Configuration/Options.php b/src/Configuration/Options.php index de6504f7..3fff0412 100644 --- a/src/Configuration/Options.php +++ b/src/Configuration/Options.php @@ -67,8 +67,8 @@ class Options implements OptionsInterface public function defined($option) { return - array_key_exists($option, $this->options) || - array_key_exists($option, $this->input) + array_key_exists($option, $this->options) + || array_key_exists($option, $this->input) ; } @@ -78,8 +78,8 @@ class Options implements OptionsInterface public function __isset($option) { return ( - array_key_exists($option, $this->options) || - array_key_exists($option, $this->input) + array_key_exists($option, $this->options) + || array_key_exists($option, $this->input) ) && $this->__get($option) !== null; } diff --git a/src/Connection/RelayMethods.php b/src/Connection/RelayMethods.php index 0e460a6e..a52c4a03 100644 --- a/src/Connection/RelayMethods.php +++ b/src/Connection/RelayMethods.php @@ -32,7 +32,7 @@ trait RelayMethods * @param string $pattern * @return bool */ - public function onInvalidated(?callable $callback, ?string $pattern = null) + public function onInvalidated(?callable $callback, string $pattern = null) { return $this->client->onInvalidated($callback, $pattern); } @@ -129,7 +129,7 @@ trait RelayMethods * @param ?int $db * @return bool */ - public function flushMemory(?string $endpointId = null, int $db = null) + public function flushMemory(string $endpointId = null, int $db = null) { return $this->client->flushMemory($endpointId, $db); } diff --git a/src/PubSub/AbstractConsumer.php b/src/PubSub/AbstractConsumer.php index 653517a0..c9ea2d65 100644 --- a/src/PubSub/AbstractConsumer.php +++ b/src/PubSub/AbstractConsumer.php @@ -32,7 +32,7 @@ abstract class AbstractConsumer implements Iterator public const STATUS_SUBSCRIBED = 2; // 0b0010 public const STATUS_PSUBSCRIBED = 4; // 0b0100 - protected $position = null; + protected $position; protected $statusFlags = self::STATUS_VALID; /** diff --git a/tests/PHPUnit/OneOfConstraint.php b/tests/PHPUnit/OneOfConstraint.php index 7c30cdbd..79529d38 100644 --- a/tests/PHPUnit/OneOfConstraint.php +++ b/tests/PHPUnit/OneOfConstraint.php @@ -44,7 +44,7 @@ class OneOfConstraint extends Constraint } /** - * @param $other + * @param mixed $other * @return string */ protected function failureDescription($other): string diff --git a/tests/PHPUnit/PredisTestCase.php b/tests/PHPUnit/PredisTestCase.php index d334f59a..d67829e8 100644 --- a/tests/PHPUnit/PredisTestCase.php +++ b/tests/PHPUnit/PredisTestCase.php @@ -22,7 +22,7 @@ use Predis\Connection; */ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase { - protected $redisServerVersion = null; + protected $redisServerVersion; protected $redisJsonVersion; /** @@ -73,7 +73,7 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase * * @return RedisCommandConstraint */ - public function isRedisCommand($command = null, ?array $arguments = null): RedisCommandConstraint + public function isRedisCommand($command = null, array $arguments = null): RedisCommandConstraint { return new RedisCommandConstraint($command, $arguments); } @@ -224,7 +224,7 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase * * @return Client */ - protected function createClient(?array $parameters = null, ?array $options = null, ?bool $flushdb = true): Client + protected function createClient(array $parameters = null, array $options = null, ?bool $flushdb = true): Client { $parameters = array_merge( $this->getDefaultParametersArray(), @@ -300,7 +300,6 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase * the default connection parameters used by Predis or a set of connection * parameters specified in the optional second argument. * - * @param array|string|null $parameters Optional connection parameters * * @return MockObject|Connection\NodeConnectionInterface @@ -362,9 +361,9 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase $this->getName(false) ); - if (isset($annotations['method']['requiresRedisVersion'], $annotations['method']['group']) && - !empty($annotations['method']['requiresRedisVersion']) && - in_array('connected', $annotations['method']['group']) + if (isset($annotations['method']['requiresRedisVersion'], $annotations['method']['group']) + && !empty($annotations['method']['requiresRedisVersion']) + && in_array('connected', $annotations['method']['group']) ) { return $annotations['method']['requiresRedisVersion'][0]; } @@ -517,9 +516,9 @@ abstract class PredisTestCase extends \PHPUnit\Framework\TestCase $this->getName(false) ); - if (isset($annotations['method'][$moduleAnnotation], $annotations['method']['group']) && - !empty($annotations['method'][$moduleAnnotation]) && - in_array('connected', $annotations['method']['group'], true) + if (isset($annotations['method'][$moduleAnnotation], $annotations['method']['group']) + && !empty($annotations['method'][$moduleAnnotation]) + && in_array('connected', $annotations['method']['group'], true) ) { return $annotations['method'][$moduleAnnotation][0]; } diff --git a/tests/PHPUnit/RedisCommandConstraint.php b/tests/PHPUnit/RedisCommandConstraint.php index 8cb77e18..d4e0b4ec 100644 --- a/tests/PHPUnit/RedisCommandConstraint.php +++ b/tests/PHPUnit/RedisCommandConstraint.php @@ -25,7 +25,7 @@ class RedisCommandConstraint extends \PHPUnit\Framework\Constraint\Constraint * @param string|CommandInterface $command Expected command instance or command ID * @param ?array $arguments Expected command arguments */ - public function __construct($command, ?array $arguments = null) + public function __construct($command, array $arguments = null) { if ($command instanceof CommandInterface) { $this->commandID = strtoupper($command->getId()); diff --git a/tests/Predis/Cluster/PredisStrategyTest.php b/tests/Predis/Cluster/PredisStrategyTest.php index 594c4ed3..fbf7922c 100644 --- a/tests/Predis/Cluster/PredisStrategyTest.php +++ b/tests/Predis/Cluster/PredisStrategyTest.php @@ -310,7 +310,7 @@ class PredisStrategyTest extends PredisTestCase * * @return array */ - protected function getExpectedCommands(?string $type = null): array + protected function getExpectedCommands(string $type = null): array { $commands = [ /* commands operating on the key space */ diff --git a/tests/Predis/Cluster/RedisStrategyTest.php b/tests/Predis/Cluster/RedisStrategyTest.php index d19eec85..dd570d53 100644 --- a/tests/Predis/Cluster/RedisStrategyTest.php +++ b/tests/Predis/Cluster/RedisStrategyTest.php @@ -333,7 +333,7 @@ class RedisStrategyTest extends PredisTestCase * * @return array */ - protected function getExpectedCommands(?string $type = null): array + protected function getExpectedCommands(string $type = null): array { $commands = [ /* commands operating on the key space */ diff --git a/tests/Predis/Command/Redis/Container/AbstractContainerTest.php b/tests/Predis/Command/Container/AbstractContainerTest.php similarity index 98% rename from tests/Predis/Command/Redis/Container/AbstractContainerTest.php rename to tests/Predis/Command/Container/AbstractContainerTest.php index 7a91307e..857f7502 100644 --- a/tests/Predis/Command/Redis/Container/AbstractContainerTest.php +++ b/tests/Predis/Command/Container/AbstractContainerTest.php @@ -10,7 +10,7 @@ * file that was distributed with this source code. */ -namespace Predis\Command\Redis\Container; +namespace Predis\Command\Container; use PHPUnit\Framework\TestCase; use Predis\ClientInterface; diff --git a/tests/Predis/Command/Redis/Container/ContainerFactoryTest.php b/tests/Predis/Command/Container/ContainerFactoryTest.php similarity index 93% rename from tests/Predis/Command/Redis/Container/ContainerFactoryTest.php rename to tests/Predis/Command/Container/ContainerFactoryTest.php index f98901e1..2aa13044 100644 --- a/tests/Predis/Command/Redis/Container/ContainerFactoryTest.php +++ b/tests/Predis/Command/Container/ContainerFactoryTest.php @@ -10,12 +10,12 @@ * file that was distributed with this source code. */ -namespace Predis\Command\Redis\Container; +namespace Predis\Command\Container; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Predis\ClientInterface; -use Predis\Command\Redis\Container\Search\FTCONFIG; +use Predis\Command\Container\Search\FTCONFIG; use UnexpectedValueException; class ContainerFactoryTest extends TestCase @@ -73,7 +73,7 @@ class ContainerFactoryTest extends TestCase public function containerProvider(): array { return [ - 'core command' => ['function', FunctionContainer::class], + 'core command' => ['function', FUNCTIONS::class], 'module command' => ['ftconfig', FTCONFIG::class], ]; } diff --git a/tests/Predis/Command/Redis/EVALSHA_RO_Test.php b/tests/Predis/Command/Redis/EVALSHA_RO_Test.php index 596e4c38..74ad40ce 100644 --- a/tests/Predis/Command/Redis/EVALSHA_RO_Test.php +++ b/tests/Predis/Command/Redis/EVALSHA_RO_Test.php @@ -61,10 +61,10 @@ class EVALSHA_RO_Test extends PredisCommandTestCase /** * @group connected * @dataProvider scriptsProvider - * @param string $script - * @param array $keys - * @param array $arguments - * @param $expectedResponse + * @param string $script + * @param array $keys + * @param array $arguments + * @param mixed $expectedResponse * @return void * @requiresRedisVersion >= 7.0.0 */ diff --git a/tests/Predis/Command/Redis/EVAL_RO_Test.php b/tests/Predis/Command/Redis/EVAL_RO_Test.php index 89c93d40..cdeb5b70 100644 --- a/tests/Predis/Command/Redis/EVAL_RO_Test.php +++ b/tests/Predis/Command/Redis/EVAL_RO_Test.php @@ -61,11 +61,11 @@ class EVAL_RO_Test extends PredisCommandTestCase /** * @group connected * @dataProvider scriptsProvider - * @param array $dictionary - * @param string $script - * @param array $keys - * @param array $arguments - * @param $expectedResponse + * @param array $dictionary + * @param string $script + * @param array $keys + * @param array $arguments + * @param mixed $expectedResponse * @return void * @requiresRedisVersion >= 7.0.0 */ diff --git a/tests/Predis/Command/Redis/EXPIREAT_Test.php b/tests/Predis/Command/Redis/EXPIREAT_Test.php index 44829683..cee43824 100644 --- a/tests/Predis/Command/Redis/EXPIREAT_Test.php +++ b/tests/Predis/Command/Redis/EXPIREAT_Test.php @@ -166,14 +166,14 @@ class EXPIREAT_Test extends PredisCommandTestCase ['noExpiry', time() + 10, 'XX'], ], 'only if new expiry is greater then current one' => [ - ['newExpiryLower', 'value', 'EXAT', time() + 1000], - ['newExpiryGreater', 'value', 'EXAT', time() + 10], + ['newExpiryLower', 'value', 'EX', 1000], + ['newExpiryGreater', 'value', 'EX', 10], ['newExpiryGreater', time() + 20, 'GT'], ['newExpiryLower', time() + 20, 'GT'], ], 'only if new expiry is lower then current one' => [ - ['newExpiryLower', 'value', 'EXAT', time() + 1000], - ['newExpiryGreater', 'value', 'EXAT', time() + 10], + ['newExpiryLower', 'value', 'EX', 1000], + ['newExpiryGreater', 'value', 'EX', 10], ['newExpiryLower', time() + 20, 'LT'], ['newExpiryGreater', time() + 20, 'LT'], ], diff --git a/tests/Predis/Command/Redis/FCALL_RO_Test.php b/tests/Predis/Command/Redis/FCALL_RO_Test.php index a90695f3..87a3d334 100644 --- a/tests/Predis/Command/Redis/FCALL_RO_Test.php +++ b/tests/Predis/Command/Redis/FCALL_RO_Test.php @@ -113,8 +113,8 @@ class FCALL_RO_Test extends PredisCommandTestCase ); if ( - isset($annotations['method']['group']) && - in_array('connected', $annotations['method']['group'], true) + isset($annotations['method']['group']) + && in_array('connected', $annotations['method']['group'], true) ) { $redis = $this->getClient(); $redis->function->delete(self::LIB_NAME); diff --git a/tests/Predis/Command/Redis/FCALL_Test.php b/tests/Predis/Command/Redis/FCALL_Test.php index 8729e6f1..4e4ab055 100644 --- a/tests/Predis/Command/Redis/FCALL_Test.php +++ b/tests/Predis/Command/Redis/FCALL_Test.php @@ -78,9 +78,9 @@ class FCALL_Test extends PredisCommandTestCase /** * @group connected * @dataProvider functionsProvider - * @param string $function - * @param array $functionArguments - * @param $expectedResponse + * @param string $function + * @param array $functionArguments + * @param mixed $expectedResponse * @return void * @requiresRedisVersion >= 7.0.0 */ diff --git a/tests/Predis/Command/Redis/Json/JSONMERGE_Test.php b/tests/Predis/Command/Redis/Json/JSONMERGE_Test.php new file mode 100644 index 00000000..b9cb7a74 --- /dev/null +++ b/tests/Predis/Command/Redis/Json/JSONMERGE_Test.php @@ -0,0 +1,103 @@ +getCommand(); + $command->setArguments($arguments); + + $this->assertSame($expected, $command->getArguments()); + } + + /** + * @group disconnected + */ + public function testParseResponse(): void + { + $this->assertSame(1, $this->getCommand()->parseResponse(1)); + } + + /** + * @dataProvider jsonProvider + * @group connected + * @param array $setArguments + * @param array $mergeArguments + * @param string $expectedResponse + * @return void + * @requiresRedisJsonVersion >= 2.6.0 + */ + public function testMergeCorrectlyMergeJsonValues( + array $setArguments, + array $mergeArguments, + string $expectedResponse + ): void { + $redis = $this->getClient(); + + $this->assertEquals('OK', $redis->jsonset(...$setArguments)); + $this->assertEquals('OK', $redis->jsonmerge(...$mergeArguments)); + $this->assertEquals($expectedResponse, $redis->jsonget('key')); + } + + public function jsonProvider(): array + { + return [ + 'create non-existing value' => [ + ['key', '$', '{"a":2}'], + ['key', '$.b', '8'], + '{"a":2,"b":8}', + ], + 'replace existing value' => [ + ['key', '$', '{"a":2}'], + ['key', '$.a', '3'], + '{"a":3}', + ], + 'replace an array' => [ + ['key', '$', '{"a":[2,4,6,8]}'], + ['key', '$.a', '[10,12]'], + '{"a":[10,12]}', + ], + 'merge in multiple-paths' => [ + ['key', '$', '{"f1": {"a":1}, "f2":{"a":2}}'], + ['key', '$', '{"f2":{"a":3, "b":4}, "f3":[2,4,6]}'], + '{"f1":{"a":1},"f2":{"a":3,"b":4},"f3":[2,4,6]}', + ], + ]; + } +} diff --git a/tests/Predis/Command/Redis/Json/JSONMSET_Test.php b/tests/Predis/Command/Redis/Json/JSONMSET_Test.php new file mode 100644 index 00000000..2083d39c --- /dev/null +++ b/tests/Predis/Command/Redis/Json/JSONMSET_Test.php @@ -0,0 +1,85 @@ +getCommand(); + $command->setArguments($arguments); + + $this->assertSame($expected, $command->getArguments()); + } + + /** + * @group disconnected + */ + public function testParseResponse(): void + { + $this->assertSame(1, $this->getCommand()->parseResponse(1)); + } + + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 2.6.0 + */ + public function testSetMultipleJsonDocuments(): void + { + $redis = $this->getClient(); + + $this->assertEquals('OK', $redis->jsonmset('doc1', '$', '{"a":2}', 'doc2', '$', '{"b":3}')); + $this->assertEquals(['[{"a":2}]', '[{"b":3}]'], $redis->jsonmget(['doc1', 'doc2'], '$')); + } + + /** + * @group connected + * @return void + * @requiresRedisJsonVersion >= 2.6.0 + */ + public function testThrowsExceptionOnNewValuesNotInTheRootPath(): void + { + $redis = $this->getClient(); + + $this->expectException(ServerException::class); + $this->expectExceptionMessage('ERR new objects must be created at the root'); + + $redis->jsonmset('doc1', '$', '{"a":2}', 'doc2', '$.f', '{"b":3}'); + } +} diff --git a/tests/Predis/Command/Redis/LCS_Test.php b/tests/Predis/Command/Redis/LCS_Test.php index 839084a3..72cb5c6c 100644 --- a/tests/Predis/Command/Redis/LCS_Test.php +++ b/tests/Predis/Command/Redis/LCS_Test.php @@ -58,9 +58,9 @@ class LCS_Test extends PredisCommandTestCase /** * @group connected * @dataProvider stringsProvider - * @param array $stringsArguments - * @param array $functionArguments - * @param $expectedResponse + * @param array $stringsArguments + * @param array $functionArguments + * @param mixed $expectedResponse * @return void * @requiresRedisVersion >= 7.0.0 */ diff --git a/tests/Predis/Command/Redis/Search/FTSEARCH_Test.php b/tests/Predis/Command/Redis/Search/FTSEARCH_Test.php index 58254af5..dfca91d5 100644 --- a/tests/Predis/Command/Redis/Search/FTSEARCH_Test.php +++ b/tests/Predis/Command/Redis/Search/FTSEARCH_Test.php @@ -113,6 +113,9 @@ class FTSEARCH_Test extends PredisCommandTestCase $ftCreateResponse = $redis->ftcreate('idx_hash', $schema, $ftCreateArguments); $this->assertEquals('OK', $ftCreateResponse); + // Timeout to make sure that index created before search performed. + usleep(2000); + $ftSearchArguments = new SearchArguments(); $ftSearchArguments->addReturn(1, 'should_return'); diff --git a/tests/Predis/Command/Redis/ZINTERCARD_Test.php b/tests/Predis/Command/Redis/ZINTERCARD_Test.php index d307eff1..7923b4d8 100644 --- a/tests/Predis/Command/Redis/ZINTERCARD_Test.php +++ b/tests/Predis/Command/Redis/ZINTERCARD_Test.php @@ -110,8 +110,8 @@ class ZINTERCARD_Test extends PredisCommandTestCase /** * @group connected * @dataProvider unexpectedValuesProvider - * @param $keys - * @param $limit + * @param mixed $keys + * @param mixed $limit * @param string $expectedExceptionMessage * @return void * @requiresRedisVersion >= 7.0.0 diff --git a/tests/Predis/Command/Redis/ZINTERSTORE_Test.php b/tests/Predis/Command/Redis/ZINTERSTORE_Test.php index 3c7229a9..bad586c1 100644 --- a/tests/Predis/Command/Redis/ZINTERSTORE_Test.php +++ b/tests/Predis/Command/Redis/ZINTERSTORE_Test.php @@ -133,9 +133,9 @@ class ZINTERSTORE_Test extends PredisCommandTestCase /** * @dataProvider unexpectedValueProvider - * @param string $destination - * @param $keys - * @param $weights + * @param string $destination + * @param mixed $keys + * @param mixed $weights * @param string $aggregate * @param string $expectedExceptionMessage * @return void diff --git a/tests/Predis/Command/Redis/ZINTER_Test.php b/tests/Predis/Command/Redis/ZINTER_Test.php index 9390cd5a..22eaef5b 100644 --- a/tests/Predis/Command/Redis/ZINTER_Test.php +++ b/tests/Predis/Command/Redis/ZINTER_Test.php @@ -127,8 +127,8 @@ class ZINTER_Test extends PredisCommandTestCase /** * @dataProvider unexpectedValueProvider - * @param $keys - * @param $weights + * @param mixed $keys + * @param mixed $weights * @param string $aggregate * @param bool $withScores * @param string $expectedExceptionMessage diff --git a/tests/Predis/Command/Redis/ZRANGESTORE_Test.php b/tests/Predis/Command/Redis/ZRANGESTORE_Test.php index d60e4ad6..2989a3ed 100644 --- a/tests/Predis/Command/Redis/ZRANGESTORE_Test.php +++ b/tests/Predis/Command/Redis/ZRANGESTORE_Test.php @@ -102,14 +102,14 @@ class ZRANGESTORE_Test extends PredisCommandTestCase /** * @group connected * @dataProvider unexpectedValuesProvider - * @param int|string $min - * @param int|string $max - * @param string|bool $by - * @param $rev - * @param $limit - * @param int $offset - * @param int $count - * @param string $expectedExceptionMessage + * @param int|string $min + * @param int|string $max + * @param string|bool $by + * @param $rev + * @param $limit + * @param int $offset + * @param int $count + * @param string $expectedExceptionMessage * @return void * @requiresRedisVersion >= 6.2.0 */ diff --git a/tests/Predis/Command/Redis/ZUNIONSTORE_Test.php b/tests/Predis/Command/Redis/ZUNIONSTORE_Test.php index 3bc036a4..2d9e8532 100644 --- a/tests/Predis/Command/Redis/ZUNIONSTORE_Test.php +++ b/tests/Predis/Command/Redis/ZUNIONSTORE_Test.php @@ -133,9 +133,9 @@ class ZUNIONSTORE_Test extends PredisCommandTestCase /** * @dataProvider unexpectedValueProvider - * @param string $destination - * @param $keys - * @param $weights + * @param string $destination + * @param $keys + * @param $weights * @param string $aggregate * @param string $expectedExceptionMessage * @return void diff --git a/tests/Predis/Command/Redis/ZUNION_Test.php b/tests/Predis/Command/Redis/ZUNION_Test.php index 2e1d3ed4..0cd033c9 100644 --- a/tests/Predis/Command/Redis/ZUNION_Test.php +++ b/tests/Predis/Command/Redis/ZUNION_Test.php @@ -101,8 +101,8 @@ class ZUNION_Test extends PredisCommandTestCase /** * @dataProvider unexpectedValueProvider - * @param $keys - * @param $weights + * @param $keys + * @param $weights * @param string $aggregate * @param bool $withScores * @param string $expectedExceptionMessage diff --git a/tests/Predis/Replication/ReplicationStrategyTest.php b/tests/Predis/Replication/ReplicationStrategyTest.php index ca9ae4bd..128bbce4 100644 --- a/tests/Predis/Replication/ReplicationStrategyTest.php +++ b/tests/Predis/Replication/ReplicationStrategyTest.php @@ -390,7 +390,7 @@ class ReplicationStrategyTest extends PredisTestCase * * @return array */ - protected function getExpectedCommands(?string $type = null): array + protected function getExpectedCommands(string $type = null): array { $commands = [ /* commands operating on the connection */