123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- <?php
- namespace Predis\Commands;
- use \PHPUnit_Framework_TestCase as StandardTestCase;
- use Predis\Client;
- use Predis\Profiles\ServerProfile;
- use Predis\Profiles\IServerProfile;
- abstract class CommandTestCase extends StandardTestCase
- {
-
- protected abstract function getExpectedCommand();
-
- protected abstract function getExpectedId();
-
- protected function getCommand()
- {
- $command = $this->getExpectedCommand();
- return $command instanceof ICommand ? $command : new $command();
- }
-
- protected function getProfile()
- {
- return ServerProfile::get(REDIS_SERVER_VERSION);
- }
-
- protected function getClient($flushdb = true)
- {
- $profile = $this->getProfile();
- if (!$profile->supportsCommand($id = $this->getExpectedId())) {
- $this->markTestSkipped("The profile {$profile->getVersion()} does not support command {$id}");
- }
- $parameters = array(
- 'host' => REDIS_SERVER_HOST,
- 'port' => REDIS_SERVER_PORT,
- );
- $options = array(
- 'profile' => $profile
- );
- $client = new Client($parameters, $options);
- $client->connect();
- $client->select(REDIS_SERVER_DBNUM);
- if ($flushdb) {
- $client->flushdb();
- }
- return $client;
- }
-
- protected function isPrefixable()
- {
- return $this->getCommand() instanceof IPrefixable;
- }
-
- protected function getCommandWithArguments()
- {
- return $this->getCommandWithArgumentsArray(func_get_args());
- }
-
- protected function getCommandWithArgumentsArray(Array $arguments)
- {
- $command = $this->getCommand();
- $command->setArguments($arguments);
- return $command;
- }
-
- protected function sleep($seconds)
- {
- usleep($seconds * 1000000);
- }
-
- protected function assertSameValues(Array $expected, Array $actual)
- {
- $this->assertThat($expected, new \ArrayHasSameValuesConstraint($actual));
- }
-
- public function testCommandId()
- {
- $command = $this->getCommand();
- $this->assertInstanceOf('Predis\Commands\ICommand', $command);
- $this->assertEquals($this->getExpectedId(), $command->getId());
- }
-
- public function testRawArguments()
- {
- $expected = array('1st', '2nd', '3rd', '4th');
- $command = $this->getCommand();
- $command->setRawArguments($expected);
- $this->assertSame($expected, $command->getArguments());
- }
- }
|