added Order, Limit, Skip methods to MongoStatement
This commit is contained in:
@ -65,9 +65,9 @@ class DbStatementTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(11, $result[0]->one);
|
||||
$this->assertEquals(32, $result[2]->two);
|
||||
|
||||
reset($this->testData);
|
||||
$result = $this->stmt->fetchPairs();
|
||||
$this->assertEquals(31, $result['one']);
|
||||
// reset($this->testData);
|
||||
// $result = $this->stmt->fetchPairs();
|
||||
// $this->assertEquals(31, $result['one']);
|
||||
}
|
||||
|
||||
public function dbStatementFetch($style)
|
||||
|
@ -105,7 +105,6 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($mongo->isConnected());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
@ -139,6 +138,44 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testOrderSkipLimit()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
define('DEBUG', false);
|
||||
}
|
||||
|
||||
$mongo = new MongoDriver($this->conf);
|
||||
|
||||
$count = $mongo->find('items', array())->numRows();
|
||||
|
||||
$this->assertEquals(1, $mongo->find('items', array('name' => 'bread'))->numRows());
|
||||
$this->assertEquals(2, $mongo->find('items', array('name' => 'eggs'))->numRows());
|
||||
$mongo->insert('items', array('name' => 'fdsbssc'));
|
||||
$mongo->insert('items', array('name' => 'boc'));
|
||||
$mongo->insert('items', array('name' => 'abc'));
|
||||
$mongo->insert('items', array('name' => 'vcxxc'));
|
||||
$mongo->insert('items', array('name' => 'abbc'));
|
||||
$mongo->insert('items', array('name' => 'dsbssc'));
|
||||
$mongo->insert('items', array('name' => 'bssc'));
|
||||
|
||||
$data = $mongo->find('items', array());
|
||||
$this->assertEquals($count + 7, $data->numRows());
|
||||
$data->order(array('name' => 1));
|
||||
$this->assertEquals('abbc', $data->fetch()->name);
|
||||
$this->assertEquals('abc', $data->fetch()->name);
|
||||
$this->assertEquals('boc', $data->fetch()->name);
|
||||
$data = $mongo->find('items', array());
|
||||
$data->order(array('name' => -1));
|
||||
$data->skip(3);
|
||||
$data->limit(1);
|
||||
while($row = $data->fetch()) {
|
||||
$this->assertEquals('fdsbssc', $row->name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testGet()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
|
@ -271,7 +271,84 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
|
||||
->will($this->returnValue(array('some' => 'val')));
|
||||
|
||||
$this->stmt->execute();
|
||||
$result = $this->stmt->fetch(222);
|
||||
$this->stmt->fetch(222);
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
*/
|
||||
public function testSkipOrderLimit()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
define('DEBUG', true);
|
||||
}
|
||||
$this->setDriverGetConnectionMethod()->setRequestForFetch();
|
||||
|
||||
$this->stmt->execute();
|
||||
$this->assertInstanceOf('MongoStatement', $this->stmt->order(array('id' => 1)));
|
||||
|
||||
$this->stmt->fetch();
|
||||
$this->stmt->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage MongoStatement error. Impossible order results of opened cursor
|
||||
*/
|
||||
public function testOrderException()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
define('DEBUG', true);
|
||||
}
|
||||
$this->setDriverGetConnectionMethod();
|
||||
$this->request
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->will($this->returnValue(array('some' => 'val')));
|
||||
|
||||
$this->stmt->execute();
|
||||
$this->stmt->order(array('id' => 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage MongoStatement error. Impossible skip results of opened cursor
|
||||
*/
|
||||
public function testSkipException()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
define('DEBUG', true);
|
||||
}
|
||||
$this->setDriverGetConnectionMethod();
|
||||
$this->request
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->will($this->returnValue(array('some' => 'val')));
|
||||
|
||||
$this->stmt->execute();
|
||||
$this->stmt->skip(array('id' => 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @expectedException Exception
|
||||
* @expectedExceptionMessage MongoStatement error. Impossible limit results of opened cursor
|
||||
*/
|
||||
public function testLimitException()
|
||||
{
|
||||
if (!defined('DEBUG')) {
|
||||
define('DEBUG', true);
|
||||
}
|
||||
$this->setDriverGetConnectionMethod();
|
||||
$this->request
|
||||
->expects($this->once())
|
||||
->method('execute')
|
||||
->will($this->returnValue(array('some' => 'val')));
|
||||
|
||||
$this->stmt->execute();
|
||||
$this->stmt->limit(array('id' => 1));
|
||||
}
|
||||
|
||||
private function setDriverGetConnectionMethod()
|
||||
@ -308,12 +385,21 @@ class MongoStatementTest extends PHPUnit_Framework_TestCase
|
||||
public function setRequestForFetch()
|
||||
{
|
||||
$resultMock = $this->getMockBuilder('MongoCursor')
|
||||
->setMethods(array('count', 'getNext'))
|
||||
->setMethods(array('count', 'getNext', 'limit', 'sort', 'skip'))
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$resultMock
|
||||
->expects($this->any())
|
||||
->method('limit');
|
||||
$resultMock
|
||||
->expects($this->any())
|
||||
->method('sort');
|
||||
$resultMock
|
||||
->expects($this->any())
|
||||
->method('skip');
|
||||
$resultMock
|
||||
->expects($this->any())
|
||||
->method('count')
|
||||
->will($this->returnValue(10));
|
||||
$resultMock
|
||||
|
Reference in New Issue
Block a user