Re-add some missing tests, and update README

This commit is contained in:
Timothy Warren 2015-07-31 10:24:34 -04:00
parent 225017adee
commit 056e8bf6d9
15 changed files with 93 additions and 119 deletions

View File

@ -17,6 +17,7 @@ A query builder/database abstraction layer, using prepared queries for security.
## Databases Supported ## Databases Supported
* Firebird (via interbase extension) * Firebird (via interbase extension)
* Firebird (via PDO) -- expirimental
* MySQL * MySQL
* PostgreSQL * PostgreSQL
* SQLite * SQLite

View File

@ -11,8 +11,8 @@
</filter> </filter>
<testsuites> <testsuites>
<testsuite name="CoreTests"> <testsuite name="CoreTests">
<file>tests/core/core.php</file> <file>tests/core/core_test.php</file>
<file>tests/core/db_qp_test.php</file> <file>tests/core/query_parser_test.php</file>
<file>tests/core/connection_manager_test.php</file> <file>tests/core/connection_manager_test.php</file>
</testsuite> </testsuite>
<testsuite name="MySQLTests"> <testsuite name="MySQLTests">

View File

@ -171,13 +171,13 @@ abstract class Abstract_Query_Builder {
* Alias to driver util class * Alias to driver util class
* @var \Query\Driver\Abstract_Util * @var \Query\Driver\Abstract_Util
*/ */
public $util; protected $util;
/** /**
* Alias to driver sql class * Alias to driver sql class
* @var \Query\Driver\SQL_Interface * @var \Query\Driver\SQL_Interface
*/ */
public $sql; protected $sql;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Methods // Methods

View File

@ -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 * @param string $sql
* @return array * @return array
*/ */
protected function parse_join($sql) public function parse_join($sql)
{ {
// Get sql clause components // Get sql clause components
preg_match_all('`'.$this->match_patterns['function'].'`', $sql, $this->matches['functions'], PREG_SET_ORDER); preg_match_all('`'.$this->match_patterns['function'].'`', $sql, $this->matches['functions'], PREG_SET_ORDER);

View File

@ -100,9 +100,9 @@ $path = QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db';
require_once(QBASE_DIR . 'autoload.php'); require_once(QBASE_DIR . 'autoload.php');
// Require base testing classes // Require base testing classes
require_once(QTEST_DIR . '/core/core.php'); //require_once(QTEST_DIR . '/core/core_test.php');
require_once(QTEST_DIR . '/core/db_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/query_parser_test.php');
require_once(QTEST_DIR . '/core/base_query_builder_test.php'); require_once(QTEST_DIR . '/core/base_query_builder_test.php');
// End of bootstrap.php // End of bootstrap.php

View File

@ -85,7 +85,6 @@ abstract class QBTest extends Query_TestCase {
$query = self::$db->from('test')->get(); $query = self::$db->from('test')->get();
$this->assertIsA($query, 'PDOStatement'); $this->assertIsA($query, 'PDOStatement');
$this->assertTrue(self::$db->num_rows() > 0);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

View File

@ -65,6 +65,7 @@ class Connection_Manager_Test extends Query_TestCase {
$params = (object) array( $params = (object) array(
'type' => 'sqlite', 'type' => 'sqlite',
'file' => ':memory:', 'file' => ':memory:',
'prefix' => 'create_',
'options' => array( 'options' => array(
'foo' => 'bar' '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 // Check that the connection just made is returned from the get_connection method
$this->assertEqual($conn, self::$instance->get_connection()); $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 // End of connection_manager_test.php

View File

@ -16,17 +16,18 @@
/** /**
* Tests for the Query Parser * Tests for the Query Parser
*/ */
class QPTest extends Query_TestCase { class Query_Parser_Test extends Query_TestCase {
public function setUp() 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() public function TestGeneric()
{ {
$matches = $this->parser->parse_join('table1.field1=table2.field2'); $matches = $this->parser->parse_join('table1.field1=table2.field2');
$this->assertIdentical($matches['combined'], array( $this->assertEqual($matches['combined'], array(
'table1.field1', '=', 'table2.field2' 'table1.field1', '=', 'table2.field2'
)); ));
} }
@ -34,7 +35,7 @@ class QPTest extends Query_TestCase {
public function testGeneric2() public function testGeneric2()
{ {
$matches = $this->parser->parse_join('db1.table1.field1!=db2.table2.field2'); $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' 'db1.table1.field1','!=','db2.table2.field2'
)); ));
} }
@ -42,7 +43,7 @@ class QPTest extends Query_TestCase {
public function testWUnderscore() public function testWUnderscore()
{ {
$matches = $this->parser->parse_join('table_1.field1 = tab_le2.field_2'); $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' 'table_1.field1', '=', 'tab_le2.field_2'
)); ));
} }
@ -50,7 +51,7 @@ class QPTest extends Query_TestCase {
public function testFunction() public function testFunction()
{ {
$matches = $this->parser->parse_join('table1.field1 > SUM(3+5)'); $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)' 'table1.field1', '>', 'SUM(3+5)'
)); ));
} }

View File

@ -126,6 +126,12 @@ class FirebirdQBTest extends QBTest {
public function testResultErrors() 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"'); $obj = self::$db->query('SELECT * FROM "create_test"');
// Test row count // Test row count

View File

@ -136,6 +136,11 @@ class FirebirdTest extends DBtest {
public function testTruncate() public function testTruncate()
{ {
if (version_compare(PHP_VERSION, '7.0.0', '>='))
{
$this->markTestSkipped("Segfaults on this version of PHP");
}
self::$db->truncate('create_test'); self::$db->truncate('create_test');
$this->assertTrue(self::$db->affected_rows() > 0); $this->assertTrue(self::$db->affected_rows() > 0);

View File

@ -43,7 +43,12 @@ class PDOFirebirdQBTest extends QBTest {
public function testQueryFunctionAlias() 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(); $db = Query();
$this->assertTrue(self::$db === $db); $this->assertTrue(self::$db === $db);
@ -84,7 +89,12 @@ $this->markTestSkipped("Segfault");
public function testTypeList() 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(); $this->doSetUp();
$sql = self::$db->get_sql()->type_list(); $sql = self::$db->get_sql()->type_list();
$query = self::$db->query($sql); $query = self::$db->query($sql);

View File

@ -95,6 +95,11 @@ class PDOFirebirdTest extends DBtest {
public function testCreateTable() public function testCreateTable()
{ {
$this->markTestSkipped(); $this->markTestSkipped();
if (version_compare(PHP_VERSION, '7.0.0', '<='))
{
$this->markTestSkipped("Segfaults on this version of PHP");
}
//Attempt to create the table //Attempt to create the table
$sql = self::$db->get_util()->create_table('create_delete', array( $sql = self::$db->get_util()->create_table('create_delete', array(
'id' => 'SMALLINT', 'id' => 'SMALLINT',
@ -112,6 +117,11 @@ $this->markTestSkipped();
public function testDeleteTable() public function testDeleteTable()
{ {
$this->markTestSkipped(); $this->markTestSkipped();
if (version_compare(PHP_VERSION, '7.0.0', '<='))
{
$this->markTestSkipped("Segfaults on this version of PHP");
}
//Attempt to delete the table //Attempt to delete the table
$sql = self::$db->get_util()->delete_table('create_delete'); $sql = self::$db->get_util()->delete_table('create_delete');
self::$db->query($sql); self::$db->query($sql);
@ -125,7 +135,11 @@ $this->markTestSkipped();
public function testTruncate() 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'); self::$db->truncate('create_test');
$this->assertTrue(self::$db->affected_rows() > 0); $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() public function testPreparedStatements()
{ {
$this->markTestSkipped(); $this->markTestSkipped();
/*if (version_compare(PHP_VERSION, '7.0.0', '<='))
{
$this->markTestSkipped("Segfaults on this version of PHP");
}*/
$sql = <<<SQL $sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val") INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?) VALUES (?,?,?)
@ -177,6 +168,7 @@ SQL;
public function testPrepareExecute() public function testPrepareExecute()
{ {
$this->markTestSkipped();
$sql = <<<SQL $sql = <<<SQL
INSERT INTO "create_test" ("id", "key", "val") INSERT INTO "create_test" ("id", "key", "val")
VALUES (?,?,?) VALUES (?,?,?)
@ -189,34 +181,6 @@ SQL;
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
/*public function testFetch()
{
$res = self::$db->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() public function testErrorInfo()
{ {
$result = self::$db->errorInfo(); $result = self::$db->errorInfo();
@ -245,44 +209,4 @@ SQL;
$res = self::$db->get_sql()->db_list(); $res = self::$db->get_sql()->db_list();
$this->assertNULL($res); $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'));
}
} }

View File

@ -125,10 +125,10 @@ require_once(QBASE_DIR . 'autoload.php');
$test_path = QTEST_DIR.'/databases/'; $test_path = QTEST_DIR.'/databases/';
// Require base testing classes // 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/connection_manager_test.php');
require_once(QTEST_DIR . '/core/db_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/query_parser_test.php');
require_once(QTEST_DIR . '/core/base_query_builder_test.php'); require_once(QTEST_DIR . '/core/base_query_builder_test.php');
$drivers = PDO::getAvailableDrivers(); $drivers = PDO::getAvailableDrivers();
@ -139,10 +139,10 @@ if (function_exists('fbird_connect'))
} }
$driver_test_map = array( $driver_test_map = array(
//'Firebird' => in_array('interbase', $drivers),
'MySQL' => in_array('mysql', $drivers), 'MySQL' => in_array('mysql', $drivers),
'SQLite' => in_array('sqlite', $drivers), 'SQLite' => in_array('sqlite', $drivers),
'PgSQL' => in_array('pgsql', $drivers), 'PgSQL' => in_array('pgsql', $drivers),
//'Firebird' => in_array('interbase', $drivers),
//'PDOFirebird' => in_array('firebird', $drivers) //'PDOFirebird' => in_array('firebird', $drivers)
); );