Query/tests/Drivers/Firebird/FirebirdQueryBuilderTest.php

165 lines
3.8 KiB
PHP
Raw Normal View History

2016-10-12 22:12:25 -04:00
<?php declare(strict_types=1);
2012-03-15 09:25:18 -04:00
/**
* Query
*
2016-10-12 22:12:25 -04:00
* SQL Query Builder / Database Abstraction Layer
2012-03-15 09:25:18 -04:00
*
2016-10-12 22:12:25 -04:00
* PHP version 7
*
* @package Query
* @author Timothy J. Warren <tim@timshomepage.net>
* @copyright 2012 - 2016 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link https://git.timshomepage.net/aviat4ion/Query
2012-03-15 09:25:18 -04:00
*/
namespace Query\Tests\Drivers;
use PDO;
use Query\Tests\BaseQueryBuilderTest;
use InvalidArgumentException;
2016-10-12 22:12:25 -04:00
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 FirebirdQueryBuilderTest extends BaseQueryBuilderTest {
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
$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
$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 = '';
2016-10-13 21:55:23 -04:00
$fConn = Query($params);
$qConn = Query('wood');
2014-02-25 13:47:35 -05:00
2016-10-13 21:55:23 -04:00
$this->assertReference($fConn, $qConn);
}
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
{
2016-10-13 21:55:23 -04:00
$sql = self::$db->sql->typeList();
$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)
2016-10-13 21:55:23 -04:00
->getCompiledSelect();
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)
2016-10-13 21:55:23 -04:00
->getCompiledSelect();
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()
{
$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';
2016-10-13 21:55:23 -04:00
$this->assertTrue(self::$db->getUtil()->backupStructure($existing, $backup));
}
2012-03-15 09:25:18 -04:00
}