From 056e8bf6d9f78943b397010657f29b43b45e9e12 Mon Sep 17 00:00:00 2001 From: "Timothy J. Warren" Date: Fri, 31 Jul 2015 10:24:34 -0400 Subject: [PATCH] Re-add some missing tests, and update README --- README.md | 1 + phpunit.xml | 4 +- src/Query/Abstract_Query_Builder.php | 4 +- src/Query/Query_Parser.php | 4 +- tests/bootstrap.php | 6 +- tests/core/{db_test.php => base_db_test.php} | 0 tests/core/base_query_builder_test.php | 1 - tests/core/connection_manager_test.php | 28 +++++ tests/core/{core.php => core_test.php} | 0 tests/core/query_parser_test.php | 13 +- tests/databases/firebird/FirebirdQBTest.php | 6 + tests/databases/firebird/FirebirdTest.php | 5 + .../pdofirebird/PDOFirebirdQBTest.php | 14 ++- .../databases/pdofirebird/PDOFirebirdTest.php | 118 ++++-------------- tests/index.php | 8 +- 15 files changed, 93 insertions(+), 119 deletions(-) rename tests/core/{db_test.php => base_db_test.php} (100%) rename tests/core/{core.php => core_test.php} (100%) diff --git a/README.md b/README.md index 4948a3e..9b24ae7 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ A query builder/database abstraction layer, using prepared queries for security. ## Databases Supported * Firebird (via interbase extension) +* Firebird (via PDO) -- expirimental * MySQL * PostgreSQL * SQLite diff --git a/phpunit.xml b/phpunit.xml index dd86caf..0160988 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -11,8 +11,8 @@ - tests/core/core.php - tests/core/db_qp_test.php + tests/core/core_test.php + tests/core/query_parser_test.php tests/core/connection_manager_test.php diff --git a/src/Query/Abstract_Query_Builder.php b/src/Query/Abstract_Query_Builder.php index 4da157c..2b1f4e1 100644 --- a/src/Query/Abstract_Query_Builder.php +++ b/src/Query/Abstract_Query_Builder.php @@ -171,13 +171,13 @@ abstract class Abstract_Query_Builder { * Alias to driver util class * @var \Query\Driver\Abstract_Util */ - public $util; + protected $util; /** * Alias to driver sql class * @var \Query\Driver\SQL_Interface */ - public $sql; + protected $sql; // -------------------------------------------------------------------------- // Methods diff --git a/src/Query/Query_Parser.php b/src/Query/Query_Parser.php index 69894d0..d08f76c 100644 --- a/src/Query/Query_Parser.php +++ b/src/Query/Query_Parser.php @@ -66,12 +66,12 @@ class Query_Parser { // -------------------------------------------------------------------------- /** - * Public parser method for setting the parse string + * Parser method for setting the parse string * * @param string $sql * @return array */ - protected function parse_join($sql) + public function parse_join($sql) { // Get sql clause components preg_match_all('`'.$this->match_patterns['function'].'`', $sql, $this->matches['functions'], PREG_SET_ORDER); diff --git a/tests/bootstrap.php b/tests/bootstrap.php index da920ea..f42f994 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -100,9 +100,9 @@ $path = QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db'; require_once(QBASE_DIR . 'autoload.php'); // Require base testing classes -require_once(QTEST_DIR . '/core/core.php'); -require_once(QTEST_DIR . '/core/db_test.php'); -require_once(QTEST_DIR . '/core/query_parser_test.php'); +//require_once(QTEST_DIR . '/core/core_test.php'); +require_once(QTEST_DIR . '/core/base_db_test.php'); +//require_once(QTEST_DIR . '/core/query_parser_test.php'); require_once(QTEST_DIR . '/core/base_query_builder_test.php'); // End of bootstrap.php \ No newline at end of file diff --git a/tests/core/db_test.php b/tests/core/base_db_test.php similarity index 100% rename from tests/core/db_test.php rename to tests/core/base_db_test.php diff --git a/tests/core/base_query_builder_test.php b/tests/core/base_query_builder_test.php index ba4aea0..f3cf182 100644 --- a/tests/core/base_query_builder_test.php +++ b/tests/core/base_query_builder_test.php @@ -85,7 +85,6 @@ abstract class QBTest extends Query_TestCase { $query = self::$db->from('test')->get(); $this->assertIsA($query, 'PDOStatement'); - $this->assertTrue(self::$db->num_rows() > 0); } // -------------------------------------------------------------------------- diff --git a/tests/core/connection_manager_test.php b/tests/core/connection_manager_test.php index 2216595..ddd869b 100644 --- a/tests/core/connection_manager_test.php +++ b/tests/core/connection_manager_test.php @@ -65,6 +65,7 @@ class Connection_Manager_Test extends Query_TestCase { $params = (object) array( 'type' => 'sqlite', 'file' => ':memory:', + 'prefix' => 'create_', 'options' => array( 'foo' => 'bar' ) @@ -77,5 +78,32 @@ class Connection_Manager_Test extends Query_TestCase { // Check that the connection just made is returned from the get_connection method $this->assertEqual($conn, self::$instance->get_connection()); } + + // -------------------------------------------------------------------------- + + public function testGetConnection() + { + $params = (object) array( + 'type' => 'sqlite', + 'file' => ':memory:', + 'prefix' => 'create_', + 'alias' => 'conn_manager', + 'options' => array( + 'foo' => 'bar' + ) + ); + + $conn = self::$instance->connect($params); + $this->assertInstanceOf('Query\\Query_Builder', $conn); + + $this->assertEqual($conn, self::$instance->get_connection('conn_manager')); + } + + // -------------------------------------------------------------------------- + + public function testCreateDsn() + { + + } } // End of connection_manager_test.php \ No newline at end of file diff --git a/tests/core/core.php b/tests/core/core_test.php similarity index 100% rename from tests/core/core.php rename to tests/core/core_test.php diff --git a/tests/core/query_parser_test.php b/tests/core/query_parser_test.php index 4d0b641..877bec0 100644 --- a/tests/core/query_parser_test.php +++ b/tests/core/query_parser_test.php @@ -16,17 +16,18 @@ /** * Tests for the Query Parser */ -class QPTest extends Query_TestCase { +class Query_Parser_Test extends Query_TestCase { public function setUp() { - $this->parser = new Query\Query_Parser(); + $db = new Query\Drivers\Sqlite\Driver("sqlite::memory:"); + $this->parser = new Query\Query_Parser($db); } public function TestGeneric() { $matches = $this->parser->parse_join('table1.field1=table2.field2'); - $this->assertIdentical($matches['combined'], array( + $this->assertEqual($matches['combined'], array( 'table1.field1', '=', 'table2.field2' )); } @@ -34,7 +35,7 @@ class QPTest extends Query_TestCase { public function testGeneric2() { $matches = $this->parser->parse_join('db1.table1.field1!=db2.table2.field2'); - $this->assertIdentical($matches['combined'], array( + $this->assertEqual($matches['combined'], array( 'db1.table1.field1','!=','db2.table2.field2' )); } @@ -42,7 +43,7 @@ class QPTest extends Query_TestCase { public function testWUnderscore() { $matches = $this->parser->parse_join('table_1.field1 = tab_le2.field_2'); - $this->assertIdentical($matches['combined'], array( + $this->assertEqual($matches['combined'], array( 'table_1.field1', '=', 'tab_le2.field_2' )); } @@ -50,7 +51,7 @@ class QPTest extends Query_TestCase { public function testFunction() { $matches = $this->parser->parse_join('table1.field1 > SUM(3+5)'); - $this->assertIdentical($matches['combined'], array( + $this->assertEqual($matches['combined'], array( 'table1.field1', '>', 'SUM(3+5)' )); } diff --git a/tests/databases/firebird/FirebirdQBTest.php b/tests/databases/firebird/FirebirdQBTest.php index 25cea6f..e337d50 100644 --- a/tests/databases/firebird/FirebirdQBTest.php +++ b/tests/databases/firebird/FirebirdQBTest.php @@ -126,6 +126,12 @@ class FirebirdQBTest extends QBTest { public function testResultErrors() { + + if (version_compare(PHP_VERSION, '7.0.0', '>=')) + { + $this->markTestSkipped("Segfaults on this version of PHP"); + } + $obj = self::$db->query('SELECT * FROM "create_test"'); // Test row count diff --git a/tests/databases/firebird/FirebirdTest.php b/tests/databases/firebird/FirebirdTest.php index f8bbdbf..b8ca021 100644 --- a/tests/databases/firebird/FirebirdTest.php +++ b/tests/databases/firebird/FirebirdTest.php @@ -136,6 +136,11 @@ class FirebirdTest extends DBtest { public function testTruncate() { + if (version_compare(PHP_VERSION, '7.0.0', '>=')) + { + $this->markTestSkipped("Segfaults on this version of PHP"); + } + self::$db->truncate('create_test'); $this->assertTrue(self::$db->affected_rows() > 0); diff --git a/tests/databases/pdofirebird/PDOFirebirdQBTest.php b/tests/databases/pdofirebird/PDOFirebirdQBTest.php index cb523b8..cc2d9fc 100644 --- a/tests/databases/pdofirebird/PDOFirebirdQBTest.php +++ b/tests/databases/pdofirebird/PDOFirebirdQBTest.php @@ -43,7 +43,12 @@ class PDOFirebirdQBTest extends QBTest { public function testQueryFunctionAlias() { -$this->markTestSkipped("Segfault"); +$this->markTestSkipped(); + if (version_compare(PHP_VERSION, '7.0.0', '<=')) + { + $this->markTestSkipped("Segfaults on this version of PHP"); + } + $db = Query(); $this->assertTrue(self::$db === $db); @@ -84,7 +89,12 @@ $this->markTestSkipped("Segfault"); public function testTypeList() { -$this->markTestSkipped("Segfault"); +$this->markTestIncomplete(); + if (version_compare(PHP_VERSION, '7.0.0', '<=')) + { + $this->markTestSkipped("Segfaults on this version of PHP"); + } + $this->doSetUp(); $sql = self::$db->get_sql()->type_list(); $query = self::$db->query($sql); diff --git a/tests/databases/pdofirebird/PDOFirebirdTest.php b/tests/databases/pdofirebird/PDOFirebirdTest.php index b0b2867..60410f8 100644 --- a/tests/databases/pdofirebird/PDOFirebirdTest.php +++ b/tests/databases/pdofirebird/PDOFirebirdTest.php @@ -95,6 +95,11 @@ class PDOFirebirdTest extends DBtest { public function testCreateTable() { $this->markTestSkipped(); + if (version_compare(PHP_VERSION, '7.0.0', '<=')) + { + $this->markTestSkipped("Segfaults on this version of PHP"); + } + //Attempt to create the table $sql = self::$db->get_util()->create_table('create_delete', array( 'id' => 'SMALLINT', @@ -112,6 +117,11 @@ $this->markTestSkipped(); public function testDeleteTable() { $this->markTestSkipped(); + if (version_compare(PHP_VERSION, '7.0.0', '<=')) + { + $this->markTestSkipped("Segfaults on this version of PHP"); + } + //Attempt to delete the table $sql = self::$db->get_util()->delete_table('create_delete'); self::$db->query($sql); @@ -125,7 +135,11 @@ $this->markTestSkipped(); public function testTruncate() { -$this->markTestSkipped(); + if (version_compare(PHP_VERSION, '7.0.0', '<=')) + { + $this->markTestSkipped("Segfaults on this version of PHP"); + } + self::$db->truncate('create_test'); $this->assertTrue(self::$db->affected_rows() > 0); @@ -133,37 +147,14 @@ $this->markTestSkipped(); // -------------------------------------------------------------------------- - public function testCommitTransaction() - { -$this->markTestSkipped(); - $res = self::$db->beginTransaction(); - - $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)'; - self::$db->query($sql); - - $res = self::$db->commit(); - $this->assertTrue($res); - } - - // -------------------------------------------------------------------------- - - public function testRollbackTransaction() - { -$this->markTestSkipped(); - $res = self::$db->beginTransaction(); - - $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)'; - self::$db->query($sql); - - $res = self::$db->rollback(); - $this->assertTrue($res); - } - - // -------------------------------------------------------------------------- - public function testPreparedStatements() { $this->markTestSkipped(); + /*if (version_compare(PHP_VERSION, '7.0.0', '<=')) + { + $this->markTestSkipped("Segfaults on this version of PHP"); + }*/ + $sql = <<markTestSkipped(); $sql = <<query('SELECT "key","val" FROM "create_test"'); - - // Object - $fetchObj = $res->fetchObject(); - $this->assertIsA($fetchObj, 'stdClass'); - - // Associative array - $fetchAssoc = $res->fetch(PDO::FETCH_ASSOC); - $this->assertTrue(is_array($fetchAssoc)); - $this->assertTrue(array_key_exists('key', $fetchAssoc)); - - // Numeric array - $res2 = self::$db->query('SELECT "id","key","val" FROM "create_test"'); - $fetch = $res2->fetch(PDO::FETCH_NUM); - $this->assertTrue(is_array($fetch)); - }*/ - - // -------------------------------------------------------------------------- - - /*public function testPrepareQuery() - { - $this->assertNull(self::$db->prepare_query('', array())); - }*/ - - // -------------------------------------------------------------------------- - public function testErrorInfo() { $result = self::$db->errorInfo(); @@ -245,44 +209,4 @@ SQL; $res = self::$db->get_sql()->db_list(); $this->assertNULL($res); } - - // -------------------------------------------------------------------------- - - /*public function testExec() - { - $res = self::$db->exec('SELECT * FROM "create_test"'); - $this->assertEquals(NULL, $res); - }*/ - - // -------------------------------------------------------------------------- - - public function testInTransaction() - { -$this->markTestSkipped(); - self::$db->beginTransaction(); - $this->assertTrue(self::$db->inTransaction()); - self::$db->rollBack(); - $this->assertFalse(self::$db->inTransaction()); - } - - // -------------------------------------------------------------------------- - - /*public function testGetAttribute() - { - $res = self::$db->getAttribute("foo"); - $this->assertEquals(NULL, $res); - } - - // -------------------------------------------------------------------------- - - public function testSetAttribute() - { - $this->assertFalse(self::$db->setAttribute(47, 'foo')); - }*/ - - public function testLastInsertId() - { -$this->markTestSkipped(); - $this->assertEqual(0, self::$db->lastInsertId('NEWTABLE_SEQ')); - } } \ No newline at end of file diff --git a/tests/index.php b/tests/index.php index 220aac6..260faf2 100644 --- a/tests/index.php +++ b/tests/index.php @@ -125,10 +125,10 @@ require_once(QBASE_DIR . 'autoload.php'); $test_path = QTEST_DIR.'/databases/'; // Require base testing classes -require_once(QTEST_DIR . '/core/core.php'); +require_once(QTEST_DIR . '/core/core_test.php'); require_once(QTEST_DIR . '/core/connection_manager_test.php'); -require_once(QTEST_DIR . '/core/db_test.php'); -//require_once(QTEST_DIR . '/core/query_parser_test.php'); +require_once(QTEST_DIR . '/core/base_db_test.php'); +require_once(QTEST_DIR . '/core/query_parser_test.php'); require_once(QTEST_DIR . '/core/base_query_builder_test.php'); $drivers = PDO::getAvailableDrivers(); @@ -139,10 +139,10 @@ if (function_exists('fbird_connect')) } $driver_test_map = array( - //'Firebird' => in_array('interbase', $drivers), 'MySQL' => in_array('mysql', $drivers), 'SQLite' => in_array('sqlite', $drivers), 'PgSQL' => in_array('pgsql', $drivers), + //'Firebird' => in_array('interbase', $drivers), //'PDOFirebird' => in_array('firebird', $drivers) );