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.

62 lines
2.0 KiB

13 years ago
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. * @expectedExceptionMessage Trying to get property of non-object
  20. */
  21. public function testConnectNoParams()
  22. {
  23. Db::connect();
  24. }
  25. /**
  26. * @expectedException Exception
  27. * @expectedExceptionMessage Connection parameters must be an array
  28. */
  29. public function testConnectConfigNotArray()
  30. {
  31. Db::connect('name', 'config');
  32. }
  33. public function testConnectGlobalConfig()
  34. {
  35. $conf = array('hostname' => 'localhost', 'driver' => 'MySQLiDriverGlobalConfMock', 'database' => 'db', 'username' => 'test', 'password' => '1234');
  36. $this->getMockForAbstractClass('DbDriver', array(), 'MySQLiDriverGlobalConfMock', false);
  37. Config::set('Db', array('global' =>$conf));
  38. Db::connect('global');
  39. }
  40. public function testConnectWithConfigParam()
  41. {
  42. $conf = array('hostname' => 'localhost', 'driver' => 'MySQLiDriverMock', 'database' => 'db', 'username' => 'test', 'password' => '1234');
  43. $this->getMockForAbstractClass('DbDriver', array(), 'MySQLiDriverMock', false);
  44. $driver = Db::connect('mysql', $conf);
  45. $this->assertInstanceOf('DbDriver', $driver);
  46. }
  47. /**
  48. * @expectedException Exception
  49. * @expectedExceptionMessage Database driver must extends DbDriver
  50. */
  51. public function testConnectWithWrongDriver()
  52. {
  53. $this->getMock('NotDbDriver', array(), array(), 'NoDbDriverMock');
  54. $driver = Db::connect('nodb', array('hostname' => 'localhost', 'driver' => 'NoDbDriverMock'));
  55. }
  56. }