Query/tests/databases/firebird/FirebirdQBTest.php

163 lines
3.7 KiB
PHP
Raw Normal View History

2012-03-15 09:25:18 -04:00
<?php
/**
* Query
*
* Free Query Builder / Database Abstraction Layer
*
2012-04-20 13:17:39 -04:00
* @package Query
* @author Timothy J. Warren
* @copyright Copyright (c) 2012 - 2014
2012-03-15 09:25:18 -04:00
* @link https://github.com/aviat4ion/Query
2012-04-20 13:17:39 -04:00
* @license http://philsturgeon.co.uk/code/dbad-license
2012-03-15 09:25:18 -04:00
*/
// --------------------------------------------------------------------------
/**
* Firebird Query Builder Tests
2014-02-14 22:08:19 -05:00
* @requires extension interbase
2012-03-15 09:25:18 -04:00
*/
class FirebirdQBTest extends QBTest {
2014-02-25 13:47:35 -05:00
public static function setUpBeforeClass()
2014-02-25 13:47:35 -05:00
{
$dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
2014-02-14 22:08:19 -05:00
// test the query builder
2012-03-15 09:25:18 -04:00
$params = new Stdclass();
2014-02-07 16:53:01 -05:00
$params->alias = 'fire';
2012-03-15 09:25:18 -04:00
$params->type = 'firebird';
$params->file = $dbpath;
$params->host = '127.0.0.1';
$params->user = 'SYSDBA';
2012-03-15 09:25:18 -04:00
$params->pass = 'masterkey';
2012-11-07 08:42:34 -05:00
$params->prefix = 'create_';
self::$db = Query($params);
}
public function setUp()
{
if ( ! function_exists('\\fbird_connect'))
{
$this->markTestSkipped('Firebird extension does not exist');
}
2014-02-07 16:53:01 -05:00
}
2014-02-25 13:47:35 -05:00
// --------------------------------------------------------------------------
2014-02-14 22:08:19 -05:00
public function testGetNamedConnectionException()
2014-02-07 16:53:01 -05:00
{
2014-02-25 13:47:35 -05:00
try
2014-02-07 16:53:01 -05:00
{
$db = Query('water');
2014-02-07 16:53:01 -05:00
}
catch(InvalidArgumentException $e)
{
2014-02-14 22:08:19 -05:00
$this->assertIsA($e, 'InvalidArgumentException');
2014-02-07 16:53:01 -05:00
}
}
2014-02-25 13:47:35 -05:00
// --------------------------------------------------------------------------
public function testQueryFunctionAlias()
{
$db = Query();
$this->assertTrue(self::$db === $db);
}
// --------------------------------------------------------------------------
2014-02-14 22:08:19 -05:00
public function testGetNamedConnection()
2014-02-07 16:53:01 -05:00
{
$dbpath = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
2014-02-14 22:08:19 -05:00
// test the query builder
2014-02-07 16:53:01 -05:00
$params = new Stdclass();
$params->alias = 'wood';
2014-02-07 16:53:01 -05:00
$params->type = 'firebird';
$params->file = $dbpath;
$params->host = 'localhost';
$params->user = 'sysdba';
$params->pass = 'masterkey';
$params->prefix = '';
2014-02-07 16:53:01 -05:00
$f_conn = Query($params);
$q_conn = Query('wood');
2014-02-25 13:47:35 -05:00
$this->assertReference($f_conn, $q_conn);
}
2014-02-25 13:47:35 -05:00
// --------------------------------------------------------------------------
2014-02-14 22:08:19 -05:00
public function testTypeList()
2012-05-08 15:37:36 -04:00
{
$sql = self::$db->sql->type_list();
$query = self::$db->query($sql);
2012-05-08 15:37:36 -04:00
$this->assertIsA($query, 'PDOStatement');
2012-05-08 15:37:36 -04:00
$res = $query->fetchAll(PDO::FETCH_ASSOC);
2012-05-08 15:37:36 -04:00
$this->assertTrue(is_array($res));
}
2014-02-25 13:47:35 -05:00
2014-02-06 17:07:29 -05:00
// --------------------------------------------------------------------------
2014-02-25 13:47:35 -05:00
2014-02-06 17:07:29 -05:00
public function testQueryExplain()
{
$res = self::$db->select('id, key as k, val')
2014-02-06 17:07:29 -05:00
->explain()
->where('id >', 1)
->where('id <', 900)
->limit(2, 1)
2014-02-14 10:38:25 -05:00
->get_compiled_select();
2014-02-25 13:47:35 -05:00
$res2 = self::$db->select('id, key as k, val')
2014-02-14 10:38:25 -05:00
->where('id >', 1)
->where('id <', 900)
->limit(2, 1)
->get_compiled_select();
2014-02-25 13:47:35 -05:00
2014-02-14 10:38:25 -05:00
// Queries are equal because explain is not a keyword in Firebird
$this->assertEqual($res, $res2);
2014-02-06 17:07:29 -05:00
}
2014-02-25 13:47:35 -05:00
// --------------------------------------------------------------------------
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"');
2014-02-25 13:47:35 -05:00
// Test row count
$this->assertEqual(0, $obj->rowCount());
// Test error code
$this->assertFalse($obj->errorCode());
// Test error info
$error = $obj->errorInfo();
$expected = array (
0 => 0,
1 => false,
2 => false,
);
$this->assertEqual($expected, $error);
}
// --------------------------------------------------------------------------
public function testBackupStructure()
{
$existing = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_DB.FDB';
$backup = QTEST_DIR.QDS.'db_files'.QDS.'FB_TEST_BKP.FDB';
$this->assertTrue(self::$db->get_util()->backup_structure($existing, $backup));
}
2012-03-15 09:25:18 -04:00
}