-
-
Notifications
You must be signed in to change notification settings - Fork 988
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for FUNCTION DUMP, FUNCTION FLUSH, FUNCTION RESTORE com…
…mands (#1332)
- Loading branch information
1 parent
90da582
commit dd64569
Showing
8 changed files
with
368 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Command/Strategy/ContainerCommands/Functions/DumpStrategy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?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\Strategy\ContainerCommands\Functions; | ||
|
||
use Predis\Command\Strategy\SubcommandStrategyInterface; | ||
|
||
class DumpStrategy implements SubcommandStrategyInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function processArguments(array $arguments): array | ||
{ | ||
return $arguments; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Command/Strategy/ContainerCommands/Functions/FlushStrategy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?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\Strategy\ContainerCommands\Functions; | ||
|
||
use Predis\Command\Strategy\SubcommandStrategyInterface; | ||
|
||
class FlushStrategy implements SubcommandStrategyInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function processArguments(array $arguments): array | ||
{ | ||
$processedArguments = [$arguments[0]]; | ||
|
||
if (array_key_exists(1, $arguments) && null !== $arguments[1]) { | ||
$processedArguments[] = strtoupper($arguments[1]); | ||
} | ||
|
||
return $processedArguments; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Command/Strategy/ContainerCommands/Functions/RestoreStrategy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?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\Strategy\ContainerCommands\Functions; | ||
|
||
use Predis\Command\Strategy\SubcommandStrategyInterface; | ||
|
||
class RestoreStrategy implements SubcommandStrategyInterface | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function processArguments(array $arguments): array | ||
{ | ||
$processedArguments = [$arguments[0], $arguments[1]]; | ||
|
||
if (array_key_exists(2, $arguments) && null !== $arguments[2]) { | ||
$processedArguments[] = strtoupper($arguments[2]); | ||
} | ||
|
||
return $processedArguments; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
tests/Predis/Command/Strategy/ContainerCommands/Functions/DumpStrategyTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?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\Strategy\ContainerCommands\Functions; | ||
|
||
use PredisTestCase; | ||
|
||
class DumpStrategyTest extends PredisTestCase | ||
{ | ||
/** | ||
* @var DumpStrategy | ||
*/ | ||
private $strategy; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->strategy = new DumpStrategy(); | ||
} | ||
|
||
/** | ||
* @group disconnected | ||
* @return void | ||
*/ | ||
public function testProcessArguments(): void | ||
{ | ||
$this->assertSame(['arg1', 'arg2'], $this->strategy->processArguments(['arg1', 'arg2'])); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
tests/Predis/Command/Strategy/ContainerCommands/Functions/FlushStrategyTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?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\Strategy\ContainerCommands\Functions; | ||
|
||
use PredisTestCase; | ||
|
||
class FlushStrategyTest extends PredisTestCase | ||
{ | ||
/** | ||
* @var FlushStrategy | ||
*/ | ||
private $strategy; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->strategy = new FlushStrategy(); | ||
} | ||
|
||
/** | ||
* @dataProvider argumentsProvider | ||
* @group disconnected | ||
* @param array $actualArguments | ||
* @param array $expectedResponse | ||
* @return void | ||
*/ | ||
public function testProcessArguments(array $actualArguments, array $expectedResponse): void | ||
{ | ||
$this->assertSame($expectedResponse, $this->strategy->processArguments($actualArguments)); | ||
} | ||
|
||
public function argumentsProvider(): array | ||
{ | ||
return [ | ||
'with default arguments' => [ | ||
['FLUSH', null], | ||
['FLUSH'], | ||
], | ||
'with mode argument' => [ | ||
['FLUSH', 'sync'], | ||
['FLUSH', 'SYNC'], | ||
], | ||
]; | ||
} | ||
} |
Oops, something went wrong.