You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.9 KiB
70 lines
1.9 KiB
11 years ago
|
<?php
|
||
|
|
||
11 years ago
|
namespace yiiunit\extensions\mongodb;
|
||
11 years ago
|
|
||
11 years ago
|
use yii\mongodb\Collection;
|
||
|
use yii\mongodb\file\Collection as FileCollection;
|
||
11 years ago
|
|
||
|
/**
|
||
|
* @group mongo
|
||
|
*/
|
||
11 years ago
|
class DatabaseTest extends MongoDbTestCase
|
||
11 years ago
|
{
|
||
|
protected function tearDown()
|
||
|
{
|
||
|
$this->dropCollection('customer');
|
||
11 years ago
|
$this->dropFileCollection('testfs');
|
||
11 years ago
|
parent::tearDown();
|
||
|
}
|
||
|
|
||
|
// Tests :
|
||
|
|
||
|
public function testGetCollection()
|
||
|
{
|
||
|
$database = $connection = $this->getConnection()->getDatabase();
|
||
|
|
||
|
$collection = $database->getCollection('customer');
|
||
|
$this->assertTrue($collection instanceof Collection);
|
||
|
$this->assertTrue($collection->mongoCollection instanceof \MongoCollection);
|
||
|
|
||
|
$collection2 = $database->getCollection('customer');
|
||
|
$this->assertTrue($collection === $collection2);
|
||
|
|
||
|
$collectionRefreshed = $database->getCollection('customer', true);
|
||
|
$this->assertFalse($collection === $collectionRefreshed);
|
||
|
}
|
||
11 years ago
|
|
||
11 years ago
|
public function testGetFileCollection()
|
||
|
{
|
||
|
$database = $connection = $this->getConnection()->getDatabase();
|
||
|
|
||
|
$collection = $database->getFileCollection('testfs');
|
||
|
$this->assertTrue($collection instanceof FileCollection);
|
||
|
$this->assertTrue($collection->mongoCollection instanceof \MongoGridFS);
|
||
|
|
||
|
$collection2 = $database->getFileCollection('testfs');
|
||
|
$this->assertTrue($collection === $collection2);
|
||
|
|
||
|
$collectionRefreshed = $database->getFileCollection('testfs', true);
|
||
|
$this->assertFalse($collection === $collectionRefreshed);
|
||
|
}
|
||
|
|
||
11 years ago
|
public function testExecuteCommand()
|
||
11 years ago
|
{
|
||
|
$database = $connection = $this->getConnection()->getDatabase();
|
||
|
|
||
11 years ago
|
$result = $database->executeCommand([
|
||
11 years ago
|
'distinct' => 'customer',
|
||
|
'key' => 'name'
|
||
|
]);
|
||
|
$this->assertTrue(array_key_exists('ok', $result));
|
||
|
$this->assertTrue(array_key_exists('values', $result));
|
||
|
}
|
||
11 years ago
|
|
||
|
public function testCreateCollection()
|
||
|
{
|
||
|
$database = $connection = $this->getConnection()->getDatabase();
|
||
|
$collection = $database->createCollection('customer');
|
||
|
$this->assertTrue($collection instanceof \MongoCollection);
|
||
|
}
|
||
11 years ago
|
}
|