modified tests for new DbDriver hierarchy
This commit is contained in:
@ -22,6 +22,8 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
private $driver;
|
||||
|
||||
private $collection;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->conf = array(
|
||||
@ -38,6 +40,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
||||
$db->authenticate($this->conf['username'], $this->conf['password']);
|
||||
$collection = 'items';
|
||||
$db->dropCollection($collection);
|
||||
$this->collection = $db->selectCollection($collection);
|
||||
}
|
||||
|
||||
public function testCommandFactory()
|
||||
@ -58,8 +61,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
||||
|
||||
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());
|
||||
$result = $cmd->execute();
|
||||
$this->assertEquals(0, $result->count());
|
||||
@ -71,22 +73,20 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
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->execute();
|
||||
}
|
||||
|
||||
public function testInsertCommand()
|
||||
{
|
||||
$collection = $this->driver->getCollection('items');
|
||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $collection);
|
||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection);
|
||||
$cmd
|
||||
->bindParam('data', array('name' => 'insert'))
|
||||
->bindParam('safe', true);
|
||||
$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());
|
||||
$result = $cmd->execute();
|
||||
$this->assertEquals(1, $result->count());
|
||||
@ -98,22 +98,19 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
public function testUpdateCommand()
|
||||
{
|
||||
$collection = $this->driver->getCollection('items');
|
||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $collection);
|
||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection);
|
||||
$cmd
|
||||
->bindParam('data', array('name' => 'insert'))
|
||||
->bindParam('safe', true);
|
||||
$this->assertArrayHasKey('n', $cmd->execute());
|
||||
|
||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::UPDATE, $collection);
|
||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::UPDATE, $this->collection);
|
||||
$cmd
|
||||
->bindParam('condition', array('name' => 'insert'))
|
||||
->bindParam('data', array('$set' => array('name' => 'update')))
|
||||
@ -121,7 +118,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
||||
->bindParam('safe', true);
|
||||
$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());
|
||||
$result = $cmd->execute();
|
||||
$this->assertEquals(0, $result->count());
|
||||
@ -136,33 +133,31 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
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->execute();
|
||||
}
|
||||
|
||||
public function testRemoveCommand()
|
||||
{
|
||||
$collection = $this->driver->getCollection('items');
|
||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $collection);
|
||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection);
|
||||
$cmd
|
||||
->bindParam('data', array('name' => 'insert'))
|
||||
->bindParam('safe', true);
|
||||
$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());
|
||||
$result = $cmd->execute();
|
||||
$this->assertEquals(1, $result->count());
|
||||
|
||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::REMOVE, $collection);
|
||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::REMOVE, $this->collection);
|
||||
$cmd
|
||||
->bindParam('condition', array('name' => 'insert'))
|
||||
->bindParam('safe', true);
|
||||
$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());
|
||||
$result = $cmd->execute();
|
||||
$this->assertEquals(0, $result->count());
|
||||
@ -174,8 +169,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testRemoveCommandNotAllParamsBinded()
|
||||
{
|
||||
$collection = $this->driver->getCollection('items');
|
||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::REMOVE, $collection);
|
||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::REMOVE, $this->collection);
|
||||
$cmd->execute();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user