|
@ -132,6 +132,45 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase |
|
|
/** |
|
|
/** |
|
|
* @group Mongo |
|
|
* @group Mongo |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
public function testInsertCommandMultipleObjects() |
|
|
|
|
|
{ |
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection); |
|
|
|
|
|
|
|
|
|
|
|
$data = array( |
|
|
|
|
|
array('name' => 'first object'), |
|
|
|
|
|
array('name' => 'second object'), |
|
|
|
|
|
array('name' => 'equal object'), |
|
|
|
|
|
array('name' => 'equal object') |
|
|
|
|
|
); |
|
|
|
|
|
$cmd |
|
|
|
|
|
->bindParam('data', $data) |
|
|
|
|
|
->bindParam('multiple', true) |
|
|
|
|
|
->bindParam('safe', true); |
|
|
|
|
|
|
|
|
|
|
|
$this->assertFalse($cmd->getInsertId()); |
|
|
|
|
|
|
|
|
|
|
|
$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(); |
|
|
|
|
|
$this->assertEquals(1, $result->count()); |
|
|
|
|
|
$cmd->bindParam('condition', array('name' => 'second object'))->bindParam('fields', array()); |
|
|
|
|
|
$result = $cmd->execute(); |
|
|
|
|
|
$this->assertEquals(1, $result->count()); |
|
|
|
|
|
$cmd->bindParam('condition', array('name' => 'equal object'))->bindParam('fields', array()); |
|
|
|
|
|
$result = $cmd->execute(); |
|
|
|
|
|
$this->assertEquals(2, $result->count()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* @group Mongo |
|
|
|
|
|
*/ |
|
|
public function testInsertCommandNotAllParamsBinded() |
|
|
public function testInsertCommandNotAllParamsBinded() |
|
|
{ |
|
|
{ |
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection); |
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection); |
|
@ -277,6 +316,15 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase |
|
|
->bindParam('data', array('name' => 'insert')) |
|
|
->bindParam('data', array('name' => 'insert')) |
|
|
->bindParam('safe', true); |
|
|
->bindParam('safe', true); |
|
|
$this->assertStringStartsWith('Collection: ', $cmd->__toString()); |
|
|
$this->assertStringStartsWith('Collection: ', $cmd->__toString()); |
|
|
|
|
|
$this->assertContains('Bulk insert: FALSE', $cmd->__toString()); |
|
|
|
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection); |
|
|
|
|
|
$this->assertSame('Command properties not set', $cmd->__toString()); |
|
|
|
|
|
$cmd |
|
|
|
|
|
->bindParam('data', array('name' => 'insert')) |
|
|
|
|
|
->bindParam('multiple', true) |
|
|
|
|
|
->bindParam('safe', true); |
|
|
|
|
|
$this->assertContains('Bulk insert: TRUE', $cmd->__toString()); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection); |
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection); |
|
|
$this->assertSame('Command properties not set', $cmd->__toString()); |
|
|
$this->assertSame('Command properties not set', $cmd->__toString()); |
|
|