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.

55 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
  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. public function testConnectGlobalConfig()
  30. {
  31. $conf = array('hostname' => 'localhost', 'driver' => 'MySQLiDriverGlobalConfMock', 'database' => 'db', 'username' => 'test', 'password' => '1234');
  32. $this->getMockForAbstractClass('DbDriver', array(), 'MySQLiDriverGlobalConfMock', false);
  33. Config::set('Db', array('global' =>$conf));
  34. $driver = Db::connect('global');
  35. $this->assertInstanceOf('DbDriver', $driver);
  36. }
  37. public function testConnectWithConfigParam()
  38. {
  39. $conf = array('hostname' => 'localhost', 'driver' => 'MySQLiDriverMock', 'database' => 'db', 'username' => 'test', 'password' => '1234');
  40. $this->getMockForAbstractClass('DbDriver', array(), 'MySQLiDriverMock', false);
  41. $driver = Db::connect('mysql', $conf);
  42. $this->assertInstanceOf('DbDriver', $driver);
  43. }
  44. public function testConnectWithWrongDriver()
  45. {
  46. $this->getMock('NotDbDriver', array(), array(), 'NoDbDriverMock');
  47. $this->setExpectedException('InitializationException', 'Database driver must extends DbDriver');
  48. $driver = Db::connect('nodb', array('hostname' => 'localhost', 'driver' => 'NoDbDriverMock'));
  49. }
  50. }