1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
<?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\Profile;
use PredisTestCase;
/**
*
*/
class FactoryTest extends PredisTestCase
{
const DEFAULT_PROFILE_VERSION = '3.2';
const DEVELOPMENT_PROFILE_VERSION = '3.2';
/**
* @group disconnected
*/
public function testGetVersion()
{
$profile = Factory::get('2.0');
$this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile);
$this->assertEquals('2.0', $profile->getVersion());
}
/**
* @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());
}
/**
* @group disconnected
*/
public function testGetDevelopment()
{
$profile1 = Factory::get('dev');
$profile2 = Factory::getDevelopment();
$this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile1);
$this->assertInstanceOf('Predis\Profile\ProfileInterface', $profile2);
$this->assertEquals(self::DEVELOPMENT_PROFILE_VERSION, $profile2->getVersion());
}
/**
* @group disconnected
*/
public function testGetUndefinedProfile()
{
$this->expectException('\Predis\ClientException');
$this->expectExceptionMessage('Unknown server profile: \'1.0\'.');
Factory::get('1.0');
}
/**
* @group disconnected
*/
public function testDefineProfile()
{
$profileClass = get_class($this->createMock('Predis\Profile\ProfileInterface'));
Factory::define('mock', $profileClass);
$this->assertInstanceOf($profileClass, Factory::get('mock'));
}
/**
* @group disconnected
*/
public function testDefineInvalidProfile()
{
$this->expectException('\InvalidArgumentException');
$this->expectExceptionMessage('The class \'stdClass\' is not a valid profile class.');
Factory::define('bogus', 'stdClass');
}
}
|