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