Browse Source

added annotation @runInSeparateProcess and removing annotations @expectedException

master
Vyacheslav Agafonov 13 years ago
parent
commit
ece71411bd
  1. 2
      redis/RedisManager.php
  2. 39
      tests/redis/RedisManagerTest.php

2
redis/RedisManager.php

@ -33,7 +33,7 @@ class RedisManager
if (!$config) { if (!$config) {
if (gettype(Config::get('Redis')) != 'object') { if (gettype(Config::get('Redis')) != 'object') {
throw new GeneralException('config non-object');
throw new GeneralException('Redis config no existence');
} }
$config = Config::get('Redis')->$name; $config = Config::get('Redis')->$name;
} }

39
tests/redis/RedisManagerTest.php

@ -13,21 +13,18 @@
require_once dirname(__FILE__) . '/../../Registry.php'; require_once dirname(__FILE__) . '/../../Registry.php';
require_once dirname(__FILE__) . '/../../Config.php'; require_once dirname(__FILE__) . '/../../Config.php';
require_once dirname(__FILE__) . '/../../redis/RedisManager.php'; require_once dirname(__FILE__) . '/../../redis/RedisManager.php';
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php'; require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
class RedisManagerTest extends PHPUnit_Framework_TestCase class RedisManagerTest extends PHPUnit_Framework_TestCase
{ {
private $connections; private $connections;
public function run(PHPUnit_Framework_TestResult $result = NULL) public function run(PHPUnit_Framework_TestResult $result = NULL)
{ {
$this->setPreserveGlobalState(false); $this->setPreserveGlobalState(false);
return parent::run($result); return parent::run($result);
} }
public function setUp() public function setUp()
{ {
$this->getMock('Redis'); $this->getMock('Redis');
@ -46,70 +43,52 @@ class RedisManagerTest extends PHPUnit_Framework_TestCase
} }
/** /**
* @expectedExceptionMessage Trying to get property of non-object
* @TODO: line 34: $config = Config::get('Redis')->$name; - check for Redis config existence. Agafonov: 'check added' * @TODO: line 34: $config = Config::get('Redis')->$name; - check for Redis config existence. Agafonov: 'check added'
*/ */
public function testConnectNoAnyConfig() public function testConnectNoAnyConfig()
{ {
//$this->setExpectedException('GeneralException');
$this->setExpectedException('GeneralException');
$this->setExpectedException('GeneralException', 'Redis config no existence');
RedisManager::connect(); RedisManager::connect();
} }
/**
* @expected Exception GeneralException
* @expected ExceptionMessage Connection parameters must be an array
*/
public function testConnectWrongPersistantConfig() public function testConnectWrongPersistantConfig()
{ {
$this->setExpectedException('GeneralException');
$this->setExpectedException('GeneralException', 'Connection parameters must be an array');
Config::set('Redis', array('new' => 'some')); Config::set('Redis', array('new' => 'some'));
RedisManager::connect('new'); RedisManager::connect('new');
} }
/**
* @expected Exception GeneralException
* @expected ExceptionMessage Connection parameters must be an array
*/
public function testConnectDefaultConfig() public function testConnectDefaultConfig()
{ {
$this->setExpectedException('GeneralException');
$this->setExpectedException('GeneralException', 'Connection parameters must be an array');
Config::set('Redis', array('default' => 'some')); Config::set('Redis', array('default' => 'some'));
RedisManager::connect(); RedisManager::connect();
} }
/**
* @expected Exception GeneralException
* @expected ExceptionMessage Failed to connect to Redis server at
*/
public function testConnectFailedConnection() public function testConnectFailedConnection()
{ {
$this->setExpectedException('GeneralException');
$this->setExpectedException('GeneralException', 'Failed to connect to Redis server at');
Config::set('Redis', array('new' => array('host' => 'error', 'port' => 2023, 'database' => 'some'))); Config::set('Redis', array('new' => array('host' => 'error', 'port' => 2023, 'database' => 'some')));
RedisManager::connect('new'); RedisManager::connect('new');
} }
/**
* @expected Exception GeneralException
* @expected ExceptionMessage Failed to select Redis database with index
*/
public function testConnectEstablishedConnectionNoDb() public function testConnectEstablishedConnectionNoDb()
{ {
$this->setExpectedException('GeneralException');
$this->setExpectedException('GeneralException', 'Failed to select Redis database with index');
Config::set('Redis', array('new' => array('host' => true, 'port' => 2023, 'database' => 'some'))); Config::set('Redis', array('new' => array('host' => true, 'port' => 2023, 'database' => 'some')));
RedisManager::connect('new'); RedisManager::connect('new');
} }
public function testConnectionGood() public function testConnectionGood()
{ {
// $this->setExpectedException('GeneralException');
Config::set('Redis', array('new' => array('host' => true, 'port' => 2023, 'database' => true))); Config::set('Redis', array('new' => array('host' => true, 'port' => 2023, 'database' => true)));
$redis = RedisManager::connect('new'); $redis = RedisManager::connect('new');
$this->assertInstanceOf('RedisMock', $redis); $this->assertInstanceOf('RedisMock', $redis);
} }
/**
* @runInSeparateProcess
*/
public function testConnectWithDebug() public function testConnectWithDebug()
{ {
if (!defined('DEBUG')) { if (!defined('DEBUG')) {

Loading…
Cancel
Save