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.
59 lines
1.7 KiB
59 lines
1.7 KiB
<?php
|
|
|
|
/*
|
|
* @copyright NetMonsters <team@netmonsters.ru>
|
|
* @link http://netmonsters.ru
|
|
* @package Majestic
|
|
* @subpackage UnitTests
|
|
* @since 2011-11-1
|
|
*
|
|
* Unit tests for Db class
|
|
*/
|
|
|
|
require_once dirname(__FILE__) . '/../../Registry.php';
|
|
require_once dirname(__FILE__) . '/../../Config.php';
|
|
require_once dirname(__FILE__) . '/../../model/Db.php';
|
|
|
|
class DbTest extends PHPUnit_Framework_TestCase
|
|
{
|
|
|
|
/**
|
|
* @expectedException Exception
|
|
*/
|
|
public function testConnectNoParams()
|
|
{
|
|
Db::connect();
|
|
}
|
|
/**
|
|
* @expectedException Exception
|
|
* @expectedExceptionMessage Connection parameters must be an array
|
|
*/
|
|
public function testConnectConfigNotArray()
|
|
{
|
|
Db::connect('name', 'config');
|
|
}
|
|
|
|
public function testConnectGlobalConfig()
|
|
{
|
|
$this->getMock('DbDriver', array(), array(), 'MySQLiDriverGlobalConfMock');
|
|
Config::set('Db', array('global' =>array('hostname' => 'localhost', 'driver' => 'MySQLiDriverGlobalConfMock')));
|
|
Db::connect('global');
|
|
}
|
|
|
|
public function testConnectWithConfigParam()
|
|
{
|
|
$this->getMock('DbDriver', array(), array(), 'MySQLiDriverMock');
|
|
$driver = Db::connect('mysql', array('hostname' => 'localhost', 'driver' => 'MySQLiDriverMock'));
|
|
$this->assertInstanceOf('DbDriver', $driver);
|
|
}
|
|
/**
|
|
* @expectedException Exception
|
|
* @expectedExceptionMessage Database driver must extends DbDriver
|
|
*/
|
|
public function testConnectWithWrongDriver()
|
|
{
|
|
$this->getMock('NotDbDriver', array(), array(), 'NoDbDriverMock');
|
|
$driver = Db::connect('nodb', array('hostname' => 'localhost', 'driver' => 'NoDbDriverMock'));
|
|
}
|
|
|
|
}
|