diff --git a/model/MongoDbCommand.php b/model/MongoDbCommand.php index d348d4c..88a849d 100644 --- a/model/MongoDbCommand.php +++ b/model/MongoDbCommand.php @@ -38,7 +38,7 @@ abstract class MongoDbCommand if ($this->checkParams()) { return $this->concreteExecute(); } 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.'); } } diff --git a/model/MongoModel.php b/model/MongoModel.php index 8eb1814..cb433dc 100644 --- a/model/MongoModel.php +++ b/model/MongoModel.php @@ -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) */ protected function fetchField($data, $params = array(), $field, $cache_key = null) diff --git a/model/MongoStatement.php b/model/MongoStatement.php index 399cb67..9060dee 100644 --- a/model/MongoStatement.php +++ b/model/MongoStatement.php @@ -22,7 +22,7 @@ class MongoStatement extends DbStatement $this->result->sort($sort); return $this; } 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); return $this; } 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); return $this; } 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; default: - throw new Exception('Invalid fetch mode "' . $style . '" specified'); + throw new GeneralException('Invalid fetch mode "' . $style . '" specified'); } return $row; } @@ -132,7 +132,7 @@ class MongoStatement extends DbStatement $result = $request->execute(); } if ($result === false) { - throw new Exception('MongoDB request error.'); + throw new GeneralException('MongoDB request error.'); } if ($result instanceof MongoCursor || is_array($result)) { $this->result = $result; @@ -148,7 +148,7 @@ class MongoStatement extends DbStatement } return true; } else { - throw new Exception('No connection to MongoDB server.'); + throw new GeneralException('No connection to MongoDB server.'); } } diff --git a/model/MySQLiStatement.php b/model/MySQLiStatement.php index 47160cc..b489899 100644 --- a/model/MySQLiStatement.php +++ b/model/MySQLiStatement.php @@ -25,10 +25,10 @@ class MySQLiStatement extends 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/tests/model/MongoDbCommandTest.php b/tests/model/MongoDbCommandTest.php index 75a18d6..a325379 100644 --- a/tests/model/MongoDbCommandTest.php +++ b/tests/model/MongoDbCommandTest.php @@ -14,6 +14,7 @@ require_once dirname(__FILE__) . '/../../model/DbDriver.php'; require_once dirname(__FILE__) . '/../../model/NoSqlDbDriver.php'; require_once dirname(__FILE__) . '/../../model/MongoDriver.php'; require_once dirname(__FILE__) . '/../../model/MongoDbCommand.php'; +require_once dirname(__FILE__) . '/../../exception/GeneralException.php'; 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. */ 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. */ 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. */ 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. */ 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. */ public function testCommandCommandNotAllParamsBinded() diff --git a/tests/model/MongoDriverTest.php b/tests/model/MongoDriverTest.php index edcedd4..a027f1b 100644 --- a/tests/model/MongoDriverTest.php +++ b/tests/model/MongoDriverTest.php @@ -17,6 +17,7 @@ require_once dirname(__FILE__) . '/../../model/MongoDbCommand.php'; require_once dirname(__FILE__) . '/../../model/DbStatement.php'; require_once dirname(__FILE__) . '/../../model/MongoStatement.php'; require_once dirname(__FILE__) . '/../../model/MongoDriver.php'; +require_once dirname(__FILE__) . '/../../exception/GeneralException.php'; 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". */ public function testGetConnectionNoHostname() diff --git a/tests/model/MongoModelTest.php b/tests/model/MongoModelTest.php index 695b788..cc3d8a6 100644 --- a/tests/model/MongoModelTest.php +++ b/tests/model/MongoModelTest.php @@ -101,6 +101,20 @@ class MongoModelTest extends PHPUnit_Framework_TestCase /** * @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() { if (!defined('DEBUG')) { diff --git a/tests/model/MongoStatementTest.php b/tests/model/MongoStatementTest.php index 81eba4a..a09a324 100644 --- a/tests/model/MongoStatementTest.php +++ b/tests/model/MongoStatementTest.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/MongoStatement.php'; +require_once dirname(__FILE__) . '/../../exception/GeneralException.php'; class MongoStatementTest extends PHPUnit_Framework_TestCase { @@ -136,7 +137,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase /** * @runInSeparateProcess - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage MongoDB request error. */ public function testExecuteNoResult() @@ -154,7 +155,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase /** * @runInSeparateProcess - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage No connection to MongoDB server. */ public function testExecuteNoConnection() @@ -283,7 +284,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase /** * @runInSeparateProcess - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage Invalid fetch mode "222" specified */ public function testFetchWrongMode() @@ -324,7 +325,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase /** * @runInSeparateProcess - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage MongoStatement error. Impossible order results of opened cursor */ public function testOrderException() @@ -344,7 +345,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase /** * @runInSeparateProcess - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage MongoStatement error. Impossible skip results of opened cursor */ public function testSkipException() @@ -364,7 +365,7 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase /** * @runInSeparateProcess - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage MongoStatement error. Impossible limit results of opened cursor */ public function testLimitException() diff --git a/tests/model/MySQLiStatementTest.php b/tests/model/MySQLiStatementTest.php index 71b72bb..c50149d 100644 --- a/tests/model/MySQLiStatementTest.php +++ b/tests/model/MySQLiStatementTest.php @@ -63,7 +63,7 @@ class MySQLiStatementTest 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 */ @@ -74,7 +74,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase } /** - * @expectedException Exception + * @expectedException GeneralException * @expectedExceptionMessage Objects excepts DbExpr not allowed. */ public function testBindParamExceptionWrongObject() @@ -101,7 +101,7 @@ class MySQLiStatementTest extends PHPUnit_Framework_TestCase $this->setDriverGetConnectionMethod(); $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'; $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)); $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()); } /**