Query/tests/ConnectionManagerTest.php

117 lines
2.6 KiB
PHP
Raw Permalink Normal View History

2016-10-12 22:12:25 -04:00
<?php declare(strict_types=1);
/**
* Query
*
* SQL Query Builder / Database Abstraction Layer
*
2020-04-10 20:54:31 -04:00
* PHP version 7.4
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>
2020-03-18 11:31:56 -04:00
* @copyright 2012 - 2020 Timothy J. Warren
2018-01-19 16:50:34 -05:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2019-12-11 16:49:42 -05:00
* @link https://git.timshomepage.net/aviat/Query
* @version 3.0.0
2016-10-12 22:12:25 -04:00
*/
namespace Query\Tests;
use DomainException;
use Query\{ConnectionManager, QueryBuilderInterface};
class ConnectionManagerTest extends TestCase {
protected static $instance;
2019-12-10 12:17:40 -05:00
public static function setUpBeforeClass(): void
{
ConnectionManager::getInstance();
self::$instance = ConnectionManager::getInstance();
}
2019-12-10 12:17:40 -05:00
public static function tearDownAfterClass(): void
2018-01-26 08:39:30 -05:00
{
self::$instance = NULL;
}
2019-12-10 12:17:40 -05:00
public function testNoClone(): void
{
2016-10-12 20:32:23 -04:00
$this->expectException('DomainException');
$this->expectExceptionMessage("Can't clone singleton");
$clone = clone self::$instance;
$this->assertNull($clone);
}
2019-12-10 12:17:40 -05:00
public function testNoSerialize(): void
{
$this->expectException(DomainException::class);
$this->expectExceptionMessage('No serializing of singleton');
serialize(self::$instance);
$this->expectException(DomainException::class);
$this->expectExceptionMessage('No serializing of singleton');
self::$instance->__sleep();
}
2019-12-10 12:17:40 -05:00
public function testNoUnserialize(): void
{
$this->expectException(DomainException::class);
$this->expectExceptionMessage("Can't unserialize singleton");
self::$instance->__wakeup();
}
2019-12-10 12:17:40 -05:00
public function testParseParams(): void
{
2018-01-26 08:39:30 -05:00
$params = new class {
public $type = 'sqlite';
public $file = ':memory:';
public $options = [
'foo' => 'bar'
2018-01-26 08:39:30 -05:00
];
};
2018-01-26 08:39:30 -05:00
$expected = [
':memory:',
'Sqlite',
$params,
2018-01-26 08:39:30 -05:00
['foo' => 'bar']
];
2016-10-13 21:55:23 -04:00
$this->assertEqual($expected, self::$instance->parseParams($params));
}
2019-12-10 12:17:40 -05:00
public function testConnect(): void
{
2018-01-26 08:39:30 -05:00
$params = new class {
public $type = 'sqlite';
public $file = ':memory:';
public $prefix = 'create_';
public $options = [
'foo' => 'bar'
2018-01-26 08:39:30 -05:00
];
};
$conn = self::$instance->connect($params);
// 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());
}
2019-12-10 12:17:40 -05:00
public function testGetConnection(): void
{
2018-01-26 08:39:30 -05:00
$params = (object) [
'type' => 'sqlite',
'file' => ':memory:',
'prefix' => 'create_',
'alias' => 'conn_manager',
2018-01-26 08:39:30 -05:00
'options' => [
'foo' => 'bar'
2018-01-26 08:39:30 -05:00
]
];
$conn = self::$instance->connect($params);
2016-10-13 21:55:23 -04:00
$this->assertEqual($conn, self::$instance->getConnection('conn_manager'));
}
}
// End of connection_manager_test.php