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
			| 
											12 years ago
										 | <?php
 | ||
|  | 
 | ||
| 
											12 years ago
										 | namespace yiiunit\extensions\mongodb;
 | ||
| 
											12 years ago
										 | 
 | ||
| 
											12 years ago
										 | use yii\mongodb\Collection;
 | ||
|  | use yii\mongodb\file\Collection as FileCollection;
 | ||
| 
											12 years ago
										 | 
 | ||
|  | /**
 | ||
|  |  * @group mongo
 | ||
|  |  */
 | ||
| 
											12 years ago
										 | class DatabaseTest extends MongoDbTestCase
 | ||
| 
											12 years ago
										 | {
 | ||
|  | 	protected function tearDown()
 | ||
|  | 	{
 | ||
|  | 		$this->dropCollection('customer');
 | ||
| 
											12 years ago
										 | 		$this->dropFileCollection('testfs');
 | ||
| 
											12 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);
 | ||
|  | 	}
 | ||
| 
											12 years ago
										 | 
 | ||
| 
											12 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);
 | ||
|  | 	}
 | ||
|  | 
 | ||
| 
											12 years ago
										 | 	public function testExecuteCommand()
 | ||
| 
											12 years ago
										 | 	{
 | ||
|  | 		$database = $connection = $this->getConnection()->getDatabase();
 | ||
|  | 
 | ||
| 
											12 years ago
										 | 		$result = $database->executeCommand([
 | ||
| 
											12 years ago
										 | 			'distinct' => 'customer',
 | ||
|  | 			'key' => 'name'
 | ||
|  | 		]);
 | ||
|  | 		$this->assertTrue(array_key_exists('ok', $result));
 | ||
|  | 		$this->assertTrue(array_key_exists('values', $result));
 | ||
|  | 	}
 | ||
| 
											12 years ago
										 | 
 | ||
|  | 	public function testCreateCollection()
 | ||
|  | 	{
 | ||
|  | 		$database = $connection = $this->getConnection()->getDatabase();
 | ||
|  | 		$collection = $database->createCollection('customer');
 | ||
|  | 		$this->assertTrue($collection instanceof \MongoCollection);
 | ||
|  | 	}
 | ||
| 
											12 years ago
										 | }
 |