Browse Source

updated tests for MongoDbCommand with count command

master
Anton Grebnev 13 years ago
parent
commit
f728e6d6a2
  1. 40
      tests/model/MongoDbCommandTest.php

40
tests/model/MongoDbCommandTest.php

@ -99,12 +99,34 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
/**
* @group Mongo
*/
public function testFindCommandNotAllParamsBinded()
public function testCountCommand()
{
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection);
$cmd->bindParam('condition', array('name' => 'bread'));
$this->setExpectedException('GeneralException', 'FindMongoCommand error. Bind all required params first');
$count_cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COUNT, $this->collection);
$count_cmd->bindParam('condition', array('name' => 'bread'));
$count_result = $count_cmd->execute();
$find_cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection);
$find_cmd->bindParam('condition', array('name' => 'bread'))->bindParam('fields', array());
$find_result = $find_cmd->execute();
$this->assertEquals(0, $count_result);
$this->assertEquals($count_result, $find_result->count());
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection);
$cmd
->bindParam('data', array('name' => 'insert'))
->bindParam('safe', true);
$cmd->execute();
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection);
$cmd
->bindParam('data', array('name' => 'insert'))
->bindParam('safe', true);
$cmd->execute();
$count_cmd->bindParam('condition', array('name' => 'insert'));
$this->assertEquals(2, $count_cmd->execute());
$find_cmd->bindParam('condition', array('name' => 'insert'));
$this->assertEquals($find_cmd->execute()->count(), $count_cmd->execute());
}
/**
@ -305,6 +327,14 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
*/
public function testToString()
{
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COUNT, new CollectionMock());
$cmd->bindParam('condition', array());
$this->assertStringStartsWith('Collection: CollectionMock', $cmd->__toString());
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, new CollectionMock());
$cmd->bindParam('condition', array());
$this->assertStringStartsWith('Collection: CollectionMock', $cmd->__toString());
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COMMAND, new CollectionMock());
$this->assertSame('Command properties not set', $cmd->__toString());
$cmd->bindParam('command', array());
@ -326,8 +356,6 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
->bindParam('safe', true);
$this->assertContains('Bulk insert: TRUE', $cmd->__toString());
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection);
$this->assertSame('Command properties not set', $cmd->__toString());
$cmd->bindParam('condition', array('name' => 'insert'))->bindParam('fields', array());
$this->assertStringStartsWith('Collection: ', $cmd->__toString());

Loading…
Cancel
Save