Query/tests/BaseDriverTest.php

129 lines
2.9 KiB
PHP
Raw Normal View History

2016-10-12 22:12:25 -04:00
<?php declare(strict_types=1);
/**
* Query
*
2016-10-12 22:12:25 -04:00
* SQL Query Builder / Database Abstraction Layer
*
2018-01-19 16:50:34 -05:00
* PHP version 7.1
2016-10-12 22:12:25 -04:00
*
* @package Query
* @author Timothy J. Warren <tim@timshomepage.net>
2018-01-19 16:50:34 -05:00
* @copyright 2012 - 2018 Timothy J. Warren
2016-10-12 22:12:25 -04:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link https://git.timshomepage.net/aviat4ion/Query
*/
namespace Query\Tests;
/**
* Parent Database Test Class
*/
abstract class BaseDriverTest extends TestCase {
/**
* @var \Query\QueryBuilderInterface|null
*/
protected static $db;
2014-02-14 22:08:19 -05:00
abstract public function testConnection();
2014-02-25 13:47:35 -05:00
public static function tearDownAfterClass()
{
self::$db = NULL;
}
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testGetTables()
{
2016-10-13 21:55:23 -04:00
$tables = self::$db->getTables();
2018-01-26 08:39:30 -05:00
$this->assertTrue(\is_array($tables));
2014-04-08 17:13:41 -04:00
$this->assertTrue( ! empty($tables));
}
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testGetSystemTables()
{
2016-10-13 21:55:23 -04:00
$tables = self::$db->getSystemTables();
2018-01-26 08:39:30 -05:00
$this->assertTrue(\is_array($tables));
2014-04-08 17:13:41 -04:00
$this->assertTrue( ! empty($tables));
}
2014-04-08 17:13:41 -04:00
2014-02-14 22:08:19 -05:00
public function testBackupData()
2012-04-18 16:28:12 -04:00
{
2018-01-26 08:39:30 -05:00
$this->assertTrue(\is_string(self::$db->getUtil()->backupData(['create_delete', FALSE])));
$this->assertTrue(\is_string(self::$db->getUtil()->backupData(['create_delete', TRUE])));
2012-04-18 16:28:12 -04:00
}
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testGetColumns()
{
2016-10-13 21:55:23 -04:00
$cols = self::$db->getColumns('test');
2018-01-26 08:39:30 -05:00
$this->assertTrue(\is_array($cols));
2014-04-08 17:13:41 -04:00
$this->assertTrue( ! empty($cols));
}
2014-02-25 13:47:35 -05:00
2014-02-14 22:08:19 -05:00
public function testGetTypes()
{
2016-10-13 21:55:23 -04:00
$types = self::$db->getTypes();
2018-01-26 08:39:30 -05:00
$this->assertTrue(\is_array($types));
2014-04-08 17:13:41 -04:00
$this->assertTrue( ! empty($types));
}
2014-02-25 13:47:35 -05:00
public function testGetFKs()
{
2018-01-26 08:39:30 -05:00
$expected = [[
'child_column' => 'ext_id',
'parent_table' => 'testconstraints',
'parent_column' => 'someid',
'update' => 'CASCADE',
'delete' => 'CASCADE'
2018-01-26 08:39:30 -05:00
]];
2016-10-13 21:55:23 -04:00
$keys = self::$db->getFks('testconstraints2');
$this->assertEqual($expected, $keys);
}
public function testGetIndexes()
{
2016-10-13 21:55:23 -04:00
$keys = self::$db->getIndexes('test');
2018-01-26 08:39:30 -05:00
$this->assertTrue(\is_array($keys));
}
public function testGetViews()
{
2016-10-13 21:55:23 -04:00
$views = self::$db->getViews();
2018-01-26 08:39:30 -05:00
$expected = ['numbersview', 'testview'];
2014-04-28 16:41:46 -04:00
$this->assertEqual($expected, array_values($views));
2018-01-26 08:39:30 -05:00
$this->assertTrue(\is_array($views));
}
2014-04-28 16:41:46 -04:00
public function testGetTriggers()
{
// @TODO standardize trigger output for different databases
2016-10-13 21:55:23 -04:00
$triggers = self::$db->getTriggers();
2018-01-26 08:39:30 -05:00
$this->assertTrue(\is_array($triggers));
2014-04-28 16:41:46 -04:00
}
public function testGetSequences()
{
2016-10-13 21:55:23 -04:00
$seqs = self::$db->getSequences();
2014-04-28 16:41:46 -04:00
// Normalize sequence names
$seqs = array_map('strtolower', $seqs);
2018-01-26 08:39:30 -05:00
$expected = ['newtable_seq'];
2014-04-28 16:41:46 -04:00
2018-01-26 08:39:30 -05:00
$this->assertTrue(\is_array($seqs));
2014-04-28 16:41:46 -04:00
$this->assertEqual($expected, $seqs);
}
public function testGetProcedures()
{
2016-10-13 21:55:23 -04:00
$procedures = self::$db->getProcedures();
2018-01-26 08:39:30 -05:00
$this->assertTrue(\is_array($procedures));
2014-04-28 16:41:46 -04:00
}
public function testGetFunctions()
{
2016-10-13 21:55:23 -04:00
$funcs = self::$db->getFunctions();
2018-01-26 08:39:30 -05:00
$this->assertTrue(\is_array($funcs));
2014-04-28 16:41:46 -04:00
}
}
// End of db_test.php