added methods to MongoDriver for custom commands, findAndModify, count
This commit is contained in:
@ -84,7 +84,7 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
||||
->bindParam('condition', array('name' => 'insert'))
|
||||
->bindParam('fields', array())
|
||||
->bindParam('multiple', false);
|
||||
|
||||
|
||||
$result = $cmd->execute();
|
||||
$this->assertEquals('insert', $result['name']);
|
||||
}
|
||||
@ -199,4 +199,26 @@ class MongoDbCommandTest extends PHPUnit_Framework_TestCase
|
||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::REMOVE, $this->collection);
|
||||
$cmd->execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage CommandMongoCommand error. Bind all required params first.
|
||||
*/
|
||||
public function testCommandCommandNotAllParamsBinded()
|
||||
{
|
||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COMMAND, $this->collection);
|
||||
$cmd->execute();
|
||||
}
|
||||
|
||||
public function testCommandCommandNotMongoDb()
|
||||
{
|
||||
$cmd = MongoCommandBuilder::factory(MongoCommandBuilder::COMMAND, new CollectionMock());
|
||||
$cmd->bindParam('command', array());
|
||||
$this->assertFalse($cmd->execute());
|
||||
}
|
||||
}
|
||||
|
||||
class CollectionMock
|
||||
{
|
||||
public $db = array();
|
||||
}
|
||||
|
@ -176,6 +176,20 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testCount()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
define('DEBUG', false);
|
||||
}
|
||||
$mongo = new MongoDriver($this->conf);
|
||||
$this->assertEquals(5, $mongo->count('items'));
|
||||
$this->assertEquals(2, $mongo->count('items', array('name' => 'eggs')));
|
||||
$this->assertEquals(1, $mongo->count('items', array('name' => 'eggs'), 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testGet()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
@ -279,4 +293,37 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(1, $mongo->update('items', array('$set' => array('price' => 200, 'date' => 'today')), array('name' => 'ball'), true, true));
|
||||
$this->assertEquals('today', $mongo->get('items', array('name' => 'ball'))->fetch()->date);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testFindAndModify()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
define('DEBUG', false);
|
||||
}
|
||||
|
||||
$mongo = new MongoDriver($this->conf);
|
||||
|
||||
$this->assertEquals(10, $mongo->get('items', array('name' => 'bread'))->fetch()->quantity);
|
||||
$result = $mongo->findAndModify('items', array('name' => 'bread'), array('$set' => array('quantity' => 20)));
|
||||
$this->assertEquals(10, $result->fetch()->quantity);
|
||||
$this->assertEquals(20, $mongo->get('items', array('name' => 'bread'))->fetch()->quantity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testCommand()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
define('DEBUG', false);
|
||||
}
|
||||
$mongo = new MongoDriver($this->conf);
|
||||
$result = $mongo->command('items', array('distinct' =>'items', 'key' => 'name'));
|
||||
$this->assertEquals(4, count($result->fetch(DB::FETCH_ASSOC)));
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -101,6 +101,18 @@ class MongoModelTest extends PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testCount()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
define('DEBUG', false);
|
||||
}
|
||||
$this->assertEquals(5, $this->model->count());
|
||||
$this->assertEquals(2, $this->model->count(array('name' => 'eggs')));
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testFetch()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
|
Reference in New Issue
Block a user