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.

64 lines
1.7 KiB

  1. <?php
  2. /*
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage UnitTests
  7. * @since 2011-11-10
  8. *
  9. * Unit tests for MongoDriver class
  10. */
  11. require_once dirname(__FILE__) . '/../../model/DbDriver.php';
  12. require_once dirname(__FILE__) . '/../../model/NoSqlDbDriver.php';
  13. require_once dirname(__FILE__) . '/../../model/MongoDriver.php';
  14. class MongoDriverTest extends PHPUnit_Framework_TestCase
  15. {
  16. private $conf = array();
  17. public function setUp()
  18. {
  19. $this->conf = array(
  20. 'hostname' => 'localhost',
  21. 'database' => 'test',
  22. 'username' => 'test',
  23. 'password' => '1234',
  24. 'port' => 27017
  25. );
  26. }
  27. /**
  28. * @expectedException Exception
  29. * @expectedExceptionMessage Configuration must have a "hostname".
  30. */
  31. public function testGetConnectionNoHostname()
  32. {
  33. unset($this->conf['hostname']);
  34. $mongo = new MongoDriver($this->conf);
  35. $mongo->getConnection();
  36. }
  37. /**
  38. * @expectedException MongoConnectionException
  39. * @expectedExceptionMessage Couldn't authenticate with database
  40. */
  41. public function testGetConnectionWrongPassword()
  42. {
  43. $this->conf['password'] = 'nopass';
  44. $mongo = new MongoDriver($this->conf);
  45. $this->assertInstanceOf('Mongo', $mongo->getConnection());
  46. }
  47. public function testGetConnection()
  48. {
  49. $mongo = new MongoDriver($this->conf);
  50. $this->assertFalse($mongo->isConnected());
  51. $this->assertInstanceOf('Mongo', $mongo->getConnection());
  52. $this->assertTrue($mongo->isConnected());
  53. $mongo->disconnect();
  54. $this->assertFalse($mongo->isConnected());
  55. }
  56. }