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.

63 lines
2.1 KiB

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