Files
predis/tests/Predis/Command/Redis/XGROUP_Test.php
T
Vladyslav Vildanov e60030770e Added support for XGROUP container commands (#1324)
* Codestyle changes related to php-cs-fixer update (#1311)

* Codestyle changes

* Added missing type-hints

* Added GETDEL command to KeyPrefixProcessor (#1306)

* Added GETDEL command to KeyPrefixProcessor

* Added test coverage

* Codestyle fixes

* Added timeout after FT.CREATE call

* Added support for JSON.MERGE command (#1304)

* Added support for JSON.MSET command (#1307)

* Fixed subcommand test bug (#1313)

* Update CHANGELOG.md

* Update CHANGELOG.md

* Added support for XGROUP container commands

* 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>

* Added split words handling

* Fixed command id to be lowercase

* Fixed test decorator

* Added support for FUNCTION DUMP, FUNCTION FLUSH, FUNCTION RESTORE commands (#1332)

* Added support for CLIENT NO-EVICT command (#1335)

* Added support for FUNCTION KILL, FUNCTION LIST, FUNCTION STATS commands (#1334)

* Added support for FUNCTION KILL, FUNCTION LIST, FUNCTION STATS commands

* Marked tests as relay-incompatible

* Removed old tests

* Removed old tests

* Move back missing test

* Removed blank space

* Removed old test

---------

Co-authored-by: Till Krüss <tillkruss@users.noreply.github.com>
2023-07-26 16:10:53 +03:00

246 lines
6.7 KiB
PHP

<?php
/*
* This file is part of the Predis package.
*
* (c) 2009-2020 Daniele Alessandri
* (c) 2021-2023 Till Krüss
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Command\Redis;
use Predis\Response\ServerException;
class XGROUP_Test extends PredisCommandTestCase
{
/**
* {@inheritDoc}
*/
protected function getExpectedCommand(): string
{
return XGROUP::class;
}
/**
* {@inheritDoc}
*/
protected function getExpectedId(): string
{
return 'XGROUP';
}
/**
* @dataProvider createArgumentsProvider
* @group disconnected
* @param array $actualArguments
* @param array $expectedResponse
* @return void
*/
public function testCreateFilterArguments(array $actualArguments, array $expectedResponse): void
{
$command = $this->getCommand();
$command->setArguments($actualArguments);
$this->assertSame($expectedResponse, $command->getArguments());
}
/**
* @group disconnected
* @return void
*/
public function testCreateConsumerFilterArguments(): void
{
$arguments = ['CREATECONSUMER', 'key', 'group', 'consumer'];
$expected = ['CREATECONSUMER', 'key', 'group', 'consumer'];
$command = $this->getCommand();
$command->setArguments($arguments);
$this->assertSameValues($expected, $command->getArguments());
}
/**
* @group disconnected
* @return void
*/
public function testDelConsumerFilterArguments(): void
{
$arguments = ['DELCONSUMER', 'key', 'group', 'consumer'];
$expected = ['DELCONSUMER', 'key', 'group', 'consumer'];
$command = $this->getCommand();
$command->setArguments($arguments);
$this->assertSameValues($expected, $command->getArguments());
}
/**
* @group disconnected
* @return void
*/
public function testDestroyFilterArguments(): void
{
$arguments = ['DESTROY', 'key', 'group'];
$expected = ['DESTROY', 'key', 'group'];
$command = $this->getCommand();
$command->setArguments($arguments);
$this->assertSameValues($expected, $command->getArguments());
}
/**
* @dataProvider setIdArgumentsProvider
* @group disconnected
* @param array $actualArguments
* @param array $expectedResponse
* @return void
*/
public function testSetIdFilterArguments(array $actualArguments, array $expectedResponse): void
{
$command = $this->getCommand();
$command->setArguments($actualArguments);
$this->assertSame($expectedResponse, $command->getArguments());
}
/**
* @group disconnected
*/
public function testParseResponse(): void
{
$this->assertSame(1, $this->getCommand()->parseResponse(1));
}
/**
* @group connected
* @return void
* @requiresRedisVersion >= 5.0.0
*/
public function testCreatesNewConsumerGroupForExistingStream(): void
{
$redis = $this->getClient();
$redis->xadd('key', ['field' => 'value']);
$this->assertEquals('OK', $redis->xgroup->create('key', 'group', '$'));
}
/**
* @group connected
* @return void
* @requiresRedisVersion >= 5.0.0
*/
public function testCreateThrowsExceptionOnNonExistingStream(): void
{
$redis = $this->getClient();
$this->expectException(ServerException::class);
$this->expectExceptionMessage(
'ERR The XGROUP subcommand requires the key to exist.'
);
$this->assertEquals('OK', $redis->xgroup->create('key', 'group', '$'));
}
/**
* @group connected
* @return void
* @requiresRedisVersion >= 6.2.0
*/
public function testCreatesNewConsumerForExistingConsumerGroup(): void
{
$redis = $this->getClient();
$redis->xadd('key', ['field' => 'value']);
$this->assertEquals('OK', $redis->xgroup->create('key', 'group', '$'));
$this->assertSame(1, $redis->xgroup->createConsumer('key', 'group', 'consumer'));
}
/**
* @group connected
* @return void
* @requiresRedisVersion >= 6.2.0
*/
public function testRemovesConsumerFromExistingConsumerGroup(): void
{
$redis = $this->getClient();
$redis->xadd('key', ['field' => 'value']);
$this->assertEquals('OK', $redis->xgroup->create('key', 'group', '$'));
$this->assertSame(1, $redis->xgroup->createConsumer('key', 'group', 'consumer'));
$this->assertSame(0, $redis->xgroup->delConsumer('key', 'group', 'consumer'));
}
/**
* @group connected
* @return void
* @requiresRedisVersion >= 5.0.0
*/
public function testDestroyRemovesGivenConsumerGroup(): void
{
$redis = $this->getClient();
$redis->xadd('key', ['field' => 'value']);
$this->assertEquals('OK', $redis->xgroup->create('key', 'group', '$'));
$this->assertEquals(1, $redis->xgroup->destroy('key', 'group'));
}
/**
* @group connected
* @return void
* @requiresRedisVersion >= 5.0.0
*/
public function testSetGroupLastDeliveredId(): void
{
$redis = $this->getClient();
$redis->xadd('key', ['field' => 'value']);
$this->assertEquals('OK', $redis->xgroup->create('key', 'group', '$'));
$this->assertEquals('OK', $redis->xgroup->setId('key', 'group', '0'));
}
public function createArgumentsProvider(): array
{
return [
'with default arguments' => [
['CREATE', 'key', 'group', '$'],
['CREATE', 'key', 'group', '$'],
],
'with MKSTREAM modifier' => [
['CREATE', 'key', 'group', '$', true],
['CREATE', 'key', 'group', '$', 'MKSTREAM'],
],
'with ENTRIESREAD modifier' => [
['CREATE', 'key', 'group', '$', false, 'entry'],
['CREATE', 'key', 'group', '$', 'ENTRIESREAD', 'entry'],
],
'with all arguments modifier' => [
['CREATE', 'key', 'group', '$', true, 'entry'],
['CREATE', 'key', 'group', '$', 'MKSTREAM', 'ENTRIESREAD', 'entry'],
],
];
}
public function setIdArgumentsProvider(): array
{
return [
'with default arguments' => [
['SETID', 'key', 'group', '$'],
['SETID', 'key', 'group', '$'],
],
'with ENTRIESREAD modifier' => [
['SETID', 'key', 'group', '$', 'entry'],
['SETID', 'key', 'group', '$', 'ENTRIESREAD', 'entry'],
],
];
}
}