Files
predis/tests/Predis/Option/ClientProfileTest.php
T
Daniele Alessandri dc14c29676 Rename certain namespaces, interfaces and classes.
Now we follow a Symfony2-like naming convention for namespaces, interfaces
and classes sticking with one clear rule.

- Renamed namespaces:

  - Predis\Network
  - Predis\Profiles
  - Predis\Iterators
  - Predis\Options
  - Predis\Commands
  - Predis\Commands\Processors

- Renamed interfaces:

  - Predis\IReplyObject
  - Predis\IRedisServerError
  - Predis\IConnectionFactory
  - Predis\IConnectionParameters
  - Predis\Options\IOption
  - Predis\Options\IClientOptions
  - Predis\Profile\IServerProfile
  - Predis\Pipeline\IPipelineExecutor
  - Predis\Distribution\INodeKeyGenerator
  - Predis\Distribution\IDistributionStrategy
  - Predis\Protocol\IProtocolProcessor
  - Predis\Protocol\IResponseReader
  - Predis\Protocol\IResponseHandler
  - Predis\Protocol\ICommandSerializer
  - Predis\Protocol\IComposableProtocolProcessor
  - Predis\Network\IConnection
  - Predis\Network\IConnectionSingle
  - Predis\Network\IConnectionComposable
  - Predis\Network\IConnectionCluster
  - Predis\Network\IConnectionReplication
  - Predis\Commands\ICommand
  - Predis\Commands\IPrefixable
  - Predis\Command\Processor\ICommandProcessor
  - Predis\Command\Processor\ICommandProcessorChain
  - Predis\Command\Processor\IProcessingSupport

- Renamed Classes:

  - Predis\Commands\Command
  - Predis\Network\ConnectionBase

- Classes moved to different namespaces:

  - Predis\MonitorContext

Meh
2012-01-31 18:19:18 +01:00

210 lines
7.0 KiB
PHP

<?php
/*
* This file is part of the Predis package.
*
* (c) Daniele Alessandri <suppakilla@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Predis\Option;
use \PHPUnit_Framework_TestCase as StandardTestCase;
use Predis\Profile\ServerProfile;
use Predis\Command\Processor\KeyPrefixProcessor;
/**
*
*/
class ClientProfileTest extends StandardTestCase
{
/**
* @group disconnected
*/
public function testValidationReturnsServerProfileWithStringValue()
{
$options = $this->getMock('Predis\Option\ClientOptionsInterface');
$option = new ClientProfile();
$profile = $option->filter($options, '2.0');
$this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile);
$this->assertEquals('2.0', $profile->getVersion());
$this->assertNull($profile->getProcessor());
}
/**
* @group disconnected
*/
public function testValidationAcceptsProfileInstancesAsValue()
{
$value = ServerProfile::get('2.0');
$options = $this->getMock('Predis\Option\ClientOptionsInterface');
$option = new ClientProfile();
$profile = $option->filter($options, $value);
$this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile);
$this->assertEquals('2.0', $profile->getVersion());
$this->assertNull($profile->getProcessor());
}
/**
* @group disconnected
*/
public function testValidationAcceptsCallableObjectAsInitializers()
{
$value = $this->getMock('Predis\Profile\ServerProfileInterface');
$initializer = $this->getMock('stdClass', array('__invoke'));
$initializer->expects($this->once())
->method('__invoke')
->with($this->isInstanceOf('Predis\Option\ClientOptionsInterface'))
->will($this->returnValue($value));
$options = $this->getMock('Predis\Option\ClientOptionsInterface');
$option = new ClientProfile();
$profile = $option->filter($options, $initializer);
$this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile);
$this->assertSame($value, $profile);
}
/**
* @group disconnected
*/
public function testValidationThrowsExceptionOnWrongInvalidArguments()
{
$this->setExpectedException('InvalidArgumentException');
$options = $this->getMock('Predis\Option\ClientOptionsInterface');
$option = new ClientProfile();
$option->filter($options, new \stdClass());
}
/**
* @group disconnected
*/
public function testDefaultReturnsDefaultServerProfile()
{
$options = $this->getMock('Predis\Option\ClientOptionsInterface');
$option = new ClientProfile();
$profile = $option->getDefault($options);
$this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile);
$this->assertInstanceOf(get_class(ServerProfile::getDefault()), $profile);
$this->assertNull($profile->getProcessor());
}
/**
* @group disconnected
*/
public function testInvokeReturnsSpecifiedServerProfileOrDefault()
{
$options = $this->getMock('Predis\Option\ClientOptionsInterface');
$option = new ClientProfile();
$profile = $option($options, '2.0');
$this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile);
$this->assertEquals('2.0', $profile->getVersion());
$this->assertNull($profile->getProcessor());
$profile = $option($options, null);
$this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile);
$this->assertInstanceOf(get_class(ServerProfile::getDefault()), $profile);
$this->assertNull($profile->getProcessor());
}
/**
* @group disconnected
* @todo Can't we when trap __isset when mocking an interface? Doesn't seem to work here.
*/
public function testFilterSetsPrefixProcessorFromClientOptions()
{
$options = $this->getMock('Predis\Option\ClientOptions', array('__isset', '__get'));
$options->expects($this->once())
->method('__isset')
->with('prefix')
->will($this->returnValue(true));
$options->expects($this->once())
->method('__get')
->with('prefix')
->will($this->returnValue(new KeyPrefixProcessor('prefix:')));
$option = new ClientProfile();
$profile = $option->filter($options, '2.0');
$this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile);
$this->assertEquals('2.0', $profile->getVersion());
$this->assertInstanceOf('Predis\Command\Processor\KeyPrefixProcessor', $profile->getProcessor());
$this->assertEquals('prefix:', $profile->getProcessor()->getPrefix());
}
/**
* @group disconnected
* @todo Can't we when trap __isset when mocking an interface? Doesn't seem to work here.
*/
public function testDefaultSetsPrefixProcessorFromClientOptions()
{
$options = $this->getMock('Predis\Option\ClientOptions', array('__isset', '__get'));
$options->expects($this->once())
->method('__isset')
->with('prefix')
->will($this->returnValue(true));
$options->expects($this->once())
->method('__get')
->with('prefix')
->will($this->returnValue(new KeyPrefixProcessor('prefix:')));
$option = new ClientProfile();
$profile = $option->getDefault($options);
$this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile);
$this->assertInstanceOf(get_class(ServerProfile::getDefault()), $profile);
$this->assertInstanceOf('Predis\Command\Processor\KeyPrefixProcessor', $profile->getProcessor());
$this->assertEquals('prefix:', $profile->getProcessor()->getPrefix());
}
/**
* @group disconnected
*/
public function testValidationDoesNotSetPrefixProcessorWhenValueIsProfileInstance()
{
$options = $this->getMock('Predis\Option\ClientOptions', array('__isset', '__get'));
$options->expects($this->never())->method('__isset');
$options->expects($this->never())->method('__get');
$option = new ClientProfile();
$profile = $option->filter($options, ServerProfile::getDefault());
$this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $profile);
$this->assertNull($profile->getProcessor());
}
/**
* @group disconnected
* @expectedException InvalidArgumentException
* @expectedExceptionMessage Invalid value for the profile option
*/
public function testValidationThrowsExceptionOnInvalidObjectReturnedByCallback()
{
$value = function($options) { return new \stdClass(); };
$options = $this->getMock('Predis\Option\ClientOptionsInterface');
$option = new ClientProfile();
$option->filter($options, $value);
}
}