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.

61 lines
1.9 KiB

13 years ago
13 years ago
13 years ago
13 years ago
  1. <?php
  2. /*
  3. * @copyright NetMonsters <team@netmonsters.ru>
  4. * @link http://netmonsters.ru
  5. * @package Majestic
  6. * @subpackage UnitTests
  7. * @since 2011-11-1
  8. *
  9. * Unit tests for Db class
  10. */
  11. require_once dirname(__FILE__) . '/../../Registry.php';
  12. require_once dirname(__FILE__) . '/../../Config.php';
  13. require_once dirname(__FILE__) . '/../../model/DbDriver.php';
  14. require_once dirname(__FILE__) . '/../../model/Db.php';
  15. class DbTest extends PHPUnit_Framework_TestCase
  16. {
  17. /**
  18. * @expectedException Exception
  19. */
  20. public function testConnectNoParams()
  21. {
  22. Db::connect();
  23. }
  24. /**
  25. * @expectedException Exception
  26. * @expectedExceptionMessage Connection parameters must be an array
  27. */
  28. public function testConnectConfigNotArray()
  29. {
  30. Db::connect('name', 'config');
  31. }
  32. public function testConnectGlobalConfig()
  33. {
  34. $conf = array('hostname' => 'localhost', 'driver' => 'MySQLiDriverGlobalConfMock', 'database' => 'db', 'username' => 'test', 'password' => '1234');
  35. $this->getMockForAbstractClass('DbDriver', array(), 'MySQLiDriverGlobalConfMock', false);
  36. Config::set('Db', array('global' =>$conf));
  37. Db::connect('global');
  38. }
  39. public function testConnectWithConfigParam()
  40. {
  41. $conf = array('hostname' => 'localhost', 'driver' => 'MySQLiDriverMock', 'database' => 'db', 'username' => 'test', 'password' => '1234');
  42. $this->getMockForAbstractClass('DbDriver', array(), 'MySQLiDriverMock', false);
  43. $driver = Db::connect('mysql', $conf);
  44. $this->assertInstanceOf('DbDriver', $driver);
  45. }
  46. /**
  47. * @expectedException Exception
  48. * @expectedExceptionMessage Database driver must extends DbDriver
  49. */
  50. public function testConnectWithWrongDriver()
  51. {
  52. $this->getMock('NotDbDriver', array(), array(), 'NoDbDriverMock');
  53. $driver = Db::connect('nodb', array('hostname' => 'localhost', 'driver' => 'NoDbDriverMock'));
  54. }
  55. }