DatabaseTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace yiiunit\extensions\mongodb;
  3. use yii\mongodb\Collection;
  4. use yii\mongodb\Command;
  5. use yii\mongodb\file\Collection as FileCollection;
  6. class DatabaseTest extends TestCase
  7. {
  8. protected function tearDown()
  9. {
  10. $this->dropCollection('customer');
  11. $this->dropFileCollection('testfs');
  12. parent::tearDown();
  13. }
  14. // Tests :
  15. public function testGetCollection()
  16. {
  17. $database = $this->getConnection()->getDatabase();
  18. $collection = $database->getCollection('customer');
  19. $this->assertTrue($collection instanceof Collection);
  20. $this->assertSame($database, $collection->database);
  21. $collection2 = $database->getCollection('customer');
  22. $this->assertSame($collection, $collection2);
  23. $collectionRefreshed = $database->getCollection('customer', true);
  24. $this->assertNotSame($collection, $collectionRefreshed);
  25. }
  26. public function testGetFileCollection()
  27. {
  28. $database = $this->getConnection()->getDatabase();
  29. $collection = $database->getFileCollection('testfs');
  30. $this->assertTrue($collection instanceof FileCollection);
  31. $this->assertSame($database, $collection->database);
  32. $collection2 = $database->getFileCollection('testfs');
  33. $this->assertSame($collection, $collection2);
  34. $collectionRefreshed = $database->getFileCollection('testfs', true);
  35. $this->assertNotSame($collection, $collectionRefreshed);
  36. }
  37. public function testCreateCommand()
  38. {
  39. $database = $this->getConnection()->getDatabase();
  40. $command = $database->createCommand();
  41. $this->assertTrue($command instanceof Command);
  42. $this->assertEquals($database->name, $command->databaseName);
  43. }
  44. public function testCreateCollection()
  45. {
  46. $database = $this->getConnection()->getDatabase();
  47. $this->assertTrue($database->createCollection('customer'));
  48. }
  49. }