2016-10-12 22:12:25 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
/**
|
|
|
|
* Query
|
|
|
|
*
|
|
|
|
* SQL Query Builder / Database Abstraction Layer
|
|
|
|
*
|
2018-01-19 16:50:34 -05:00
|
|
|
* PHP version 7.1
|
2016-10-12 22:12:25 -04:00
|
|
|
*
|
2018-01-19 16:50:34 -05:00
|
|
|
* @package Query
|
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
|
|
|
* @copyright 2012 - 2018 Timothy J. Warren
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
* @link https://git.timshomepage.net/aviat4ion/Query
|
2016-10-12 22:12:25 -04:00
|
|
|
*/
|
2018-01-19 16:48:52 -05:00
|
|
|
namespace Query\Tests;
|
2015-07-30 16:40:30 -04:00
|
|
|
|
2018-01-19 16:48:52 -05:00
|
|
|
use DomainException;
|
|
|
|
use Query\{ConnectionManager, QueryBuilderInterface};
|
2015-07-30 16:40:30 -04:00
|
|
|
|
2018-01-19 16:48:52 -05:00
|
|
|
class ConnectionManagerTest extends TestCase {
|
|
|
|
|
|
|
|
protected static $instance;
|
2015-07-30 16:40:30 -04:00
|
|
|
|
|
|
|
public static function setUpBeforeClass()
|
|
|
|
{
|
2018-01-19 16:48:52 -05:00
|
|
|
self::$instance = ConnectionManager::getInstance();
|
2015-07-30 16:40:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoClone()
|
|
|
|
{
|
2016-10-12 20:32:23 -04:00
|
|
|
$this->expectException('DomainException');
|
|
|
|
$this->expectExceptionMessage("Can't clone singleton");
|
2015-07-30 16:40:30 -04:00
|
|
|
$clone = clone self::$instance;
|
2018-01-19 16:48:52 -05:00
|
|
|
$this->assertNull($clone);
|
2015-07-30 16:40:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoSerialize()
|
|
|
|
{
|
2018-01-19 16:48:52 -05:00
|
|
|
$this->expectException(DomainException::class);
|
|
|
|
$this->expectExceptionMessage('No serializing of singleton');
|
|
|
|
serialize(self::$instance);
|
2015-07-30 16:40:30 -04:00
|
|
|
|
2018-01-19 16:48:52 -05:00
|
|
|
$this->expectException(DomainException::class);
|
|
|
|
$this->expectExceptionMessage('No serializing of singleton');
|
|
|
|
self::$instance->__sleep();
|
2015-07-30 16:40:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoUnserialize()
|
|
|
|
{
|
2018-01-19 16:48:52 -05:00
|
|
|
$this->expectException(DomainException::class);
|
|
|
|
$this->expectExceptionMessage("Can't unserialize singleton");
|
|
|
|
self::$instance->__wakeup();
|
2015-07-30 16:40:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testParseParams()
|
|
|
|
{
|
|
|
|
$params = (object) array(
|
|
|
|
'type' => 'sqlite',
|
|
|
|
'file' => ':memory:',
|
|
|
|
'options' => array(
|
|
|
|
'foo' => 'bar'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
$expected = array(
|
|
|
|
':memory:',
|
|
|
|
'Sqlite',
|
|
|
|
$params,
|
|
|
|
array('foo' => 'bar')
|
|
|
|
);
|
|
|
|
|
2016-10-13 21:55:23 -04:00
|
|
|
$this->assertEqual($expected, self::$instance->parseParams($params));
|
2015-07-30 16:40:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2018-01-19 16:48:52 -05:00
|
|
|
$this->assertInstanceOf(QueryBuilderInterface::class, $conn);
|
2015-07-30 16:40:30 -04:00
|
|
|
|
|
|
|
|
|
|
|
// Check that the connection just made is returned from the get_connection method
|
2016-10-13 21:55:23 -04:00
|
|
|
$this->assertEqual($conn, self::$instance->getConnection());
|
2015-07-30 16:40:30 -04:00
|
|
|
}
|
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);
|
2018-01-19 16:48:52 -05:00
|
|
|
$this->assertInstanceOf(QueryBuilderInterface::class, $conn);
|
2015-07-31 10:24:34 -04:00
|
|
|
|
2016-10-13 21:55:23 -04:00
|
|
|
$this->assertEqual($conn, self::$instance->getConnection('conn_manager'));
|
2015-07-31 10:24:34 -04:00
|
|
|
}
|
2015-07-30 16:40:30 -04:00
|
|
|
}
|
2018-01-19 16:48:52 -05:00
|
|
|
// End of connection_manager_test.php
|