added condition to batchInsert against empty arrays
This commit is contained in:
@ -125,11 +125,14 @@ class InsertMongoCommand extends MongoDbCommand
|
|||||||
|
|
||||||
protected function concreteExecute()
|
protected function concreteExecute()
|
||||||
{
|
{
|
||||||
|
$result = null;
|
||||||
if (!$this->multiple) {
|
if (!$this->multiple) {
|
||||||
$result = $this->collection->insert($this->data, array('safe' => $this->safe));
|
$result = $this->collection->insert($this->data, array('safe' => $this->safe));
|
||||||
$this->insertId = $this->data['_id'];
|
$this->insertId = $this->data['_id'];
|
||||||
} else {
|
} 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;
|
return $result;
|
||||||
}
|
}
|
||||||
|
@ -151,6 +151,9 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertArrayHasKey('n', $cmd->execute());
|
$this->assertArrayHasKey('n', $cmd->execute());
|
||||||
|
|
||||||
|
$cmd->bindParam('data', array());
|
||||||
|
$cmd->execute();
|
||||||
|
|
||||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection);
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection);
|
||||||
$cmd->bindParam('condition', array('name' => 'first object'))->bindParam('fields', array());
|
$cmd->bindParam('condition', array('name' => 'first object'))->bindParam('fields', array());
|
||||||
$result = $cmd->execute();
|
$result = $cmd->execute();
|
||||||
@ -161,6 +164,8 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
|||||||
$cmd->bindParam('condition', array('name' => 'equal object'))->bindParam('fields', array());
|
$cmd->bindParam('condition', array('name' => 'equal object'))->bindParam('fields', array());
|
||||||
$result = $cmd->execute();
|
$result = $cmd->execute();
|
||||||
$this->assertEquals(2, $result->count());
|
$this->assertEquals(2, $result->count());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -126,6 +126,7 @@ class MongoModelTest extends PHPUnit_Framework_TestCase
|
|||||||
$this->model->batchInsert($data);
|
$this->model->batchInsert($data);
|
||||||
$this->assertEquals(1, $this->model->count(array('name' => 'first object')));
|
$this->assertEquals(1, $this->model->count(array('name' => 'first object')));
|
||||||
$this->assertEquals(2, $this->model->count(array('name' => 'equal object')));
|
$this->assertEquals(2, $this->model->count(array('name' => 'equal object')));
|
||||||
|
$this->model->batchInsert(array());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user