getCommand(); $command->setArguments($arguments); $this->assertSame($expected, $command->getArguments()); } /** * @group disconnected */ public function testParseResponse(): void { $this->assertSame(1, $this->getCommand()->parseResponse(1)); } /** * @group disconnected */ public function testPrefixKeys(): void { /** @var PrefixableCommand $command */ $command = $this->getCommand(); $actualArguments = ['arg1']; $prefix = 'prefix:'; $expectedArguments = ['prefix:arg1']; $command->setArguments($actualArguments); $command->prefixKeys($prefix); $this->assertSame($expectedArguments, $command->getArguments()); } /** * @group connected * @group relay-resp3 * @dataProvider jsonProvider * @param array $jsonArguments * @param string $key * @param string $path * @param string $value * @param array $expectedStringLength * @param string $expectedModifiedJson * @return void * @requiresRedisJsonVersion >= 1.0.0 */ public function testAppendStringToExistingJsonString( array $jsonArguments, string $key, string $path, string $value, array $expectedStringLength, string $expectedModifiedJson ): void { $redis = $this->getClient(); $redis->jsonset(...$jsonArguments); $actualResponse = $redis->jsonstrappend($key, $path, $value); $this->assertSame($expectedStringLength, $actualResponse); $this->assertSame($expectedModifiedJson, $redis->jsonget($key)); } /** * @group connected * @return void * @requiresRedisJsonVersion >= 2.6.1 */ public function testAppendStringToExistingJsonStringResp3(): void { $redis = $this->getResp3Client(); $redis->jsonset('key', '$', '{"key1":"value1","key2":"value2"}'); $actualResponse = $redis->jsonstrappend('key', '$.key2', '"foo"'); $this->assertSame([9], $actualResponse); $this->assertSame('{"key1":"value1","key2":"value2foo"}', $redis->jsonget('key')); } public function jsonProvider(): array { return [ 'appends to json string on root level' => [ ['key', '$', '{"key1":"value1","key2":"value2"}'], 'key', '$.key2', '"foo"', [9], '{"key1":"value1","key2":"value2foo"}', ], 'appends to json string on nested level' => [ ['key', '$', '{"key1":{"key2":"value2"}}'], 'key', '$..key2', '"foo"', [9], '{"key1":{"key2":"value2foo"}}', ], 'appends to json string on both levels' => [ ['key', '$', '{"key1":{"key2":"value2"},"key2":"value2"}'], 'key', '$..key2', '"foo"', [9, 9], '{"key1":{"key2":"value2foo"},"key2":"value2foo"}', ], 'appends to non-json string' => [ ['key', '$', '{"key1":{"key2":[1,2,3]}}'], 'key', '$..key2', '"foo"', [null], '{"key1":{"key2":[1,2,3]}}', ], ]; } }