From 0140c3f4adc60d4ee1a80b80ce9a5419e2543441 Mon Sep 17 00:00:00 2001 From: Anton Grebnev Date: Thu, 19 Jan 2012 19:16:31 +0400 Subject: [PATCH] added condition to batchInsert against empty arrays --- model/MongoDbCommand.php | 5 ++++- tests/model/MongoDbCommandTest.php | 5 +++++ tests/model/MongoModelTest.php | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/model/MongoDbCommand.php b/model/MongoDbCommand.php index 8441242..0cc81b5 100644 --- a/model/MongoDbCommand.php +++ b/model/MongoDbCommand.php @@ -125,11 +125,14 @@ class InsertMongoCommand extends MongoDbCommand protected function concreteExecute() { + $result = null; if (!$this->multiple) { $result = $this->collection->insert($this->data, array('safe' => $this->safe)); $this->insertId = $this->data['_id']; } else { - $result = $this->collection->batchInsert($this->data, array('safe' => $this->safe)); + if (count($this->data)) { + $result = $this->collection->batchInsert($this->data, array('safe' => $this->safe)); + } } return $result; } diff --git a/tests/model/MongoDbCommandTest.php b/tests/model/MongoDbCommandTest.php index 6adf834..e3bb265 100644 --- a/tests/model/MongoDbCommandTest.php +++ b/tests/model/MongoDbCommandTest.php @@ -151,6 +151,9 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase $this->assertArrayHasKey('n', $cmd->execute()); + $cmd->bindParam('data', array()); + $cmd->execute(); + $cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection); $cmd->bindParam('condition', array('name' => 'first object'))->bindParam('fields', array()); $result = $cmd->execute(); @@ -161,6 +164,8 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase $cmd->bindParam('condition', array('name' => 'equal object'))->bindParam('fields', array()); $result = $cmd->execute(); $this->assertEquals(2, $result->count()); + + } /** diff --git a/tests/model/MongoModelTest.php b/tests/model/MongoModelTest.php index e30cc79..af136a3 100644 --- a/tests/model/MongoModelTest.php +++ b/tests/model/MongoModelTest.php @@ -126,6 +126,7 @@ class MongoModelTest extends PHPUnit_Framework_TestCase $this->model->batchInsert($data); $this->assertEquals(1, $this->model->count(array('name' => 'first object'))); $this->assertEquals(2, $this->model->count(array('name' => 'equal object'))); + $this->model->batchInsert(array()); } /**