Browse Source

added condition to batchInsert against empty arrays

master
Anton Grebnev 13 years ago
parent
commit
0140c3f4ad
  1. 3
      model/MongoDbCommand.php
  2. 5
      tests/model/MongoDbCommandTest.php
  3. 1
      tests/model/MongoModelTest.php

3
model/MongoDbCommand.php

@ -125,12 +125,15 @@ 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 {
if (count($this->data)) {
$result = $this->collection->batchInsert($this->data, array('safe' => $this->safe));
}
}
return $result;
}

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

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

Loading…
Cancel
Save