Browse Source

replace Exception on GeneralException

master
Vyacheslav Agafonov 13 years ago
parent
commit
443655064c
  1. 4
      model/Db.php
  2. 2
      model/DbDriver.php
  3. 4
      model/DbStatement.php
  4. 2
      model/MySQLiDriver.php
  5. 4
      model/MySQLiStatement.php
  6. 3
      tests/ConfigTest.php
  7. 3
      tests/model/DbDriverTest.php
  8. 5
      tests/model/DbStatementTest.php
  9. 7
      tests/model/DbTest.php
  10. 3
      tests/model/MySQLiDriverTest.php
  11. 9
      tests/model/MySQLiStatementTest.php

4
model/Db.php

@ -40,7 +40,7 @@ class Db
} }
if (!is_array($config)) { if (!is_array($config)) {
throw new Exception('Connection parameters must be an array');
throw new GeneralException('Connection parameters must be an array');
} }
$driver = 'MySQLiDriver'; $driver = 'MySQLiDriver';
@ -52,7 +52,7 @@ class Db
$connection = new $driver($config); $connection = new $driver($config);
if (!$connection instanceof DbDriver) { if (!$connection instanceof DbDriver) {
throw new Exception('Database driver must extends DbDriver');
throw new GeneralException('Database driver must extends DbDriver');
} }
self::$connections[$name] = $connection; self::$connections[$name] = $connection;
} }

2
model/DbDriver.php

@ -40,7 +40,7 @@ abstract class DbDriver
$required = array('database', 'username', 'password', 'hostname'); $required = array('database', 'username', 'password', 'hostname');
foreach ($required as $option) { foreach ($required as $option) {
if (!isset($config[$option])) { if (!isset($config[$option])) {
throw new Exception('Configuration must have a "' . $option . '".');
throw new GeneralException('Configuration must have a "' . $option . '".');
} }
} }
} }

4
model/DbStatement.php

@ -41,10 +41,10 @@ abstract class DbStatement
} }
if (count($this->map) > 0) { if (count($this->map) > 0) {
if (!is_string($param) && !is_int($param)) { 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)) { 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])) { if (isset($this->map[$param])) {
$this->params[$param] = &$value; $this->params[$param] = &$value;

2
model/MySQLiDriver.php

@ -80,7 +80,7 @@ class MySQLiDriver extends DbDriver
$port); $port);
// Connection errors check // Connection errors check
if (mysqli_connect_error()) { 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'; $charset = (!empty($this->config['charset'])) ? $this->config['charset'] : 'utf8';

4
model/MySQLiStatement.php

@ -43,7 +43,7 @@ class MySQLiStatement extends DbStatement
$row = $this->result->fetch_array(MYSQLI_BOTH); $row = $this->result->fetch_array(MYSQLI_BOTH);
break; break;
default: default:
throw new Exception('Invalid fetch mode "' . $style . '" specified');
throw new GeneralException('Invalid fetch mode "' . $style . '" specified');
} }
return $row; return $row;
} }
@ -92,7 +92,7 @@ class MySQLiStatement extends DbStatement
} }
if ($result === false) { if ($result === false) {
$message = $mysqli->error . "\nQuery: \"" . $sql . '"'; $message = $mysqli->error . "\nQuery: \"" . $sql . '"';
throw new Exception($message, $mysqli->errno);
throw new GeneralException($message, $mysqli->errno);
} }
if ($result instanceof MySQLi_Result) { if ($result instanceof MySQLi_Result) {
$this->result = $result; $this->result = $result;

3
tests/ConfigTest.php

@ -12,6 +12,7 @@
require_once dirname(__FILE__) . '/../Registry.php'; require_once dirname(__FILE__) . '/../Registry.php';
require_once dirname(__FILE__) . '/../Config.php'; require_once dirname(__FILE__) . '/../Config.php';
require_once dirname(__FILE__) . '/../exception/GeneralException.php';
class ConfigTest extends PHPUnit_Framework_TestCase class ConfigTest extends PHPUnit_Framework_TestCase
{ {
@ -34,7 +35,7 @@ class ConfigTest extends PHPUnit_Framework_TestCase
} }
/** /**
* @expectedException Exception
* @expectedException GeneralException
* @expectedExceptionMessage Configuration variable * @expectedExceptionMessage Configuration variable
*/ */
public function testArrayAsParam() public function testArrayAsParam()

3
tests/model/DbDriverTest.php

@ -13,6 +13,7 @@
require_once dirname(__FILE__) . '/../../model/DbExpr.php'; require_once dirname(__FILE__) . '/../../model/DbExpr.php';
require_once dirname(__FILE__) . '/../../model/Db.php'; require_once dirname(__FILE__) . '/../../model/Db.php';
require_once dirname(__FILE__) . '/../../model/DbDriver.php'; require_once dirname(__FILE__) . '/../../model/DbDriver.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
class DbDriverTest extends PHPUnit_Framework_TestCase 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". * @expectedExceptionMessage Configuration must have a "username".
*/ */
public function testConstructWrongConfig() public function testConstructWrongConfig()

5
tests/model/DbStatementTest.php

@ -13,6 +13,7 @@
require_once dirname(__FILE__) . '/../../model/Db.php'; require_once dirname(__FILE__) . '/../../model/Db.php';
require_once dirname(__FILE__) . '/../../model/DbDriver.php'; require_once dirname(__FILE__) . '/../../model/DbDriver.php';
require_once dirname(__FILE__) . '/../../model/DbStatement.php'; require_once dirname(__FILE__) . '/../../model/DbStatement.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
class DbStatementTest extends PHPUnit_Framework_TestCase 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 * @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
*/ */
@ -67,7 +68,7 @@ class DbStatementTest extends PHPUnit_Framework_TestCase
} }
/** /**
* @expectedException Exception
* @expectedException GeneralException
* @expectedExceptionMessage Objects excepts DbExpr not allowed. * @expectedExceptionMessage Objects excepts DbExpr not allowed.
*/ */
public function testBindParamExceptionWrongObject() public function testBindParamExceptionWrongObject()

7
tests/model/DbTest.php

@ -14,12 +14,13 @@ require_once dirname(__FILE__) . '/../../Registry.php';
require_once dirname(__FILE__) . '/../../Config.php'; 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';
class DbTest extends PHPUnit_Framework_TestCase class DbTest extends PHPUnit_Framework_TestCase
{ {
/** /**
* @expectedException Exception
* @expectedException GeneralException
* @expectedExceptionMessage Trying to get property of non-object * @expectedExceptionMessage Trying to get property of non-object
*/ */
public function testConnectNoParams() public function testConnectNoParams()
@ -27,7 +28,7 @@ class DbTest extends PHPUnit_Framework_TestCase
Db::connect(); Db::connect();
} }
/** /**
* @expectedException Exception
* @expectedException GeneralException
* @expectedExceptionMessage Connection parameters must be an array * @expectedExceptionMessage Connection parameters must be an array
*/ */
public function testConnectConfigNotArray() public function testConnectConfigNotArray()
@ -51,7 +52,7 @@ class DbTest extends PHPUnit_Framework_TestCase
$this->assertInstanceOf('DbDriver', $driver); $this->assertInstanceOf('DbDriver', $driver);
} }
/** /**
* @expectedException Exception
* @expectedException GeneralException
* @expectedExceptionMessage Database driver must extends DbDriver * @expectedExceptionMessage Database driver must extends DbDriver
*/ */
public function testConnectWithWrongDriver() public function testConnectWithWrongDriver()

3
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/MySQLiStatement.php';
require_once dirname(__FILE__) . '/../../model/DbDriver.php'; require_once dirname(__FILE__) . '/../../model/DbDriver.php';
require_once dirname(__FILE__) . '/../../model/MySQLiDriver.php'; require_once dirname(__FILE__) . '/../../model/MySQLiDriver.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
class MySQLiDriverTest extends PHPUnit_Extensions_Database_TestCase 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 * @expectedExceptionMessage Unknown database
*/ */
public function testGetConnectionWrongConfig() public function testGetConnectionWrongConfig()

9
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/DbDriver.php';
require_once dirname(__FILE__) . '/../../model/DbStatement.php'; require_once dirname(__FILE__) . '/../../model/DbStatement.php';
require_once dirname(__FILE__) . '/../../model/MySQLiStatement.php'; require_once dirname(__FILE__) . '/../../model/MySQLiStatement.php';
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
class MySQLiStatementTest extends PHPUnit_Framework_TestCase class MySQLiStatementTest extends PHPUnit_Framework_TestCase
{ {
@ -63,7 +64,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
/** /**
* @runInSeparateProcess * @runInSeparateProcess
* @expectedException Exception
* @expectedException GeneralException
* @expectedExceptionMessage ERROR * @expectedExceptionMessage ERROR
*/ */
public function testDriverExecuteNoResult() public function testDriverExecuteNoResult()
@ -153,22 +154,22 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
/** /**
* @runInSeparateProcess * @runInSeparateProcess
* @expectedException Exception
* @TODO: exception just for code coverage - could not mock mysqli properties * @TODO: exception just for code coverage - could not mock mysqli properties
*/ */
public function testNumRows() public function testNumRows()
{ {
$this->markTestSkipped();
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 Exception
* @expectedException GeneralException
* @expectedExceptionMessage Invalid fetch mode * @expectedExceptionMessage Invalid fetch mode
* @runInSeparateProcess * @runInSeparateProcess
*/ */

Loading…
Cancel
Save