From d5ae1334788fc98f0201abe540c98a7a8dd5b33f Mon Sep 17 00:00:00 2001 From: Anton Grebnev Date: Tue, 5 Jun 2012 13:52:39 +0400 Subject: [PATCH] added test for findAndModify if no item in collection and test for eval --- model/MongoStatement.php | 3 ++- tests/model/MongoDriverTest.php | 35 +++++++++++++++++++++++++++++++++++ tests/model/MongoStatementTest.php | 4 ++-- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/model/MongoStatement.php b/model/MongoStatement.php index 6097c10..45d194c 100644 --- a/model/MongoStatement.php +++ b/model/MongoStatement.php @@ -135,6 +135,7 @@ class MongoStatement extends DbStatement */ protected function driverExecute($request) { + $this->result = false; $mongo = $this->driver->getConnection(); if ($mongo instanceof Mongo) { if (DEBUG) { @@ -181,4 +182,4 @@ class MongoStatement extends DbStatement { return $this->insertId; } -} \ No newline at end of file +} diff --git a/tests/model/MongoDriverTest.php b/tests/model/MongoDriverTest.php index e11bb2a..26c6a1c 100644 --- a/tests/model/MongoDriverTest.php +++ b/tests/model/MongoDriverTest.php @@ -369,6 +369,41 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase * @runInSeparateProcess * @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() { if (!defined('DEBUG')) { diff --git a/tests/model/MongoStatementTest.php b/tests/model/MongoStatementTest.php index 1fb5fca..b2415f1 100644 --- a/tests/model/MongoStatementTest.php +++ b/tests/model/MongoStatementTest.php @@ -245,10 +245,10 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase $this->request ->expects($this->once()) ->method('execute') - ->will($this->returnValue(array('some' => 'val'))); + ->will($this->returnValue(array('retval' => 'val'))); $this->stmt->execute(); - $this->assertFalse($this->stmt->fetch()); + $this->assertEquals('val', $this->stmt->fetch()); } /**