MongoDBTest.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Alcaeus\MongoDbAdapter\Tests;
  3. /**
  4. * @author alcaeus <alcaeus@alcaeus.org>
  5. */
  6. class MongoDBTest extends TestCase
  7. {
  8. public function testGetCollection()
  9. {
  10. $db = $this->getDatabase();
  11. $collection = $db->selectCollection('test');
  12. $this->assertInstanceOf('MongoCollection', $collection);
  13. $this->assertSame('mongo-php-adapter.test', (string) $collection);
  14. }
  15. public function testGetCollectionProperty()
  16. {
  17. $db = $this->getDatabase();
  18. $collection = $db->test;
  19. $this->assertInstanceOf('MongoCollection', $collection);
  20. $this->assertSame('mongo-php-adapter.test', (string) $collection);
  21. }
  22. public function testCommand()
  23. {
  24. $db = $this->getDatabase();
  25. $this->assertEquals(['ok' => 1], $db->command(['ping' => 1], [], $hash));
  26. }
  27. public function testCommandError()
  28. {
  29. $db = $this->getDatabase();
  30. $expected = [
  31. 'ok' => 0,
  32. 'errmsg' => 'listDatabases may only be run against the admin database.',
  33. 'code' => 13,
  34. ];
  35. $this->assertEquals($expected, $db->command(['listDatabases' => 1], [], $hash));
  36. }
  37. /**
  38. * @return \MongoDB
  39. */
  40. protected function getDatabase()
  41. {
  42. $client = new \MongoClient();
  43. return $client->selectDB('mongo-php-adapter');
  44. }
  45. }