Browse Source

modified classes for GeneralException thrown

master
Anton Grebnev 13 years ago
parent
commit
71cc211c4f
  1. 2
      model/MongoDbCommand.php
  2. 8
      model/MongoModel.php
  3. 12
      model/MongoStatement.php
  4. 4
      model/MySQLiStatement.php
  5. 11
      tests/model/MongoDbCommandTest.php
  6. 3
      tests/model/MongoDriverTest.php
  7. 14
      tests/model/MongoModelTest.php
  8. 13
      tests/model/MongoStatementTest.php
  9. 10
      tests/model/MySQLiStatementTest.php

2
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.');
}
}

8
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)

12
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.');
}
}

4
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;

11
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()

3
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()

14
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')) {

13
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()

10
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());
}
/**

Loading…
Cancel
Save