Browse Source

replacement @expectedException to setExpectedException

master
Vyacheslav Agafonov 13 years ago
parent
commit
66857702b6
  1. 16
      tests/model/DbDriverTest.php
  2. 1
      tests/model/DbExprTest.php
  3. 9
      tests/model/DbStatementTest.php
  4. 17
      tests/model/DbTest.php
  5. 11
      tests/model/ModelTest.php
  6. 5
      tests/model/MySQLiDriverTest.php
  7. 9
      tests/model/MySQLiStatementTest.php

16
tests/model/DbDriverTest.php

@ -17,7 +17,6 @@ require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
class DbDriverTest extends PHPUnit_Framework_TestCase
{
private $driver;
public function setUp()
@ -29,15 +28,18 @@ class DbDriverTest extends PHPUnit_Framework_TestCase
public function testConstruct()
{
$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()
{
$this->setExpectedException('GeneralException', 'Configuration must have a "username"');
$conf = array('hostname' => 'localhost', 'database' => 'db');
$this->getMockForAbstractClass('DbDriver', array($conf));
}
@ -130,7 +132,7 @@ class DbDriverTest extends PHPUnit_Framework_TestCase
public function testDeleteWithWHEREDbExpr()
{
$this->setDriverPrepareFunction();
$sql = $this->driver->delete('users', new DbExpr('name=tony'));
$this->assertEquals('DELETE FROM `users` WHERE name=tony', $sql);
}

1
tests/model/DbExprTest.php

@ -14,7 +14,6 @@ require_once dirname(__FILE__) . '/../../model/DbExpr.php';
class DbExprTest extends PHPUnit_Framework_TestCase
{
public function testExpr()
{
$expr = new DbExpr('THIS IS SQL EXPRESSION');

9
tests/model/DbStatementTest.php

@ -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
*/
public function testBindParamExceptionParam()
{
$val = 1;
$this->setExpectedException('GeneralException', 'Placeholder must be an array or string');
$this->stmt->bindParam(array(), $val);
}
/**
* @expectedException GeneralException
* @expectedExceptionMessage Objects excepts DbExpr not allowed.
*/
public function testBindParamExceptionWrongObject()
{
$this->setExpectedException('GeneralException', 'Objects excepts DbExpr not allowed.');
$val = $this->getMock('NotDbExpr');
$this->stmt->bindParam('paa', $val);
}

17
tests/model/DbTest.php

@ -19,21 +19,14 @@ require_once dirname(__FILE__) . '/../../exception/InitializationException.php';
class DbTest extends PHPUnit_Framework_TestCase
{
/**
* @expectedExceptionMessage Trying to get property of non-object
*/
public function testConnectNoParams()
{
$this->setExpectedException('InitializationException');
$this->setExpectedException('InitializationException', 'Trying to get property of non-object');
Db::connect();
}
/**
* @expectedExceptionMessage Connection parameters must be an array
*/
public function testConnectConfigNotArray()
{
$this->setExpectedException('InitializationException');
$this->setExpectedException('InitializationException', 'Connection parameters must be an array');
Db::connect('name', 'config');
}
@ -53,13 +46,11 @@ class DbTest extends PHPUnit_Framework_TestCase
$driver = Db::connect('mysql', $conf);
$this->assertInstanceOf('DbDriver', $driver);
}
/**
* @expectedExceptionMessage Database driver must extends DbDriver
*/
public function testConnectWithWrongDriver()
{
$this->setExpectedException('InitializationException', 'Database driver must extends DbDriver');
$this->getMock('NotDbDriver', array(), array(), 'NoDbDriverMock');
$this->setExpectedException('InitializationException');
$driver = Db::connect('nodb', array('hostname' => 'localhost', 'driver' => 'NoDbDriverMock'));
}

11
tests/model/ModelTest.php

@ -111,15 +111,8 @@ class ModelTest extends PHPUnit_Framework_TestCase
$model = new ReflectionClass('Model');
$method = $model->getMethod('fetch');
$method->setAccessible(true);
$key = $this->getCacheKeyMockGetSet();
//$debug = print_r($this->model, true);
//throw new Exception($debug);
$this->assertEquals('field', $method->invoke($this->model, 'SELECT', array(), $key));
$this->assertTrue(true, $method->invoke($this->model, 'SELECT', array(), $key));
}
public function testFetchField()
@ -139,7 +132,7 @@ class ModelTest extends PHPUnit_Framework_TestCase
$method->setAccessible(true);
$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()

5
tests/model/MySQLiDriverTest.php

@ -80,16 +80,13 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase
$this->assertTrue($driver->isConnected());
}
/**
* @expectedException GeneralException
* @expectedExceptionMessage Unknown database
*/
public function testGetConnectionWrongConfig()
{
if (!defined('DEBUG')) {
define('DEBUG', false);
}
$this->setExpectedException('GeneralException', 'Unknown database \'nodb\'');
$this->conf['database'] = 'nodb';
$driver = new MySQLiDriver($this->conf);
$this->assertNull('mysqli', $driver->getConnection());

9
tests/model/MySQLiStatementTest.php

@ -64,14 +64,13 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
/**
* @runInSeparateProcess
* @expectedException GeneralException
* @expectedExceptionMessage ERROR
*/
public function testDriverExecuteNoResult()
{
if (!defined('DEBUG')) {
define('DEBUG', false);
}
$this->setExpectedException('GeneralException', 'ERROR');
$this->setDriverGetConnectionWrongResultMethod();
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
}
@ -158,19 +157,16 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
*/
public function testNumRows()
{
$this->markTestSkipped();
$this->markTestSkipped('Unable to execute a method or access a property of an incomplete object.');
if (!defined('DEBUG')) {
define('DEBUG', false);
}
$this->setDriverGetConnectionMethod();
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
$this->assertNull($this->stmt->numRows());
}
/**
* @expectedException GeneralException
* @expectedExceptionMessage Invalid fetch mode
* @runInSeparateProcess
*/
public function testFetchInvalidMode()
@ -178,6 +174,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
if (!defined('DEBUG')) {
define('DEBUG', false);
}
$this->setExpectedException('GeneralException');
$this->setDriverGetConnectionMethod();
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
$this->stmt->fetch(324);

Loading…
Cancel
Save