mirror of
https://github.com/predis/predis.git
synced 2026-08-27 10:34:10 +00:00
4195f137ef
* Added ACL RESP3 integration tests * Added RESP3 commands integration tests and response handling * Fixed required server versions * Added more integration tests for RESP3 responses * Move static strings to constants * Codestyle fixes * Codestyle fixes * Change non-existing key name * Change non-existing key name * Added RESP3 test coverage for JSON module * Added new assertion, fixed RESP3 JSON responses and versions * Added feature tests on timeseries module RESP3 responses * Updated version decorators * Added feature tests on bloom filter module RESP3 responses * Added feature tests on search module RESP3 responses * Mark tests as relay-incompatible * Added feature tests on cms, cuckoo filters RESP3 responses * Revert changes * Increased time intervals to avoid test failures * Added feature tests on tdigest, topk filters RESP3 responses * Updated test case responses * Codestyle fix
210 lines
5.5 KiB
PHP
210 lines
5.5 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;
|
|
use UnexpectedValueException;
|
|
|
|
/**
|
|
* @group commands
|
|
* @group realm-set
|
|
*/
|
|
class SINTERCARD_Test extends PredisCommandTestCase
|
|
{
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function getExpectedCommand(): string
|
|
{
|
|
return SINTERCARD::class;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function getExpectedId(): string
|
|
{
|
|
return 'SINTERCARD';
|
|
}
|
|
|
|
/**
|
|
* @group disconnected
|
|
* @dataProvider argumentsProvider
|
|
*/
|
|
public function testFilterArguments(array $actualArguments, array $expectedArguments): void
|
|
{
|
|
$command = $this->getCommand();
|
|
$command->setArguments($actualArguments);
|
|
|
|
$this->assertSame($expectedArguments, $command->getArguments());
|
|
}
|
|
|
|
/**
|
|
* @group disconnected
|
|
*/
|
|
public function testParseResponse(): void
|
|
{
|
|
$this->assertSame(1, $this->getCommand()->parseResponse(1));
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
* @dataProvider setsProvider
|
|
* @param array $firstSet
|
|
* @param array $secondSet
|
|
* @param array $keys
|
|
* @param int $limit
|
|
* @param int $expectedCardinality
|
|
* @return void
|
|
* @requiresRedisVersion >= 7.0.0
|
|
*/
|
|
public function testReturnsCorrectCardinalityOfGivenSetIntersection(
|
|
array $firstSet,
|
|
array $secondSet,
|
|
array $keys,
|
|
int $limit,
|
|
int $expectedCardinality
|
|
): void {
|
|
$redis = $this->getClient();
|
|
|
|
$redis->sadd(...$firstSet);
|
|
$redis->sadd(...$secondSet);
|
|
|
|
$this->assertSame($expectedCardinality, $redis->sintercard($keys, $limit));
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
* @return void
|
|
* @requiresRedisVersion >= 7.0.0
|
|
*/
|
|
public function testReturnsCorrectCardinalityOfGivenSetIntersectionResp3(): void
|
|
{
|
|
$redis = $this->getResp3Client();
|
|
|
|
$redis->sadd('key1', 'member1', 'member2', 'member3');
|
|
$redis->sadd('key2', 'member1', 'member2', 'member3');
|
|
|
|
$this->assertSame(3, $redis->sintercard(['key1', 'key2']));
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
* @dataProvider unexpectedValuesProvider
|
|
* @param array $arguments
|
|
* @param string $expectedExceptionMessage
|
|
* @return void
|
|
* @requiresRedisVersion >= 7.0.0
|
|
*/
|
|
public function testThrowsExceptionOnUnexpectedValuesGiven(
|
|
array $arguments,
|
|
string $expectedExceptionMessage
|
|
): void {
|
|
$redis = $this->getClient();
|
|
|
|
$this->expectException(UnexpectedValueException::class);
|
|
$this->expectExceptionMessage($expectedExceptionMessage);
|
|
|
|
$redis->sintercard(...$arguments);
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
* @return void
|
|
* @requiresRedisVersion >= 7.0.0
|
|
*/
|
|
public function testThrowsExceptionOnWrongType(): void
|
|
{
|
|
$this->expectException(ServerException::class);
|
|
$this->expectExceptionMessage('Operation against a key holding the wrong kind of value');
|
|
|
|
$redis = $this->getClient();
|
|
|
|
$redis->set('sintercard', 'a');
|
|
$redis->sintercard(['sintercard']);
|
|
}
|
|
|
|
public function argumentsProvider(): array
|
|
{
|
|
return [
|
|
'with required arguments' => [
|
|
[['key1', 'key2']],
|
|
[2, 'key1', 'key2'],
|
|
],
|
|
'with default arguments' => [
|
|
[['key1', 'key2'], 0],
|
|
[2, 'key1', 'key2', 'LIMIT', 0],
|
|
],
|
|
'with non-default LIMIT' => [
|
|
[['key1', 'key2'], 2],
|
|
[2, 'key1', 'key2', 'LIMIT', 2],
|
|
],
|
|
];
|
|
}
|
|
|
|
public function setsProvider(): array
|
|
{
|
|
return [
|
|
'with full intersection' => [
|
|
['key1', 'member1', 'member2', 'member3'],
|
|
['key2', 'member1', 'member2', 'member3'],
|
|
['key1', 'key2'],
|
|
0,
|
|
3,
|
|
],
|
|
'with partial intersection' => [
|
|
['key1', 'member1', 'member2', 'member3'],
|
|
['key2', 'member1', 'member4', 'member5'],
|
|
['key1', 'key2'],
|
|
0,
|
|
1,
|
|
],
|
|
'with no intersection' => [
|
|
['key1', 'member1', 'member2', 'member3'],
|
|
['key2', 'member4', 'member5', 'member6'],
|
|
['key1', 'key2'],
|
|
0,
|
|
0,
|
|
],
|
|
'with no intersection on non-existing key' => [
|
|
['key1', 'member1', 'member2', 'member3'],
|
|
['key2', 'member1', 'member2', 'member3'],
|
|
['key1', 'key3'],
|
|
0,
|
|
0,
|
|
],
|
|
'with non-default LIMIT' => [
|
|
['key1', 'member1', 'member2', 'member3'],
|
|
['key2', 'member1', 'member2', 'member3'],
|
|
['key1', 'key2'],
|
|
1,
|
|
1,
|
|
],
|
|
];
|
|
}
|
|
|
|
public function unexpectedValuesProvider(): array
|
|
{
|
|
return [
|
|
'with wrong keys argument' => [
|
|
['key1', 0],
|
|
'Wrong keys argument type or position offset',
|
|
],
|
|
'with wrong limit argument' => [
|
|
[['key1'], 'wrong'],
|
|
'Wrong limit argument type',
|
|
],
|
|
];
|
|
}
|
|
}
|