added test for findAndModify if no item in collection and test for eval
This commit is contained in:
@ -135,6 +135,7 @@ class MongoStatement extends DbStatement
|
|||||||
*/
|
*/
|
||||||
protected function driverExecute($request)
|
protected function driverExecute($request)
|
||||||
{
|
{
|
||||||
|
$this->result = false;
|
||||||
$mongo = $this->driver->getConnection();
|
$mongo = $this->driver->getConnection();
|
||||||
if ($mongo instanceof Mongo) {
|
if ($mongo instanceof Mongo) {
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
@ -181,4 +182,4 @@ class MongoStatement extends DbStatement
|
|||||||
{
|
{
|
||||||
return $this->insertId;
|
return $this->insertId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -369,6 +369,41 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
|
|||||||
* @runInSeparateProcess
|
* @runInSeparateProcess
|
||||||
* @group Mongo
|
* @group Mongo
|
||||||
*/
|
*/
|
||||||
|
public function testFindAndModifyNoItem()
|
||||||
|
{
|
||||||
|
if (!defined('DEBUG')) {
|
||||||
|
define('DEBUG', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
$mongo = new MongoDriver($this->conf);
|
||||||
|
|
||||||
|
$this->assertEquals(10, $mongo->get('items', array('name' => 'bread'))->fetch()->quantity);
|
||||||
|
$result = $mongo->findAndModify('items', array('name' => 'breading'), array('$set' => array('quantity' => 20)))->fetch();
|
||||||
|
$this->assertFalse($result);
|
||||||
|
$this->assertEquals(10, $mongo->get('items', array('name' => 'bread'))->fetch()->quantity);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @runInSeparateProcess
|
||||||
|
* @group Mongo
|
||||||
|
*/
|
||||||
|
public function testEvalCommand()
|
||||||
|
{
|
||||||
|
if (!defined('DEBUG')) {
|
||||||
|
define('DEBUG', false);
|
||||||
|
}
|
||||||
|
$mongo = new MongoDriver($this->conf);
|
||||||
|
$result = $mongo->command('items', array('$eval' => 'function() { return db.items.count();}'));
|
||||||
|
$this->assertEquals(5, $result->fetch());
|
||||||
|
$this->assertEquals(5, $mongo->count('items'));
|
||||||
|
$result = $mongo->command('items', array('$eval' => 'function() { return "HELLO!";}'));
|
||||||
|
$this->assertEquals("HELLO!", $result->fetch());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @runInSeparateProcess
|
||||||
|
* @group Mongo
|
||||||
|
*/
|
||||||
public function testEval()
|
public function testEval()
|
||||||
{
|
{
|
||||||
if (!defined('DEBUG')) {
|
if (!defined('DEBUG')) {
|
||||||
|
@ -245,10 +245,10 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->request
|
$this->request
|
||||||
->expects($this->once())
|
->expects($this->once())
|
||||||
->method('execute')
|
->method('execute')
|
||||||
->will($this->returnValue(array('some' => 'val')));
|
->will($this->returnValue(array('retval' => 'val')));
|
||||||
|
|
||||||
$this->stmt->execute();
|
$this->stmt->execute();
|
||||||
$this->assertFalse($this->stmt->fetch());
|
$this->assertEquals('val', $this->stmt->fetch());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user