2015-07-30 16:40:30 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Connection_Manager_Test extends Query_TestCase {
|
|
|
|
|
|
|
|
static $instance = NULL;
|
|
|
|
|
|
|
|
public static function setUpBeforeClass()
|
|
|
|
{
|
2015-11-10 11:18:11 -05:00
|
|
|
self::$instance = Query\ConnectionManager::get_instance();
|
2015-07-30 16:40:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
public function testNoClone()
|
|
|
|
{
|
|
|
|
$this->setExpectedException('DomainException', "Can't clone singleton");
|
|
|
|
$clone = clone self::$instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
public function testNoSerialize()
|
|
|
|
{
|
|
|
|
$this->setExpectedException('DomainException', "No serializing of singleton");
|
|
|
|
$string = serialize(self::$instance);
|
|
|
|
|
|
|
|
$this->setExpectedException('DomainException', "No serializing of singleton");
|
|
|
|
$string = self::$instance->__sleep();
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
public function testNoUnserialize()
|
|
|
|
{
|
|
|
|
$this->setExpectedException('DomainException', "Can't unserialize singleton");
|
|
|
|
$obj = self::$instance->__wakeup();
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
public function testParseParams()
|
|
|
|
{
|
|
|
|
$params = (object) array(
|
|
|
|
'type' => 'sqlite',
|
|
|
|
'file' => ':memory:',
|
|
|
|
'options' => array(
|
|
|
|
'foo' => 'bar'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
':memory:',
|
|
|
|
'Sqlite',
|
|
|
|
$params,
|
|
|
|
array('foo' => 'bar')
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->assertEqual($expected, self::$instance->parse_params($params));
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
public function testConnect()
|
|
|
|
{
|
|
|
|
$params = (object) array(
|
|
|
|
'type' => 'sqlite',
|
|
|
|
'file' => ':memory:',
|
2015-07-31 10:24:34 -04:00
|
|
|
'prefix' => 'create_',
|
2015-07-30 16:40:30 -04:00
|
|
|
'options' => array(
|
|
|
|
'foo' => 'bar'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$conn = self::$instance->connect($params);
|
2015-11-10 11:18:11 -05:00
|
|
|
$this->assertInstanceOf('Query\\QueryBuilder', $conn);
|
2015-07-30 16:40:30 -04:00
|
|
|
|
|
|
|
|
|
|
|
// Check that the connection just made is returned from the get_connection method
|
|
|
|
$this->assertEqual($conn, self::$instance->get_connection());
|
|
|
|
}
|
2015-07-31 10:24:34 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
public function testGetConnection()
|
|
|
|
{
|
|
|
|
$params = (object) array(
|
|
|
|
'type' => 'sqlite',
|
|
|
|
'file' => ':memory:',
|
|
|
|
'prefix' => 'create_',
|
|
|
|
'alias' => 'conn_manager',
|
|
|
|
'options' => array(
|
|
|
|
'foo' => 'bar'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$conn = self::$instance->connect($params);
|
2015-11-10 11:18:11 -05:00
|
|
|
$this->assertInstanceOf('Query\\QueryBuilder', $conn);
|
2015-07-31 10:24:34 -04:00
|
|
|
|
|
|
|
$this->assertEqual($conn, self::$instance->get_connection('conn_manager'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
public function testCreateDsn()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2015-07-30 16:40:30 -04:00
|
|
|
}
|
|
|
|
// End of connection_manager_test.php
|