added setExpectedException and check type Config

This commit is contained in:
Vyacheslav Agafonov
2011-11-30 13:26:36 +04:00
parent b7e71c20b7
commit be83874392
4 changed files with 30 additions and 7 deletions

View File

@ -15,24 +15,25 @@ require_once dirname(__FILE__) . '/../../Config.php';
require_once dirname(__FILE__) . '/../../model/DbDriver.php';
require_once dirname(__FILE__) . '/../../model/Db.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
class DbTest extends PHPUnit_Framework_TestCase
{
/**
* @expectedException GeneralException
* @expectedExceptionMessage Trying to get property of non-object
*/
public function testConnectNoParams()
{
Db::connect();
$this->setExpectedException('InitializationException');
Db::connect();
}
/**
* @expectedException GeneralException
* @expectedExceptionMessage Connection parameters must be an array
*/
public function testConnectConfigNotArray()
{
$this->setExpectedException('InitializationException');
Db::connect('name', 'config');
}
@ -41,7 +42,8 @@ class DbTest extends PHPUnit_Framework_TestCase
$conf = array('hostname' => 'localhost', 'driver' => 'MySQLiDriverGlobalConfMock', 'database' => 'db', 'username' => 'test', 'password' => '1234');
$this->getMockForAbstractClass('DbDriver', array(), 'MySQLiDriverGlobalConfMock', false);
Config::set('Db', array('global' =>$conf));
Db::connect('global');
$driver = Db::connect('global');
$this->assertInstanceOf('DbDriver', $driver);
}
public function testConnectWithConfigParam()
@ -52,12 +54,12 @@ class DbTest extends PHPUnit_Framework_TestCase
$this->assertInstanceOf('DbDriver', $driver);
}
/**
* @expectedException GeneralException
* @expectedExceptionMessage Database driver must extends DbDriver
*/
public function testConnectWithWrongDriver()
{
$this->getMock('NotDbDriver', array(), array(), 'NoDbDriverMock');
$this->setExpectedException('InitializationException');
$driver = Db::connect('nodb', array('hostname' => 'localhost', 'driver' => 'NoDbDriverMock'));
}