mirror of
https://github.com/predis/predis.git
synced 2026-08-24 20:49:41 +00:00
30e48f566e
* feat(commands): Add support for VectorSet commands * Codestyle fixes * Fixed test * Added logging for test purposes * Marked tests as relay incompatible * Missing incompatible tests * Updated CHANGELOG to reflect experimental nature of feature * Marked properties as nullable * Changed static variables to constants * Codestyle fixe * Revert changes * Update CHANGELOG.md --------- Co-authored-by: Till Krüss <tillkruss@users.noreply.github.com>
76 lines
2.3 KiB
PHP
76 lines
2.3 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of the Predis package.
|
|
*
|
|
* (c) 2009-2020 Daniele Alessandri
|
|
* (c) 2021-2025 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\Utils;
|
|
|
|
use Predis\Command\Redis\Utils\CommandUtility;
|
|
use PredisTestCase;
|
|
use UnexpectedValueException;
|
|
|
|
class CommandUtilityTest extends PredisTestCase
|
|
{
|
|
/**
|
|
* @dataProvider arrayProvider
|
|
* @param array $actual
|
|
* @param array $expected
|
|
* @param callable|null $callback
|
|
* @param bool $recursive
|
|
* @return void
|
|
*/
|
|
public function testArrayToDictionary(array $actual, array $expected, ?callable $callback, bool $recursive = true)
|
|
{
|
|
$this->assertSame($expected, CommandUtility::arrayToDictionary($actual, $callback, $recursive));
|
|
}
|
|
|
|
/**
|
|
* @return void
|
|
*/
|
|
public function testArrayToDictionaryThrowsExceptionOnOddNumberOfElements()
|
|
{
|
|
$this->expectException(UnexpectedValueException::class);
|
|
$this->expectExceptionMessage('Array must have an even number of arguments');
|
|
|
|
CommandUtility::arrayToDictionary(['key1', 'value1', 'key1']);
|
|
}
|
|
|
|
public function arrayProvider(): array
|
|
{
|
|
return [
|
|
'without nesting arrays' => [
|
|
['key1', 'value1', 'key2', 'value2', 'key3', 'value3'],
|
|
['key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3'],
|
|
null,
|
|
],
|
|
'with nesting arrays' => [
|
|
['key1', ['key2', ['key3', 'value3']]],
|
|
['key1' => ['key2' => ['key3' => 'value3']]],
|
|
null,
|
|
],
|
|
'with callback applied' => [
|
|
['key1', ['key2', ['key3', '0.1']]],
|
|
['key1' => ['key2' => ['key3' => 0.1]]],
|
|
function ($key, $value) {
|
|
return [$key, (float) $value];
|
|
},
|
|
],
|
|
'with non-recursive approach' => [
|
|
['key1', ['key2', ['key3', '0.1']]],
|
|
['key1' => ['key2', ['key3', '0.1']]],
|
|
function ($key, $value) {
|
|
return [$key, (float) $value];
|
|
},
|
|
false,
|
|
],
|
|
];
|
|
}
|
|
}
|