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