modified classes for GeneralException thrown
This commit is contained in:
@ -38,7 +38,7 @@ abstract class MongoDbCommand
|
|||||||
if ($this->checkParams()) {
|
if ($this->checkParams()) {
|
||||||
return $this->concreteExecute();
|
return $this->concreteExecute();
|
||||||
} else {
|
} else {
|
||||||
throw new Exception(get_called_class() . ' error. Bind all required params first.');
|
throw new GeneralException(get_called_class() . ' error. Bind all required params first.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,6 +34,14 @@ abstract class MongoModel extends Model
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @TODO: test method
|
||||||
|
*/
|
||||||
|
public function deleteAll($query = array())
|
||||||
|
{
|
||||||
|
$this->db->delete($this->table(), $query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* @TODO: check for limits (if just one record needed)
|
* @TODO: check for limits (if just one record needed)
|
||||||
*/
|
*/
|
||||||
protected function fetchField($data, $params = array(), $field, $cache_key = null)
|
protected function fetchField($data, $params = array(), $field, $cache_key = null)
|
||||||
|
@ -22,7 +22,7 @@ class MongoStatement extends DbStatement
|
|||||||
$this->result->sort($sort);
|
$this->result->sort($sort);
|
||||||
return $this;
|
return $this;
|
||||||
} else {
|
} else {
|
||||||
throw new Exception('MongoStatement error. Impossible order results of opened cursor.');
|
throw new GeneralException('MongoStatement error. Impossible order results of opened cursor.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ class MongoStatement extends DbStatement
|
|||||||
$this->result->skip($skip);
|
$this->result->skip($skip);
|
||||||
return $this;
|
return $this;
|
||||||
} else {
|
} else {
|
||||||
throw new Exception('MongoStatement error. Impossible skip results of opened cursor.');
|
throw new GeneralException('MongoStatement error. Impossible skip results of opened cursor.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +42,7 @@ class MongoStatement extends DbStatement
|
|||||||
$this->result->limit($limit);
|
$this->result->limit($limit);
|
||||||
return $this;
|
return $this;
|
||||||
} else {
|
} else {
|
||||||
throw new Exception('MongoStatement error. Impossible limit results of opened cursor.');
|
throw new GeneralException('MongoStatement error. Impossible limit results of opened cursor.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +65,7 @@ class MongoStatement extends DbStatement
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new Exception('Invalid fetch mode "' . $style . '" specified');
|
throw new GeneralException('Invalid fetch mode "' . $style . '" specified');
|
||||||
}
|
}
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ class MongoStatement extends DbStatement
|
|||||||
$result = $request->execute();
|
$result = $request->execute();
|
||||||
}
|
}
|
||||||
if ($result === false) {
|
if ($result === false) {
|
||||||
throw new Exception('MongoDB request error.');
|
throw new GeneralException('MongoDB request error.');
|
||||||
}
|
}
|
||||||
if ($result instanceof MongoCursor || is_array($result)) {
|
if ($result instanceof MongoCursor || is_array($result)) {
|
||||||
$this->result = $result;
|
$this->result = $result;
|
||||||
@ -148,7 +148,7 @@ class MongoStatement extends DbStatement
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
throw new Exception('No connection to MongoDB server.');
|
throw new GeneralException('No connection to MongoDB server.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,10 +25,10 @@ class MySQLiStatement extends 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;
|
||||||
|
@ -14,6 +14,7 @@ require_once dirname(__FILE__) . '/../../model/DbDriver.php';
|
|||||||
require_once dirname(__FILE__) . '/../../model/NoSqlDbDriver.php';
|
require_once dirname(__FILE__) . '/../../model/NoSqlDbDriver.php';
|
||||||
require_once dirname(__FILE__) . '/../../model/MongoDriver.php';
|
require_once dirname(__FILE__) . '/../../model/MongoDriver.php';
|
||||||
require_once dirname(__FILE__) . '/../../model/MongoDbCommand.php';
|
require_once dirname(__FILE__) . '/../../model/MongoDbCommand.php';
|
||||||
|
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
|
||||||
|
|
||||||
class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -90,7 +91,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Exception
|
* @expectedException GeneralException
|
||||||
* @expectedExceptionMessage FindMongoCommand error. Bind all required params first.
|
* @expectedExceptionMessage FindMongoCommand error. Bind all required params first.
|
||||||
*/
|
*/
|
||||||
public function testFindCommandNotAllParamsBinded()
|
public function testFindCommandNotAllParamsBinded()
|
||||||
@ -120,7 +121,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Exception
|
* @expectedException GeneralException
|
||||||
* @expectedExceptionMessage InsertMongoCommand error. Bind all required params first.
|
* @expectedExceptionMessage InsertMongoCommand error. Bind all required params first.
|
||||||
*/
|
*/
|
||||||
public function testInsertCommandNotAllParamsBinded()
|
public function testInsertCommandNotAllParamsBinded()
|
||||||
@ -155,7 +156,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Exception
|
* @expectedException GeneralException
|
||||||
* @expectedExceptionMessage UpdateMongoCommand error. Bind all required params first.
|
* @expectedExceptionMessage UpdateMongoCommand error. Bind all required params first.
|
||||||
*/
|
*/
|
||||||
public function testUpdateCommandNotAllParamsBinded()
|
public function testUpdateCommandNotAllParamsBinded()
|
||||||
@ -191,7 +192,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Exception
|
* @expectedException GeneralException
|
||||||
* @expectedExceptionMessage RemoveMongoCommand error. Bind all required params first.
|
* @expectedExceptionMessage RemoveMongoCommand error. Bind all required params first.
|
||||||
*/
|
*/
|
||||||
public function testRemoveCommandNotAllParamsBinded()
|
public function testRemoveCommandNotAllParamsBinded()
|
||||||
@ -201,7 +202,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Exception
|
* @expectedException GeneralException
|
||||||
* @expectedExceptionMessage CommandMongoCommand error. Bind all required params first.
|
* @expectedExceptionMessage CommandMongoCommand error. Bind all required params first.
|
||||||
*/
|
*/
|
||||||
public function testCommandCommandNotAllParamsBinded()
|
public function testCommandCommandNotAllParamsBinded()
|
||||||
|
@ -17,6 +17,7 @@ require_once dirname(__FILE__) . '/../../model/MongoDbCommand.php';
|
|||||||
require_once dirname(__FILE__) . '/../../model/DbStatement.php';
|
require_once dirname(__FILE__) . '/../../model/DbStatement.php';
|
||||||
require_once dirname(__FILE__) . '/../../model/MongoStatement.php';
|
require_once dirname(__FILE__) . '/../../model/MongoStatement.php';
|
||||||
require_once dirname(__FILE__) . '/../../model/MongoDriver.php';
|
require_once dirname(__FILE__) . '/../../model/MongoDriver.php';
|
||||||
|
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
|
||||||
|
|
||||||
class MongoDriverTest extends PHPUnit_Framework_TestCase
|
class MongoDriverTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -72,7 +73,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Exception
|
* @expectedException GeneralException
|
||||||
* @expectedExceptionMessage Configuration must have a "hostname".
|
* @expectedExceptionMessage Configuration must have a "hostname".
|
||||||
*/
|
*/
|
||||||
public function testGetConnectionNoHostname()
|
public function testGetConnectionNoHostname()
|
||||||
|
@ -101,6 +101,20 @@ class MongoModelTest extends PHPUnit_Framework_TestCase
|
|||||||
/**
|
/**
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
*/
|
*/
|
||||||
|
public function testDeleteAll()
|
||||||
|
{
|
||||||
|
if (!defined('DEBUG')) {
|
||||||
|
define('DEBUG', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals(2, $this->model->count(array('name' => 'eggs')));
|
||||||
|
$this->assertEquals(0, $this->model->deleteAll(array('name' => 'eggs')));
|
||||||
|
$this->assertFalse($this->model->find(array('name' => 'eggs'))->fetch());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @runInSeparateProcess
|
||||||
|
*/
|
||||||
public function testCount()
|
public function testCount()
|
||||||
{
|
{
|
||||||
if (!defined('DEBUG')) {
|
if (!defined('DEBUG')) {
|
||||||
|
@ -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/MongoStatement.php';
|
require_once dirname(__FILE__) . '/../../model/MongoStatement.php';
|
||||||
|
require_once dirname(__FILE__) . '/../../exception/GeneralException.php';
|
||||||
|
|
||||||
class MongoStatementTest extends PHPUnit_Framework_TestCase
|
class MongoStatementTest extends PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -136,7 +137,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @expectedException Exception
|
* @expectedException GeneralException
|
||||||
* @expectedExceptionMessage MongoDB request error.
|
* @expectedExceptionMessage MongoDB request error.
|
||||||
*/
|
*/
|
||||||
public function testExecuteNoResult()
|
public function testExecuteNoResult()
|
||||||
@ -154,7 +155,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @expectedException Exception
|
* @expectedException GeneralException
|
||||||
* @expectedExceptionMessage No connection to MongoDB server.
|
* @expectedExceptionMessage No connection to MongoDB server.
|
||||||
*/
|
*/
|
||||||
public function testExecuteNoConnection()
|
public function testExecuteNoConnection()
|
||||||
@ -283,7 +284,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @expectedException Exception
|
* @expectedException GeneralException
|
||||||
* @expectedExceptionMessage Invalid fetch mode "222" specified
|
* @expectedExceptionMessage Invalid fetch mode "222" specified
|
||||||
*/
|
*/
|
||||||
public function testFetchWrongMode()
|
public function testFetchWrongMode()
|
||||||
@ -324,7 +325,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @expectedException Exception
|
* @expectedException GeneralException
|
||||||
* @expectedExceptionMessage MongoStatement error. Impossible order results of opened cursor
|
* @expectedExceptionMessage MongoStatement error. Impossible order results of opened cursor
|
||||||
*/
|
*/
|
||||||
public function testOrderException()
|
public function testOrderException()
|
||||||
@ -344,7 +345,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @expectedException Exception
|
* @expectedException GeneralException
|
||||||
* @expectedExceptionMessage MongoStatement error. Impossible skip results of opened cursor
|
* @expectedExceptionMessage MongoStatement error. Impossible skip results of opened cursor
|
||||||
*/
|
*/
|
||||||
public function testSkipException()
|
public function testSkipException()
|
||||||
@ -364,7 +365,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @expectedException Exception
|
* @expectedException GeneralException
|
||||||
* @expectedExceptionMessage MongoStatement error. Impossible limit results of opened cursor
|
* @expectedExceptionMessage MongoStatement error. Impossible limit results of opened cursor
|
||||||
*/
|
*/
|
||||||
public function testLimitException()
|
public function testLimitException()
|
||||||
|
@ -63,7 +63,7 @@ class MySQLiStatementTest 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
|
||||||
*/
|
*/
|
||||||
@ -74,7 +74,7 @@ class MySQLiStatementTest 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()
|
||||||
@ -101,7 +101,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->setDriverGetConnectionMethod();
|
$this->setDriverGetConnectionMethod();
|
||||||
|
|
||||||
$result = $this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
|
$result = $this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
|
||||||
$this->assertEquals('SELECT * place_val FROM place_val AND new_val', $result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -116,7 +116,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->sql = 'PLAIN SQL';
|
$this->sql = 'PLAIN SQL';
|
||||||
$result = $this->stmt->execute(array());
|
$result = $this->stmt->execute(array());
|
||||||
$this->assertEquals('PLAIN SQL', $result);
|
$this->assertTrue($result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -217,7 +217,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase
|
|||||||
->will($this->returnValue($mysqliMock));
|
->will($this->returnValue($mysqliMock));
|
||||||
|
|
||||||
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
|
$this->stmt->execute(array('place' => 'place_val', 'new' => 'new_val'));
|
||||||
$this->assertEquals(array('pair' => 'value'), $this->stmt->fetchPairs());
|
$this->assertSame(array('pair' => 'value'), $this->stmt->fetchPairs());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user