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.

58 lines
1.7 KiB

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/Db.php';
  14. class DbTest extends PHPUnit_Framework_TestCase
  15. {
  16. /**
  17. * @expectedException Exception
  18. */
  19. public function testConnectNoParams()
  20. {
  21. Db::connect();
  22. }
  23. /**
  24. * @expectedException Exception
  25. * @expectedExceptionMessage Connection parameters must be an array
  26. */
  27. public function testConnectConfigNotArray()
  28. {
  29. Db::connect('name', 'config');
  30. }
  31. public function testConnectGlobalConfig()
  32. {
  33. $this->getMock('DbDriver', array(), array(), 'MySQLiDriverGlobalConfMock');
  34. Config::set('Db', array('global' =>array('hostname' => 'localhost', 'driver' => 'MySQLiDriverGlobalConfMock')));
  35. Db::connect('global');
  36. }
  37. public function testConnectWithConfigParam()
  38. {
  39. $this->getMock('DbDriver', array(), array(), 'MySQLiDriverMock');
  40. $driver = Db::connect('mysql', array('hostname' => 'localhost', 'driver' => 'MySQLiDriverMock'));
  41. $this->assertInstanceOf('DbDriver', $driver);
  42. }
  43. /**
  44. * @expectedException Exception
  45. * @expectedExceptionMessage Database driver must extends DbDriver
  46. */
  47. public function testConnectWithWrongDriver()
  48. {
  49. $this->getMock('NotDbDriver', array(), array(), 'NoDbDriverMock');
  50. $driver = Db::connect('nodb', array('hostname' => 'localhost', 'driver' => 'NoDbDriverMock'));
  51. }
  52. }