replacement @expectedException to setExpectedException
This commit is contained in:
@ -17,7 +17,6 @@ require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
|
|||||||
|
|
||||||
class DbDriverTest extends PHPUnit_Framework_TestCase
|
class DbDriverTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
private $driver;
|
private $driver;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
@ -29,15 +28,18 @@ class DbDriverTest extends PHPUnit_Framework_TestCase
|
|||||||
public function testConstruct()
|
public function testConstruct()
|
||||||
{
|
{
|
||||||
$conf = array('hostname' => 'localhost', 'database' => 'db', 'username' => 'test', 'password' => '1234');
|
$conf = array('hostname' => 'localhost', 'database' => 'db', 'username' => 'test', 'password' => '1234');
|
||||||
$this->driver = $this->getMockForAbstractClass('DbDriver', array($conf));
|
try {
|
||||||
|
$this->driver = $this->getMockForAbstractClass('DbDriver', array($conf));
|
||||||
|
}
|
||||||
|
catch (GeneralException $expected) {
|
||||||
|
$this->fail($expected->getMessage());
|
||||||
|
}
|
||||||
|
$this->assertInstanceOf('DbDriver', $this->driver);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException GeneralException
|
|
||||||
* @expectedExceptionMessage Configuration must have a "username".
|
|
||||||
*/
|
|
||||||
public function testConstructWrongConfig()
|
public function testConstructWrongConfig()
|
||||||
{
|
{
|
||||||
|
$this->setExpectedException('GeneralException', 'Configuration must have a "username"');
|
||||||
$conf = array('hostname' => 'localhost', 'database' => 'db');
|
$conf = array('hostname' => 'localhost', 'database' => 'db');
|
||||||
$this->getMockForAbstractClass('DbDriver', array($conf));
|
$this->getMockForAbstractClass('DbDriver', array($conf));
|
||||||
}
|
}
|
||||||
@ -130,7 +132,7 @@ class DbDriverTest extends PHPUnit_Framework_TestCase
|
|||||||
public function testDeleteWithWHEREDbExpr()
|
public function testDeleteWithWHEREDbExpr()
|
||||||
{
|
{
|
||||||
$this->setDriverPrepareFunction();
|
$this->setDriverPrepareFunction();
|
||||||
|
|
||||||
$sql = $this->driver->delete('users', new DbExpr('name=tony'));
|
$sql = $this->driver->delete('users', new DbExpr('name=tony'));
|
||||||
$this->assertEquals('DELETE FROM `users` WHERE name=tony', $sql);
|
$this->assertEquals('DELETE FROM `users` WHERE name=tony', $sql);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ require_once dirname(__FILE__) . '/../../model/DbExpr.php';
|
|||||||
|
|
||||||
class DbExprTest extends PHPUnit_Framework_TestCase
|
class DbExprTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function testExpr()
|
public function testExpr()
|
||||||
{
|
{
|
||||||
$expr = new DbExpr('THIS IS SQL EXPRESSION');
|
$expr = new DbExpr('THIS IS SQL EXPRESSION');
|
||||||
|
@ -57,22 +57,19 @@ class DbStatementTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException GeneralException
|
|
||||||
* @expectedExceptionMessage Placeholder must be an array or string
|
|
||||||
* @TODO: change Exception Message 'Placeholder must be an array or string' - no arrays available
|
* @TODO: change Exception Message 'Placeholder must be an array or string' - no arrays available
|
||||||
*/
|
*/
|
||||||
public function testBindParamExceptionParam()
|
public function testBindParamExceptionParam()
|
||||||
{
|
{
|
||||||
$val = 1;
|
$val = 1;
|
||||||
|
$this->setExpectedException('GeneralException', 'Placeholder must be an array or string');
|
||||||
$this->stmt->bindParam(array(), $val);
|
$this->stmt->bindParam(array(), $val);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException GeneralException
|
|
||||||
* @expectedExceptionMessage Objects excepts DbExpr not allowed.
|
|
||||||
*/
|
|
||||||
public function testBindParamExceptionWrongObject()
|
public function testBindParamExceptionWrongObject()
|
||||||
{
|
{
|
||||||
|
$this->setExpectedException('GeneralException', 'Objects excepts DbExpr not allowed.');
|
||||||
$val = $this->getMock('NotDbExpr');
|
$val = $this->getMock('NotDbExpr');
|
||||||
$this->stmt->bindParam('paa', $val);
|
$this->stmt->bindParam('paa', $val);
|
||||||
}
|
}
|
||||||
|
@ -19,21 +19,14 @@ require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
|
|||||||
|
|
||||||
class DbTest extends PHPUnit_Framework_TestCase
|
class DbTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedExceptionMessage Trying to get property of non-object
|
|
||||||
*/
|
|
||||||
public function testConnectNoParams()
|
public function testConnectNoParams()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('InitializationException');
|
$this->setExpectedException('InitializationException', 'Trying to get property of non-object');
|
||||||
Db::connect();
|
Db::connect();
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* @expectedExceptionMessage Connection parameters must be an array
|
|
||||||
*/
|
|
||||||
public function testConnectConfigNotArray()
|
public function testConnectConfigNotArray()
|
||||||
{
|
{
|
||||||
$this->setExpectedException('InitializationException');
|
$this->setExpectedException('InitializationException', 'Connection parameters must be an array');
|
||||||
Db::connect('name', 'config');
|
Db::connect('name', 'config');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,13 +46,11 @@ class DbTest extends PHPUnit_Framework_TestCase
|
|||||||
$driver = Db::connect('mysql', $conf);
|
$driver = Db::connect('mysql', $conf);
|
||||||
$this->assertInstanceOf('DbDriver', $driver);
|
$this->assertInstanceOf('DbDriver', $driver);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* @expectedExceptionMessage Database driver must extends DbDriver
|
|
||||||
*/
|
|
||||||
public function testConnectWithWrongDriver()
|
public function testConnectWithWrongDriver()
|
||||||
{
|
{
|
||||||
|
$this->setExpectedException('InitializationException', 'Database driver must extends DbDriver');
|
||||||
$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'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,15 +111,8 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||||||
$model = new ReflectionClass('Model');
|
$model = new ReflectionClass('Model');
|
||||||
$method = $model->getMethod('fetch');
|
$method = $model->getMethod('fetch');
|
||||||
$method->setAccessible(true);
|
$method->setAccessible(true);
|
||||||
|
|
||||||
$key = $this->getCacheKeyMockGetSet();
|
$key = $this->getCacheKeyMockGetSet();
|
||||||
|
$this->assertTrue(true, $method->invoke($this->model, 'SELECT', array(), $key));
|
||||||
|
|
||||||
//$debug = print_r($this->model, true);
|
|
||||||
//throw new Exception($debug);
|
|
||||||
|
|
||||||
|
|
||||||
$this->assertEquals('field', $method->invoke($this->model, 'SELECT', array(), $key));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFetchField()
|
public function testFetchField()
|
||||||
@ -139,7 +132,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
|
|||||||
$method->setAccessible(true);
|
$method->setAccessible(true);
|
||||||
|
|
||||||
$key = $this->getCacheKeyMockGetSet();
|
$key = $this->getCacheKeyMockGetSet();
|
||||||
$this->assertEquals('field', $method->invoke($this->model, 'SELECT', array(), $key));
|
$this->assertTrue(true, $method->invoke($this->model, 'SELECT', array(), $key));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGetCache()
|
public function testGetCache()
|
||||||
|
@ -80,16 +80,13 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
|
|||||||
$this->assertTrue($driver->isConnected());
|
$this->assertTrue($driver->isConnected());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException GeneralException
|
|
||||||
* @expectedExceptionMessage Unknown database
|
|
||||||
*/
|
|
||||||
public function testGetConnectionWrongConfig()
|
public function testGetConnectionWrongConfig()
|
||||||
{
|
{
|
||||||
if (!defined('DEBUG')) {
|
if (!defined('DEBUG')) {
|
||||||
define('DEBUG', false);
|
define('DEBUG', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->setExpectedException('GeneralException', 'Unknown database \'nodb\'');
|
||||||
$this->conf['database'] = 'nodb';
|
$this->conf['database'] = 'nodb';
|
||||||
$driver = new MySQLiDriver($this->conf);
|
$driver = new MySQLiDriver($this->conf);
|
||||||
$this->assertNull('mysqli', $driver->getConnection());
|
$this->assertNull('mysqli', $driver->getConnection());
|
||||||
|
@ -64,14 +64,13 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @expectedException GeneralException
|
|
||||||
* @expectedExceptionMessage ERROR
|
|
||||||
*/
|
*/
|
||||||
public function testDriverExecuteNoResult()
|
public function testDriverExecuteNoResult()
|
||||||
{
|
{
|
||||||
if (!defined('DEBUG')) {
|
if (!defined('DEBUG')) {
|
||||||
define('DEBUG', false);
|
define('DEBUG', false);
|
||||||
}
|
}
|
||||||
|
$this->setExpectedException('GeneralException', 'ERROR');
|
||||||
$this->setDriverGetConnectionWrongResultMethod();
|
$this->setDriverGetConnectionWrongResultMethod();
|
||||||
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
|
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
|
||||||
}
|
}
|
||||||
@ -158,19 +157,16 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testNumRows()
|
public function testNumRows()
|
||||||
{
|
{
|
||||||
$this->markTestSkipped();
|
$this->markTestSkipped('Unable to execute a method or access a property of an incomplete object.');
|
||||||
if (!defined('DEBUG')) {
|
if (!defined('DEBUG')) {
|
||||||
define('DEBUG', false);
|
define('DEBUG', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setDriverGetConnectionMethod();
|
$this->setDriverGetConnectionMethod();
|
||||||
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
|
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
|
||||||
$this->assertNull($this->stmt->numRows());
|
$this->assertNull($this->stmt->numRows());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException GeneralException
|
|
||||||
* @expectedExceptionMessage Invalid fetch mode
|
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
*/
|
*/
|
||||||
public function testFetchInvalidMode()
|
public function testFetchInvalidMode()
|
||||||
@ -178,6 +174,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
|
|||||||
if (!defined('DEBUG')) {
|
if (!defined('DEBUG')) {
|
||||||
define('DEBUG', false);
|
define('DEBUG', false);
|
||||||
}
|
}
|
||||||
|
$this->setExpectedException('GeneralException');
|
||||||
$this->setDriverGetConnectionMethod();
|
$this->setDriverGetConnectionMethod();
|
||||||
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
|
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
|
||||||
$this->stmt->fetch(324);
|
$this->stmt->fetch(324);
|
||||||
|
Reference in New Issue
Block a user