From 6a38213a62c63da11cb4df1b6b82a264199dd6ef Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Mon, 28 Apr 2014 16:41:46 -0400 Subject: [PATCH] Improve some tests and docblocks --- core/abstract/abstract_driver.php | 17 +++++---- core/abstract/abstract_query_builder.php | 2 +- core/query_builder.php | 4 +- drivers/firebird/firebird_sql.php | 4 +- drivers/sqlite/sqlite_driver.php | 1 - tests/core/db_test.php | 45 ++++++++++++++++++++++- tests/databases/firebird/FirebirdTest.php | 28 -------------- tests/databases/mysql/MySQLTest.php | 23 +----------- tests/databases/pgsql/PgSQLTest.php | 21 ----------- tests/databases/sqlite/SqliteTest.php | 23 ++++++++++-- 10 files changed, 81 insertions(+), 87 deletions(-) diff --git a/core/abstract/abstract_driver.php b/core/abstract/abstract_driver.php index e361ef3..d06380c 100644 --- a/core/abstract/abstract_driver.php +++ b/core/abstract/abstract_driver.php @@ -43,13 +43,13 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface { /** * Reference to sql class - * @var SQL_Interface + * @var SQL\SQL_Interface */ public $sql; /** * Reference to util class - * @var Abstract_Util + * @var Util\Abstract_Util */ public $util; @@ -340,7 +340,9 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface { */ public function get_tables() { - return $this->driver_query('table_list'); + $tables = $this->driver_query('table_list'); + natsort($tables); + return $tables; } // ------------------------------------------------------------------------- @@ -364,7 +366,9 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface { */ public function get_views() { - return $this->driver_query('view_list'); + $views = $this->driver_query('view_list'); + sort($views); + return $views; } // ------------------------------------------------------------------------- @@ -583,10 +587,9 @@ abstract class Abstract_Driver extends \PDO implements Driver_Interface { // and is not already quoted before quoting // that value, otherwise, return the original value return ( - strpos($str, $this->escape_char) !== 0 + is_string($str) + && strpos($str, $this->escape_char) !== 0 && strrpos($str, $this->escape_char) !== 0 - && is_string($str) - && ! is_numeric($str) ) ? "{$this->escape_char}{$str}{$this->escape_char}" : $str; diff --git a/core/abstract/abstract_query_builder.php b/core/abstract/abstract_query_builder.php index 27fd7ea..28a4b7f 100644 --- a/core/abstract/abstract_query_builder.php +++ b/core/abstract/abstract_query_builder.php @@ -347,7 +347,7 @@ abstract class Abstract_Query_Builder implements Query_Builder_Interface { { $where = array(); $this->_mixed_set($where, $key, $val, self::BOTH); - $this->where_values = $this->_mixed_set($this->where_values, $key, $val, self::VALUE); + $this->_mixed_set($this->where_values, $key, $val, self::VALUE); return $where; } diff --git a/core/query_builder.php b/core/query_builder.php index d00f9ca..a1cae92 100644 --- a/core/query_builder.php +++ b/core/query_builder.php @@ -478,8 +478,8 @@ class Query_Builder extends Abstract_Query_Builder { */ public function set($key, $val = NULL) { - $this->set_array_keys = $this->_mixed_set($this->set_array_keys, $key, $val, self::KEY); - $this->values = $this->_mixed_set($this->values, $key, $val, self::VALUE); + $this->_mixed_set($this->set_array_keys, $key, $val, self::KEY); + $this->_mixed_set($this->values, $key, $val, self::VALUE); // Use the keys of the array to make the insert/update string // Escape the field names diff --git a/drivers/firebird/firebird_sql.php b/drivers/firebird/firebird_sql.php index 47cf831..a49cff1 100644 --- a/drivers/firebird/firebird_sql.php +++ b/drivers/firebird/firebird_sql.php @@ -131,7 +131,7 @@ SQL; public function view_list() { return <<sql->table_list(); - $res = $this->query($sql); return db_filter($res->fetchAll(\PDO::FETCH_ASSOC), 'name'); } diff --git a/tests/core/db_test.php b/tests/core/db_test.php index 221ced8..93b9d33 100644 --- a/tests/core/db_test.php +++ b/tests/core/db_test.php @@ -98,8 +98,51 @@ abstract class DBTest extends Query_TestCase { public function testGetViews() { - $this->assertTrue(is_array($this->db->get_views())); + $views = $this->db->get_views(); + $expected = array('numbersview', 'testview'); + $this->assertEqual($expected, array_values($views)); + $this->assertTrue(is_array($views)); } + // -------------------------------------------------------------------------- + + public function testGetTriggers() + { + // @TODO standardize trigger output for different databases + + $triggers = $this->db->get_triggers(); + $this->assertTrue(is_array($triggers)); + } + + // -------------------------------------------------------------------------- + + public function testGetSequences() + { + $seqs = $this->db->get_sequences(); + + // Normalize sequence names + $seqs = array_map('strtolower', $seqs); + + $expected = array('newtable_seq'); + + $this->assertTrue(is_array($seqs)); + $this->assertEqual($expected, $seqs); + } + + // -------------------------------------------------------------------------- + + public function testGetProcedures() + { + $procedures = $this->db->get_procedures(); + $this->assertTrue(is_array($procedures)); + } + + // -------------------------------------------------------------------------- + + public function testGetFunctions() + { + $funcs = $this->db->get_functions(); + $this->assertTrue(is_array($funcs)); + } } // End of db_test.php \ No newline at end of file diff --git a/tests/databases/firebird/FirebirdTest.php b/tests/databases/firebird/FirebirdTest.php index e8f1a47..a2b2e8c 100644 --- a/tests/databases/firebird/FirebirdTest.php +++ b/tests/databases/firebird/FirebirdTest.php @@ -219,34 +219,6 @@ SQL; // -------------------------------------------------------------------------- - public function testGetSequences() - { - $this->assertTrue(is_array($this->db->get_sequences())); - } - - // -------------------------------------------------------------------------- - - public function testGetProcedures() - { - $this->assertTrue(is_array($this->db->get_procedures())); - } - - // -------------------------------------------------------------------------- - - public function testGetFunctions() - { - $this->assertTrue(is_array($this->db->get_functions())); - } - - // -------------------------------------------------------------------------- - - public function testGetTriggers() - { - $this->assertTrue(is_array($this->db->get_triggers())); - } - - // -------------------------------------------------------------------------- - public function testErrorInfo() { $result = $this->db->errorInfo(); diff --git a/tests/databases/mysql/MySQLTest.php b/tests/databases/mysql/MySQLTest.php index 5b1ce67..2bc3bc2 100644 --- a/tests/databases/mysql/MySQLTest.php +++ b/tests/databases/mysql/MySQLTest.php @@ -195,27 +195,6 @@ SQL; // -------------------------------------------------------------------------- - public function testGetsProcedures() - { - $this->assertTrue(is_array($this->db->get_procedures())); - } - - // -------------------------------------------------------------------------- - - public function testGetFunctions() - { - $this->assertTrue(is_array($this->db->get_functions())); - } - - // -------------------------------------------------------------------------- - - public function testGetTriggers() - { - $this->assertTrue(is_array($this->db->get_triggers())); - } - - // -------------------------------------------------------------------------- - public function testGetSequences() { $this->assertNull($this->db->get_sequences()); @@ -227,4 +206,6 @@ SQL; { $this->assertTrue(is_string($this->db->util->backup_structure())); } + + } \ No newline at end of file diff --git a/tests/databases/pgsql/PgSQLTest.php b/tests/databases/pgsql/PgSQLTest.php index 9193d4a..7f2306c 100644 --- a/tests/databases/pgsql/PgSQLTest.php +++ b/tests/databases/pgsql/PgSQLTest.php @@ -222,27 +222,6 @@ SQL; // -------------------------------------------------------------------------- - public function testGetSequences() - { - $this->assertTrue(is_array($this->db->get_sequences())); - } - - // -------------------------------------------------------------------------- - - public function testGetProcedures() - { - $this->assertTrue(is_array($this->db->get_procedures())); - } - - // -------------------------------------------------------------------------- - - public function testGetTriggers() - { - $this->assertTrue(is_array($this->db->get_triggers())); - } - - // -------------------------------------------------------------------------- - public function testGetDBs() { $this->assertTrue(is_array($this->db->get_dbs())); diff --git a/tests/databases/sqlite/SqliteTest.php b/tests/databases/sqlite/SqliteTest.php index dfecbe3..c27db30 100644 --- a/tests/databases/sqlite/SqliteTest.php +++ b/tests/databases/sqlite/SqliteTest.php @@ -261,15 +261,32 @@ SQL; $this->assertEqual(NULL, $sql); } + // -------------------------------------------------------------------------- + public function testGetSystemTables() { $sql = $this->db->get_system_tables(); $this->assertTrue(is_array($sql)); } - public function testGetTriggers() + // -------------------------------------------------------------------------- + + public function testGetSequences() { - $sql = $this->db->get_triggers(); - $this->assertTrue(is_array($sql)); + $this->assertNull($this->db->get_sequences()); + } + + // -------------------------------------------------------------------------- + + public function testGetFunctions() + { + $this->assertNull($this->db->get_functions()); + } + + // -------------------------------------------------------------------------- + + public function testGetProcedures() + { + $this->assertNull($this->db->get_procedures()); } } \ No newline at end of file