Returns the default server profile.
public static getDefault ( ) : Predis\Profile\ProfileInterface | ||
리턴 | Predis\Profile\ProfileInterface |
/** * @group disconnected */ public function testConstructorStartsConsumer() { $cmdMonitor = Profile\Factory::getDefault()->createCommand('monitor'); $connection = $this->getMock('Predis\\Connection\\NodeConnectionInterface'); $client = $this->getMock('Predis\\Client', array('createCommand', 'executeCommand'), array($connection)); $client->expects($this->once())->method('createCommand')->with('MONITOR', array())->will($this->returnValue($cmdMonitor)); $client->expects($this->once())->method('executeCommand')->with($cmdMonitor); new MonitorConsumer($client); }
/** * @group disconnected */ public function testGetDefault() { $profile1 = Factory::get(self::DEFAULT_PROFILE_VERSION); $profile2 = Factory::get('default'); $profile3 = Factory::getDefault(); $this->assertInstanceOf('Predis\\Profile\\ProfileInterface', $profile1); $this->assertInstanceOf('Predis\\Profile\\ProfileInterface', $profile2); $this->assertInstanceOf('Predis\\Profile\\ProfileInterface', $profile3); $this->assertEquals($profile1->getVersion(), $profile2->getVersion()); $this->assertEquals($profile2->getVersion(), $profile3->getVersion()); }
public function testClient() { $app = $this->register(); list($parameters, $options) = $this->getParametersAndOptions($app['predis']); $this->assertEquals('tcp', $parameters->scheme); $this->assertEquals('127.0.0.1', $parameters->host); $this->assertEquals(6379, $parameters->port); $this->assertEquals(ProfileFactory::getDefault(), $options->profile); $this->assertNull($options->prefix); }
/** * {@inheritdoc} */ public function getDefault(OptionsInterface $options) { $profile = Predis_Factory::getDefault(); $this->setProcessors($options, $profile); return $profile; }
/** * @group disconnected */ public function testExecuteCommandDoesNotSendCommandsWithoutExecute() { $profile = Profile\Factory::getDefault(); $connection = $this->getMock('Predis\\Connection\\NodeConnectionInterface'); $connection->expects($this->never())->method('writeRequest'); $connection->expects($this->never())->method('readResponse'); $pipeline = new Pipeline(new Client($connection)); $pipeline->executeCommand($profile->createCommand('echo', array('one'))); $pipeline->executeCommand($profile->createCommand('echo', array('two'))); $pipeline->executeCommand($profile->createCommand('echo', array('three'))); }
public function testClientsAliased() { $params = $this->getSomeParameters(); $app = $this->register(array( 'predis.clients' => array( '1st' => "{$params['scheme']}://{$params['host']}:{$params['port']}", '2nd' => $params, '3rd' => array('parameters' => $params), '4th' => array('parameters' => $params, 'options' => array('profile' => 'dev')), ) )); $this->checkParameters($app['predis'], '1st', $params); $this->checkParameters($app['predis'], '2nd', $params); $this->checkParameters($app['predis'], '3rd', $params); $this->checkParameters($app['predis'], '4th', $params); list(, $options) = $this->getParametersAndOptions($app['predis']['1st']); $this->assertEquals(ProfileFactory::getDefault(), $options->profile); list(, $options) = $this->getParametersAndOptions($app['predis']['2nd']); $this->assertEquals(ProfileFactory::getDefault(), $options->profile); list(, $options) = $this->getParametersAndOptions($app['predis']['3rd']); $this->assertEquals(ProfileFactory::getDefault(), $options->profile); list(, $options) = $this->getParametersAndOptions($app['predis']['4th']); $this->assertEquals(ProfileFactory::getDevelopment(), $options->profile); }
/** * @group disconnected */ public function testCallingRedisCommandExecutesInstanceOfCommand() { $ping = Profile\Factory::getDefault()->createCommand('ping', array()); $connection = $this->getMock('Predis\\Connection\\ConnectionInterface'); $connection->expects($this->once())->method('executeCommand')->with($this->isInstanceOf('Predis\\Command\\ConnectionPing'))->will($this->returnValue('PONG')); $profile = $this->getMock('Predis\\Profile\\ProfileInterface'); $profile->expects($this->once())->method('createCommand')->with('ping', array())->will($this->returnValue($ping)); $options = array('profile' => $profile); $client = $this->getMock('Predis\\Client', null, array($connection, $options)); $this->assertEquals('PONG', $client->ping()); }
/** * @group disconnected */ public function testCreatesNewCommandUsingSpecifiedProfile() { $ping = ProfileFactory::getDefault()->createCommand('ping', []); $profile = $this->getMock('Predis\\Profile\\ProfileInterface'); $profile->expects($this->once())->method('createCommand')->with('ping', [])->will($this->returnValue($ping)); $client = new Client(null, ['profile' => $profile]); $this->assertSame($ping, $client->createCommand('ping', [])); }
/** * @group disconnected */ public function testExecuteCommandOnEachNode() { $ping = Profile\Factory::getDefault()->createCommand('ping', array()); $connection1 = $this->getMock('Predis\\Connection\\NodeConnectionInterface'); $connection1->expects($this->once())->method('executeCommand')->with($ping)->will($this->returnValue(true)); $connection2 = $this->getMock('Predis\\Connection\\NodeConnectionInterface'); $connection2->expects($this->once())->method('executeCommand')->with($ping)->will($this->returnValue(false)); $cluster = new PredisCluster(); $cluster->add($connection1); $cluster->add($connection2); $this->assertSame(array(true, false), $cluster->executeCommandOnNodes($ping)); }
/** * @group disconnected * @expectedException \Predis\NotSupportedException * @expectedExceptionMessage Cannot use 'PING' with redis-cluster. */ public function testThrowsExceptionOnNonSupportedCommand() { $ping = Profile\Factory::getDefault()->createCommand('ping'); $cluster = new RedisCluster(new Connection\Factory()); $cluster->add($this->getMockConnection('tcp://127.0.0.1:6379')); $cluster->getConnection($ping); }
/** * @group disconnected */ public function testDoesNotApplyPrefixOnProfileValue() { $option = new ProfileOption(); $options = $this->getMock('Predis\\Configuration\\OptionsInterface'); $value = Profile\Factory::getDefault(); $options->expects($this->never())->method('__isset'); $options->expects($this->never())->method('__get'); $profile = $option->filter($options, $value); $this->assertInstanceOf('Predis\\Profile\\ProfileInterface', $profile); $this->assertInstanceOf(get_class(Profile\Factory::getDefault()), $profile); $this->assertNull($profile->getProcessor()); }
/** * @group disconnected */ public function testIterationRewindable() { $client = $this->getMock('Predis\\Client', array('getProfile', 'lrange')); $client->expects($this->any())->method('getProfile')->will($this->returnValue(Profile\Factory::getDefault())); $client->expects($this->exactly(2))->method('lrange')->with('key:list', 0, 9)->will($this->returnValue(array('item:1', 'item:2'))); $iterator = new ListKey($client, 'key:list'); $iterator->rewind(); $this->assertTrue($iterator->valid()); $this->assertSame('item:1', $iterator->current()); $this->assertSame(0, $iterator->key()); $iterator->rewind(); $this->assertTrue($iterator->valid()); $this->assertSame('item:1', $iterator->current()); $this->assertSame(0, $iterator->key()); $iterator->next(); $this->assertTrue($iterator->valid()); $this->assertSame(1, $iterator->key()); $this->assertSame('item:2', $iterator->current()); $iterator->next(); $this->assertFalse($iterator->valid()); }