|
@ -22,6 +22,8 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase |
|
|
|
|
|
|
|
|
private $driver; |
|
|
private $driver; |
|
|
|
|
|
|
|
|
|
|
|
private $collection; |
|
|
|
|
|
|
|
|
public function setUp() |
|
|
public function setUp() |
|
|
{ |
|
|
{ |
|
|
$this->conf = array( |
|
|
$this->conf = array( |
|
@ -38,6 +40,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase |
|
|
$db->authenticate($this->conf['username'], $this->conf['password']); |
|
|
$db->authenticate($this->conf['username'], $this->conf['password']); |
|
|
$collection = 'items'; |
|
|
$collection = 'items'; |
|
|
$db->dropCollection($collection); |
|
|
$db->dropCollection($collection); |
|
|
|
|
|
$this->collection = $db->selectCollection($collection); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function testCommandFactory() |
|
|
public function testCommandFactory() |
|
@ -58,8 +61,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase |
|
|
|
|
|
|
|
|
public function testFindCommand() |
|
|
public function testFindCommand() |
|
|
{ |
|
|
{ |
|
|
$collection = $this->driver->getCollection('items'); |
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $collection); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection); |
|
|
$cmd->bindParam('condition', array('name' => 'bread'))->bindParam('fields', array()); |
|
|
$cmd->bindParam('condition', array('name' => 'bread'))->bindParam('fields', array()); |
|
|
$result = $cmd->execute(); |
|
|
$result = $cmd->execute(); |
|
|
$this->assertEquals(0, $result->count()); |
|
|
$this->assertEquals(0, $result->count()); |
|
@ -71,22 +73,20 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase |
|
|
*/ |
|
|
*/ |
|
|
public function testFindCommandNotAllParamsBinded() |
|
|
public function testFindCommandNotAllParamsBinded() |
|
|
{ |
|
|
{ |
|
|
$collection = $this->driver->getCollection('items'); |
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $collection); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection); |
|
|
$cmd->bindParam('condition', array('name' => 'bread')); |
|
|
$cmd->bindParam('condition', array('name' => 'bread')); |
|
|
$cmd->execute(); |
|
|
$cmd->execute(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function testInsertCommand() |
|
|
public function testInsertCommand() |
|
|
{ |
|
|
{ |
|
|
$collection = $this->driver->getCollection('items'); |
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $collection); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection); |
|
|
$cmd |
|
|
$cmd |
|
|
->bindParam('data', array('name' => 'insert')) |
|
|
->bindParam('data', array('name' => 'insert')) |
|
|
->bindParam('safe', true); |
|
|
->bindParam('safe', true); |
|
|
$this->assertArrayHasKey('n', $cmd->execute()); |
|
|
$this->assertArrayHasKey('n', $cmd->execute()); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $collection); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection); |
|
|
$cmd->bindParam('condition', array('name' => 'insert'))->bindParam('fields', array()); |
|
|
$cmd->bindParam('condition', array('name' => 'insert'))->bindParam('fields', array()); |
|
|
$result = $cmd->execute(); |
|
|
$result = $cmd->execute(); |
|
|
$this->assertEquals(1, $result->count()); |
|
|
$this->assertEquals(1, $result->count()); |
|
@ -98,22 +98,19 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase |
|
|
*/ |
|
|
*/ |
|
|
public function testInsertCommandNotAllParamsBinded() |
|
|
public function testInsertCommandNotAllParamsBinded() |
|
|
{ |
|
|
{ |
|
|
$collection = $this->driver->getCollection('items'); |
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $collection); |
|
|
|
|
|
$cmd->bindParam('data', array('name' => 'bread')); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection); |
|
|
$cmd->execute(); |
|
|
$cmd->execute(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function testUpdateCommand() |
|
|
public function testUpdateCommand() |
|
|
{ |
|
|
{ |
|
|
$collection = $this->driver->getCollection('items'); |
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $collection); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection); |
|
|
$cmd |
|
|
$cmd |
|
|
->bindParam('data', array('name' => 'insert')) |
|
|
->bindParam('data', array('name' => 'insert')) |
|
|
->bindParam('safe', true); |
|
|
->bindParam('safe', true); |
|
|
$this->assertArrayHasKey('n', $cmd->execute()); |
|
|
$this->assertArrayHasKey('n', $cmd->execute()); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::UPDATE, $collection); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::UPDATE, $this->collection); |
|
|
$cmd |
|
|
$cmd |
|
|
->bindParam('condition', array('name' => 'insert')) |
|
|
->bindParam('condition', array('name' => 'insert')) |
|
|
->bindParam('data', array('$set' => array('name' => 'update'))) |
|
|
->bindParam('data', array('$set' => array('name' => 'update'))) |
|
@ -121,7 +118,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase |
|
|
->bindParam('safe', true); |
|
|
->bindParam('safe', true); |
|
|
$this->assertArrayHasKey('n', $cmd->execute()); |
|
|
$this->assertArrayHasKey('n', $cmd->execute()); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $collection); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection); |
|
|
$cmd->bindParam('condition', array('name' => 'insert'))->bindParam('fields', array()); |
|
|
$cmd->bindParam('condition', array('name' => 'insert'))->bindParam('fields', array()); |
|
|
$result = $cmd->execute(); |
|
|
$result = $cmd->execute(); |
|
|
$this->assertEquals(0, $result->count()); |
|
|
$this->assertEquals(0, $result->count()); |
|
@ -136,33 +133,31 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase |
|
|
*/ |
|
|
*/ |
|
|
public function testUpdateCommandNotAllParamsBinded() |
|
|
public function testUpdateCommandNotAllParamsBinded() |
|
|
{ |
|
|
{ |
|
|
$collection = $this->driver->getCollection('items'); |
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::UPDATE, $collection); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::UPDATE, $this->collection); |
|
|
$cmd->bindParam('data', array('name' => 'bread')); |
|
|
$cmd->bindParam('data', array('name' => 'bread')); |
|
|
$cmd->execute(); |
|
|
$cmd->execute(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function testRemoveCommand() |
|
|
public function testRemoveCommand() |
|
|
{ |
|
|
{ |
|
|
$collection = $this->driver->getCollection('items'); |
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $collection); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection); |
|
|
$cmd |
|
|
$cmd |
|
|
->bindParam('data', array('name' => 'insert')) |
|
|
->bindParam('data', array('name' => 'insert')) |
|
|
->bindParam('safe', true); |
|
|
->bindParam('safe', true); |
|
|
$this->assertArrayHasKey('n', $cmd->execute()); |
|
|
$this->assertArrayHasKey('n', $cmd->execute()); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $collection); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection); |
|
|
$cmd->bindParam('condition', array('name' => 'insert'))->bindParam('fields', array()); |
|
|
$cmd->bindParam('condition', array('name' => 'insert'))->bindParam('fields', array()); |
|
|
$result = $cmd->execute(); |
|
|
$result = $cmd->execute(); |
|
|
$this->assertEquals(1, $result->count()); |
|
|
$this->assertEquals(1, $result->count()); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::REMOVE, $collection); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::REMOVE, $this->collection); |
|
|
$cmd |
|
|
$cmd |
|
|
->bindParam('condition', array('name' => 'insert')) |
|
|
->bindParam('condition', array('name' => 'insert')) |
|
|
->bindParam('safe', true); |
|
|
->bindParam('safe', true); |
|
|
$this->assertArrayHasKey('n', $cmd->execute()); |
|
|
$this->assertArrayHasKey('n', $cmd->execute()); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $collection); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection); |
|
|
$cmd->bindParam('condition', array('name' => 'insert'))->bindParam('fields', array()); |
|
|
$cmd->bindParam('condition', array('name' => 'insert'))->bindParam('fields', array()); |
|
|
$result = $cmd->execute(); |
|
|
$result = $cmd->execute(); |
|
|
$this->assertEquals(0, $result->count()); |
|
|
$this->assertEquals(0, $result->count()); |
|
@ -174,8 +169,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase |
|
|
*/ |
|
|
*/ |
|
|
public function testRemoveCommandNotAllParamsBinded() |
|
|
public function testRemoveCommandNotAllParamsBinded() |
|
|
{ |
|
|
{ |
|
|
$collection = $this->driver->getCollection('items'); |
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::REMOVE, $collection); |
|
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::REMOVE, $this->collection); |
|
|
$cmd->execute(); |
|
|
$cmd->execute(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|