|
|
@ -90,14 +90,11 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase |
|
|
|
$this->assertEquals('insert', $result['name']); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @expectedException GeneralException |
|
|
|
* @expectedExceptionMessage FindMongoCommand error. Bind all required params first. |
|
|
|
*/ |
|
|
|
public function testFindCommandNotAllParamsBinded() |
|
|
|
{ |
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::FIND, $this->collection); |
|
|
|
$cmd->bindParam('condition', array('name' => 'bread')); |
|
|
|
$this->setExpectedException('GeneralException', 'FindMongoCommand error. Bind all required params first'); |
|
|
|
$cmd->execute(); |
|
|
|
} |
|
|
|
|
|
|
@ -120,13 +117,10 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase |
|
|
|
$this->assertEquals(1, $result->count()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @expectedException GeneralException |
|
|
|
* @expectedExceptionMessage InsertMongoCommand error. Bind all required params first. |
|
|
|
*/ |
|
|
|
public function testInsertCommandNotAllParamsBinded() |
|
|
|
{ |
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection); |
|
|
|
$this->setExpectedException('GeneralException', 'InsertMongoCommand error. Bind all required params first'); |
|
|
|
$cmd->execute(); |
|
|
|
} |
|
|
|
|
|
|
@ -155,14 +149,11 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase |
|
|
|
$this->assertEquals(1, $result->count()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @expectedException GeneralException |
|
|
|
* @expectedExceptionMessage UpdateMongoCommand error. Bind all required params first. |
|
|
|
*/ |
|
|
|
public function testUpdateCommandNotAllParamsBinded() |
|
|
|
{ |
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::UPDATE, $this->collection); |
|
|
|
$cmd->bindParam('data', array('name' => 'bread')); |
|
|
|
$this->setExpectedException('GeneralException', 'UpdateMongoCommand error. Bind all required params first'); |
|
|
|
$cmd->execute(); |
|
|
|
} |
|
|
|
|
|
|
@ -191,23 +182,17 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase |
|
|
|
$this->assertEquals(0, $result->count()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @expectedException GeneralException |
|
|
|
* @expectedExceptionMessage RemoveMongoCommand error. Bind all required params first. |
|
|
|
*/ |
|
|
|
public function testRemoveCommandNotAllParamsBinded() |
|
|
|
{ |
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::REMOVE, $this->collection); |
|
|
|
$this->setExpectedException('GeneralException', 'RemoveMongoCommand error. Bind all required params first.'); |
|
|
|
$cmd->execute(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @expectedException GeneralException |
|
|
|
* @expectedExceptionMessage CommandMongoCommand error. Bind all required params first. |
|
|
|
*/ |
|
|
|
public function testCommandCommandNotAllParamsBinded() |
|
|
|
{ |
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COMMAND, $this->collection); |
|
|
|
$this->setExpectedException('GeneralException', 'CommandMongoCommand error. Bind all required params first'); |
|
|
|
$cmd->execute(); |
|
|
|
} |
|
|
|
|
|
|
@ -217,9 +202,69 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase |
|
|
|
$cmd->bindParam('command', array()); |
|
|
|
$this->assertFalse($cmd->execute()); |
|
|
|
} |
|
|
|
|
|
|
|
public function testCommandCommand() |
|
|
|
{ |
|
|
|
$col = new CollectionMock(); |
|
|
|
$col->db = $this->getMock('MongoDb', array('command'), array(), 'SomeMongoMock', false); |
|
|
|
$col->db |
|
|
|
->expects($this->once()) |
|
|
|
->method('command') |
|
|
|
->will($this->returnValue(true)); |
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COMMAND, $col); |
|
|
|
$cmd->bindParam('command', array()); |
|
|
|
$this->assertTrue($cmd->execute()); |
|
|
|
} |
|
|
|
|
|
|
|
public function testToStringParamsNotSet() |
|
|
|
{ |
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COMMAND, new CollectionMock()); |
|
|
|
$this->assertSame('Command properties not set', $cmd->__toString()); |
|
|
|
} |
|
|
|
|
|
|
|
public function testToString() |
|
|
|
{ |
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COMMAND, new CollectionMock()); |
|
|
|
$this->assertSame('Command properties not set', $cmd->__toString()); |
|
|
|
$cmd->bindParam('command', array()); |
|
|
|
$this->assertStringStartsWith('Collection: CollectionMock', $cmd->__toString()); |
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::INSERT, $this->collection); |
|
|
|
$this->assertSame('Command properties not set', $cmd->__toString()); |
|
|
|
$cmd |
|
|
|
->bindParam('data', array('name' => 'insert')) |
|
|
|
->bindParam('safe', true); |
|
|
|
$this->assertStringStartsWith('Collection: ', $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()); |
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::REMOVE, $this->collection); |
|
|
|
$this->assertSame('Command properties not set', $cmd->__toString()); |
|
|
|
$cmd |
|
|
|
->bindParam('condition', array('name' => 'insert')) |
|
|
|
->bindParam('safe', true); |
|
|
|
$this->assertStringStartsWith('Collection: ', $cmd->__toString()); |
|
|
|
|
|
|
|
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::UPDATE, $this->collection); |
|
|
|
$this->assertSame('Command properties not set', $cmd->__toString()); |
|
|
|
$cmd |
|
|
|
->bindParam('condition', array('name' => 'insert')) |
|
|
|
->bindParam('data', array('$set' => array('name' => 'update'))) |
|
|
|
->bindParam('upsert', false) |
|
|
|
->bindParam('safe', true); |
|
|
|
$this->assertStringStartsWith('Collection: ', $cmd->__toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
class CollectionMock |
|
|
|
{ |
|
|
|
public $db = array(); |
|
|
|
|
|
|
|
public function __toString() |
|
|
|
{ |
|
|
|
return 'CollectionMock'; |
|
|
|
} |
|
|
|
} |