Improve code coverage on a few stupid spots

This commit is contained in:
Timothy Warren 2014-04-01 14:54:38 -04:00
parent 235f93bdc4
commit a04b8b44ff
3 changed files with 24 additions and 16 deletions

View File

@ -48,6 +48,7 @@ final class Connection_Manager {
/** /**
* Private constructor to prevent multiple instances * Private constructor to prevent multiple instances
* @codeCoverageIgnore
*/ */
private function __construct() {} private function __construct() {}
@ -55,6 +56,7 @@ final class Connection_Manager {
/** /**
* Private clone method to prevent cloning * Private clone method to prevent cloning
* @codeCoverageIgnore
*/ */
private function __clone() {} private function __clone() {}
@ -62,6 +64,7 @@ final class Connection_Manager {
/** /**
* Make sure serialize/deseriaze doesn't work * Make sure serialize/deseriaze doesn't work
* @codeCoverageIgnore
* @throws DomainException * @throws DomainException
*/ */
private function __wakeup() private function __wakeup()
@ -80,10 +83,12 @@ final class Connection_Manager {
public static function get_instance() public static function get_instance()
{ {
// @codeCoverageIgnoreStart
if (self::$instance === null) if (self::$instance === null)
{ {
self::$instance = new self(); self::$instance = new self();
} }
// @codeCoverageIgnoreEnd
return self::$instance; return self::$instance;
} }
@ -212,12 +217,15 @@ final class Connection_Manager {
*/ */
private function create_dsn($dbtype, $params) private function create_dsn($dbtype, $params)
{ {
// Add the driver type to the dsn
$dsn = ($dbtype !== 'firebird' && $dbtype !== 'sqlite')
? strtolower($dbtype).':'
: '';
if ($dbtype === 'firebird') $dsn = "{$params->host}:{$params->file}"; if ($dbtype === 'firebird') $dsn = "{$params->host}:{$params->file}";
elseif ($dbtype === 'sqlite') $dsn = $params->file; elseif ($dbtype === 'sqlite') $dsn = $params->file;
else else
{ {
$dsn = strtolower($dbtype) . ':';
if ( ! empty($params->database)) if ( ! empty($params->database))
{ {
$dsn .= "dbname={$params->database}"; $dsn .= "dbname={$params->database}";

View File

@ -5,6 +5,7 @@
* Free Query Builder / Database Abstraction Layer * Free Query Builder / Database Abstraction Layer
* *
* @package Query * @package Query
* @subpackage Core
* @author Timothy J. Warren * @author Timothy J. Warren
* @copyright Copyright (c) 2012 - 2014 * @copyright Copyright (c) 2012 - 2014
* @link https://github.com/aviat4ion/Query * @link https://github.com/aviat4ion/Query
@ -15,8 +16,6 @@
/** /**
* Global functions that don't really fit anywhere else * Global functions that don't really fit anywhere else
*
* @package Query
*/ */
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -27,7 +26,6 @@ if ( ! function_exists('do_include'))
* Bulk directory loading workaround for use * Bulk directory loading workaround for use
* with array_map and glob * with array_map and glob
* *
* @subpackage Core
* @param string $path * @param string $path
* @return void * @return void
*/ */
@ -44,7 +42,6 @@ if ( ! function_exists('mb_trim'))
/** /**
* Multibyte-safe trim function * Multibyte-safe trim function
* *
* @subpackage Core
* @param string $string * @param string $string
* @return string * @return string
*/ */
@ -59,7 +56,6 @@ if ( ! function_exists('mb_trim'))
/** /**
* Filter out db rows into one array * Filter out db rows into one array
* *
* @subpackage Core
* @param array $array * @param array $array
* @param mixed $index * @param mixed $index
* @return array * @return array
@ -81,7 +77,6 @@ function db_filter($array, $index)
/** /**
* Connection function * Connection function
* *
* @subpackage Core
* @param mixed $params * @param mixed $params
* @return Query_Builder * @return Query_Builder
*/ */
@ -99,7 +94,7 @@ function Query($params = '')
// Otherwise, return a new connection // Otherwise, return a new connection
return $cmanager->connect($params); return $cmanager->connect($params);
} }
// @codeCoverageIgnoreStart
} }
// @codeCoverageIgnoreEnd
// End of common.php // End of common.php

View File

@ -24,7 +24,7 @@ class PgSQLQBTest extends QBTest {
{ {
$this->markTestSkipped("Postgres extension for PDO not loaded"); $this->markTestSkipped("Postgres extension for PDO not loaded");
} }
// Attempt to connect, if there is a test config file // Attempt to connect, if there is a test config file
if (is_file(QTEST_DIR . "/settings.json")) if (is_file(QTEST_DIR . "/settings.json"))
{ {
@ -57,9 +57,9 @@ class PgSQLQBTest extends QBTest {
{ {
$this->assertTrue(in_array('pgsql', PDO::getAvailableDrivers())); $this->assertTrue(in_array('pgsql', PDO::getAvailableDrivers()));
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
public function testQueryExplain() public function testQueryExplain()
{ {
$query = $this->db->select('id, key as k, val') $query = $this->db->select('id, key as k, val')
@ -67,9 +67,9 @@ class PgSQLQBTest extends QBTest {
->where('id >', 1) ->where('id >', 1)
->where('id <', 900) ->where('id <', 900)
->get('create_test', 2, 1); ->get('create_test', 2, 1);
$res = $query->fetchAll(PDO::FETCH_ASSOC); $res = $query->fetchAll(PDO::FETCH_ASSOC);
$expected = array ( $expected = array (
array ( array (
'QUERY PLAN' => 'Limit (cost=6.41..10.64 rows=2 width=68)', 'QUERY PLAN' => 'Limit (cost=6.41..10.64 rows=2 width=68)',
@ -93,7 +93,12 @@ class PgSQLQBTest extends QBTest {
'QUERY PLAN' => ' Index Cond: ((create_test.id > 1) AND (create_test.id < 900))', 'QUERY PLAN' => ' Index Cond: ((create_test.id > 1) AND (create_test.id < 900))',
), ),
); );
$this->assertEqual($expected, $res); $this->assertEqual($expected, $res);
} }
public function testBackupStructure()
{
$this->assertEquals('', $this->db->util->backup_structure());
}
} }