diff --git a/model/Db.php b/model/Db.php index a587fa5..95e738c 100644 --- a/model/Db.php +++ b/model/Db.php @@ -40,7 +40,7 @@ class Db } if (!is_array($config)) { - throw new Exception('Connection parameters must be an array'); + throw new GeneralException('Connection parameters must be an array'); } $driver = 'MySQLiDriver'; @@ -52,7 +52,7 @@ class Db $connection = new $driver($config); if (!$connection instanceof DbDriver) { - throw new Exception('Database driver must extends DbDriver'); + throw new GeneralException('Database driver must extends DbDriver'); } self::$connections[$name] = $connection; } diff --git a/model/DbDriver.php b/model/DbDriver.php index 444d2af..7670662 100644 --- a/model/DbDriver.php +++ b/model/DbDriver.php @@ -40,7 +40,7 @@ abstract class DbDriver $required = array('database', 'username', 'password', 'hostname'); foreach ($required as $option) { if (!isset($config[$option])) { - throw new Exception('Configuration must have a "' . $option . '".'); + throw new GeneralException('Configuration must have a "' . $option . '".'); } } } diff --git a/model/DbStatement.php b/model/DbStatement.php index 301c574..58e3cd5 100644 --- a/model/DbStatement.php +++ b/model/DbStatement.php @@ -41,10 +41,10 @@ abstract class DbStatement } if (count($this->map) > 0) { if (!is_string($param) && !is_int($param)) { - throw new Exception('Placeholder must be an array or string'); + throw new GeneralException('Placeholder must be an array or string'); } if (is_object($value) && ! ($value instanceof DbExpr)) { - throw new Exception('Objects excepts DbExpr not allowed.'); + throw new GeneralException('Objects excepts DbExpr not allowed.'); } if (isset($this->map[$param])) { $this->params[$param] = &$value; diff --git a/model/MySQLiDriver.php b/model/MySQLiDriver.php index 4afa22c..a287fb4 100644 --- a/model/MySQLiDriver.php +++ b/model/MySQLiDriver.php @@ -80,7 +80,7 @@ class MySQLiDriver extends DbDriver $port); // Connection errors check if (mysqli_connect_error()) { - throw new Exception(mysqli_connect_error(), mysqli_connect_errno()); + throw new GeneralException(mysqli_connect_error(), mysqli_connect_errno()); } $charset = (!empty($this->config['charset'])) ? $this->config['charset'] : 'utf8'; diff --git a/model/MySQLiStatement.php b/model/MySQLiStatement.php index 6e0ec6b..54dcd63 100644 --- a/model/MySQLiStatement.php +++ b/model/MySQLiStatement.php @@ -43,7 +43,7 @@ class MySQLiStatement extends DbStatement $row = $this->result->fetch_array(MYSQLI_BOTH); break; default: - throw new Exception('Invalid fetch mode "' . $style . '" specified'); + throw new GeneralException('Invalid fetch mode "' . $style . '" specified'); } return $row; } @@ -92,7 +92,7 @@ class MySQLiStatement extends DbStatement } if ($result === false) { $message = $mysqli->error . "\nQuery: \"" . $sql . '"'; - throw new Exception($message, $mysqli->errno); + throw new GeneralException($message, $mysqli->errno); } if ($result instanceof MySQLi_Result) { $this->result = $result; diff --git a/tests/ConfigTest.php b/tests/ConfigTest.php index b340b95..690100a 100644 --- a/tests/ConfigTest.php +++ b/tests/ConfigTest.php @@ -12,6 +12,7 @@ require_once dirname(__FILE__) . '/../Registry.php'; require_once dirname(__FILE__) . '/../Config.php'; +require_once dirname(__FILE__) . '/../exception/GeneralException.php'; class ConfigTest extends PHPUnit_Framework_TestCase { @@ -34,7 +35,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase } /** - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage Configuration variable */ public function testArrayAsParam() diff --git a/tests/model/DbDriverTest.php b/tests/model/DbDriverTest.php index 891b0a0..d8c5518 100644 --- a/tests/model/DbDriverTest.php +++ b/tests/model/DbDriverTest.php @@ -13,6 +13,7 @@ require_once dirname(__FILE__) . '/../../model/DbExpr.php'; require_once dirname(__FILE__) . '/../../model/Db.php'; require_once dirname(__FILE__) . '/../../model/DbDriver.php'; +require_once dirname(__FILE__) . '/../../exception/GeneralException.php'; class DbDriverTest extends PHPUnit_Framework_TestCase { @@ -32,7 +33,7 @@ class DbDriverTest extends PHPUnit_Framework_TestCase } /** - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage Configuration must have a "username". */ public function testConstructWrongConfig() diff --git a/tests/model/DbStatementTest.php b/tests/model/DbStatementTest.php index 4624bfa..3f78360 100644 --- a/tests/model/DbStatementTest.php +++ b/tests/model/DbStatementTest.php @@ -13,6 +13,7 @@ require_once dirname(__FILE__) . '/../../model/Db.php'; require_once dirname(__FILE__) . '/../../model/DbDriver.php'; require_once dirname(__FILE__) . '/../../model/DbStatement.php'; +require_once dirname(__FILE__) . '/../../exception/GeneralException.php'; class DbStatementTest extends PHPUnit_Framework_TestCase { @@ -56,7 +57,7 @@ class DbStatementTest extends PHPUnit_Framework_TestCase } /** - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage Placeholder must be an array or string * @TODO: change Exception Message 'Placeholder must be an array or string' - no arrays available */ @@ -67,7 +68,7 @@ class DbStatementTest extends PHPUnit_Framework_TestCase } /** - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage Objects excepts DbExpr not allowed. */ public function testBindParamExceptionWrongObject() diff --git a/tests/model/DbTest.php b/tests/model/DbTest.php index f1e9847..4357379 100644 --- a/tests/model/DbTest.php +++ b/tests/model/DbTest.php @@ -14,12 +14,13 @@ require_once dirname(__FILE__) . '/../../Registry.php'; 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'; class DbTest extends PHPUnit_Framework_TestCase { /** - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage Trying to get property of non-object */ public function testConnectNoParams() @@ -27,7 +28,7 @@ class DbTest extends PHPUnit_Framework_TestCase Db::connect(); } /** - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage Connection parameters must be an array */ public function testConnectConfigNotArray() @@ -51,7 +52,7 @@ class DbTest extends PHPUnit_Framework_TestCase $this->assertInstanceOf('DbDriver', $driver); } /** - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage Database driver must extends DbDriver */ public function testConnectWithWrongDriver() diff --git a/tests/model/MySQLiDriverTest.php b/tests/model/MySQLiDriverTest.php index 156cdad..20eab2a 100644 --- a/tests/model/MySQLiDriverTest.php +++ b/tests/model/MySQLiDriverTest.php @@ -15,6 +15,7 @@ require_once dirname(__FILE__) . '/../../model/DbStatement.php'; require_once dirname(__FILE__) . '/../../model/MySQLiStatement.php'; require_once dirname(__FILE__) . '/../../model/DbDriver.php'; require_once dirname(__FILE__) . '/../../model/MySQLiDriver.php'; +require_once dirname(__FILE__) . '/../../exception/GeneralException.php'; class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase { @@ -80,7 +81,7 @@ class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase } /** - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage Unknown database */ public function testGetConnectionWrongConfig() diff --git a/tests/model/MySQLiStatementTest.php b/tests/model/MySQLiStatementTest.php index 1e695c6..8f03e4a 100644 --- a/tests/model/MySQLiStatementTest.php +++ b/tests/model/MySQLiStatementTest.php @@ -16,6 +16,7 @@ require_once dirname(__FILE__) . '/../../model/Db.php'; require_once dirname(__FILE__) . '/../../model/DbDriver.php'; require_once dirname(__FILE__) . '/../../model/DbStatement.php'; require_once dirname(__FILE__) . '/../../model/MySQLiStatement.php'; +require_once dirname(__FILE__) . '/../../exception/GeneralException.php'; class MySQLiStatementTest extends PHPUnit_Framework_TestCase { @@ -63,7 +64,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase /** * @runInSeparateProcess - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage ERROR */ public function testDriverExecuteNoResult() @@ -153,22 +154,22 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase /** * @runInSeparateProcess - * @expectedException Exception * @TODO: exception just for code coverage - could not mock mysqli properties */ public function testNumRows() { + $this->markTestSkipped(); if (!defined('DEBUG')) { define('DEBUG', false); } - + $this->setDriverGetConnectionMethod(); $this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val')); $this->assertNull($this->stmt->numRows()); } /** - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage Invalid fetch mode * @runInSeparateProcess */