|
|
@ -67,8 +67,8 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase |
|
|
|
$collection = 'items'; |
|
|
|
$db->dropCollection($collection); |
|
|
|
$collection = $db->selectCollection($collection); |
|
|
|
foreach($data as $document) { |
|
|
|
$collection->insert($document); |
|
|
|
foreach ($data as $document) { |
|
|
|
$collection->insert($document); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -117,7 +117,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase |
|
|
|
if (!defined('DEBUG')) { |
|
|
|
define('DEBUG', false); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$mongo = new MongoDriver($this->conf); |
|
|
|
$this->assertEquals(1, $mongo->find('items', array('name' => 'bread'))->numRows()); |
|
|
|
$this->assertEquals(2, $mongo->find('items', array('name' => 'eggs'))->numRows()); |
|
|
@ -131,7 +131,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase |
|
|
|
$this->assertEquals(3, $mongo->find('items', array('price' => array('$lt' => 3.5)))->numRows()); |
|
|
|
$data = $mongo->find('items', array('price' => array('$lt' => 3.5))); |
|
|
|
$count = 0; |
|
|
|
while($row = $data->fetch(Db::FETCH_ASSOC)) { |
|
|
|
while ($row = $data->fetch(Db::FETCH_ASSOC)) { |
|
|
|
$count++; |
|
|
|
$this->assertLessThan(3.5, $row['price']); |
|
|
|
} |
|
|
@ -173,7 +173,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase |
|
|
|
$data->order(array('name' => -1)); |
|
|
|
$data->skip(3); |
|
|
|
$data->limit(1); |
|
|
|
while($row = $data->fetch()) { |
|
|
|
while ($row = $data->fetch()) { |
|
|
|
$this->assertEquals('fdsbssc', $row->name); |
|
|
|
} |
|
|
|
} |
|
|
@ -252,12 +252,35 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase |
|
|
|
* @runInSeparateProcess |
|
|
|
* @group Mongo |
|
|
|
*/ |
|
|
|
public function testBatchInsert() |
|
|
|
{ |
|
|
|
if (!defined('DEBUG')) { |
|
|
|
define('DEBUG', false); |
|
|
|
} |
|
|
|
|
|
|
|
$data = array( |
|
|
|
array('name' => 'first object'), |
|
|
|
array('name' => 'second object'), |
|
|
|
array('name' => 'equal object'), |
|
|
|
array('name' => 'equal object') |
|
|
|
); |
|
|
|
$mongo = new MongoDriver($this->conf); |
|
|
|
$mongo->insert('items', $data, true); |
|
|
|
$this->assertEquals(1, $mongo->find('items', array('name' => 'first object'))->numRows()); |
|
|
|
$this->assertEquals(1, $mongo->find('items', array('name' => 'second object'))->numRows()); |
|
|
|
$this->assertEquals(2, $mongo->find('items', array('name' => 'equal object'))->numRows()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* @runInSeparateProcess |
|
|
|
* @group Mongo |
|
|
|
*/ |
|
|
|
public function testGetInsertId() |
|
|
|
{ |
|
|
|
if (!defined('DEBUG')) { |
|
|
|
define('DEBUG', false); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$mongo = new MongoDriver($this->conf); |
|
|
|
$this->assertEquals(0, $mongo->getInsertId()); |
|
|
|
$this->assertEquals(1, $mongo->find('items', array('name' => 'bread'))->numRows()); |
|
|
@ -337,7 +360,7 @@ class MongoDriverTest extends PHPUnit_Framework_TestCase |
|
|
|
define('DEBUG', false); |
|
|
|
} |
|
|
|
$mongo = new MongoDriver($this->conf); |
|
|
|
$result = $mongo->command('items', array('distinct' =>'items', 'key' => 'name')); |
|
|
|
$result = $mongo->command('items', array('distinct' => 'items', 'key' => 'name')); |
|
|
|
$this->assertEquals(4, count($result->fetch(DB::FETCH_ASSOC))); |
|
|
|
} |
|
|
|
} |