Query/tests/index.php

165 lines
3.2 KiB
PHP
Raw Normal View History

<?php declare(strict_types=1);
/**
* Query
*
2018-01-19 16:50:34 -05:00
* SQL Query Builder / Database Abstraction Layer
*
2022-09-29 11:33:08 -04:00
* PHP version 8.1
2018-01-19 16:50:34 -05:00
*
* @package Query
2023-01-20 11:30:51 -05:00
* @author Timothy J. Warren <tim@timshome.page>
* @copyright 2012 - 2023 Timothy J. Warren
2018-01-19 16:50:34 -05:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2019-12-11 16:49:42 -05:00
* @link https://git.timshomepage.net/aviat/Query
2022-09-29 11:33:08 -04:00
* @version 4.0.0
*/
2023-03-17 15:30:36 -04:00
namespace {
/**
* Unit test bootstrap - Using php simpletest
*/
2019-12-11 16:48:43 -05:00
define('QTEST_DIR', __DIR__);
define('QBASE_DIR', realpath(__DIR__ . '/../') . '/');
define('QDS', DIRECTORY_SEPARATOR);
require_once QBASE_DIR . 'vendor/simpletest/simpletest/autorun.php';
require_once QBASE_DIR . 'vendor/autoload.php';
}
2016-10-12 20:32:23 -04:00
namespace Query\Tests {
/**
* Base class for TestCases
*/
2023-03-17 15:30:36 -04:00
abstract class TestCase extends \UnitTestCase
{
public function __construct()
2016-10-12 20:32:23 -04:00
{
2023-03-17 15:30:36 -04:00
$class = static::class;
2016-10-12 20:32:23 -04:00
if (PHP_SAPI !== 'cli')
{
echo 'Running test suite: ' . $class . '<br />';
flush();
}
2016-10-12 20:32:23 -04:00
2023-03-17 15:30:36 -04:00
if (method_exists($class, 'setupBeforeClass'))
{
$class::setupBeforeClass();
}
parent::__construct();
}
public function __destruct()
{
2023-03-17 15:30:36 -04:00
$class = static::class;
2023-03-17 15:30:36 -04:00
if (method_exists($class, 'tearDownAfterClass'))
{
$class::tearDownAfterClass();
}
}
/**
* Define assertInstanceOf for simpletest
*
* @param string $message
*/
public function assertInstanceOf($expected, $actual, $message = '')
{
$this->assertIsA($actual, $expected, $message);
}
/**
* Alias to assertEqual
*
* @param mixed $expected
* @param mixed $actual
* @param string $message
*/
public function assertEquals($expected, $actual, $message = '')
{
$this->assertEqual($expected, $actual, $message);
}
/**
* Alias to skipIf in SimpleTest
*
* @param string $message
*/
public function markTestSkipped($message = '')
{
$this->skipUnless(FALSE, $message);
}
2018-01-26 08:39:30 -05:00
public function expectException($exception = FALSE, $message = '%s')
{
return parent::expectException(FALSE);
}
/**
* Alias to the method in PHPUnit
*
* @param string $message
*/
public function expectExceptionMessage($message)
{
// noop
}
}
}
/**
* Load the test suites
*/
2023-03-17 15:30:36 -04:00
namespace {
function get_json_config()
2016-10-12 20:32:23 -04:00
{
2018-01-26 08:39:30 -05:00
$files = [
__DIR__ . '/settings.json',
2023-03-17 15:30:36 -04:00
__DIR__ . '/settings.json.dist',
2018-01-26 08:39:30 -05:00
];
2023-03-17 15:30:36 -04:00
foreach ($files as $file)
{
if (is_file($file))
{
return json_decode(file_get_contents($file));
}
}
2016-10-12 20:32:23 -04:00
return FALSE;
}
// Include db tests
// Load db classes based on capability
2023-03-17 15:30:36 -04:00
$testPath = QTEST_DIR . '/Drivers/';
// Require base testing classes
require_once QTEST_DIR . '/CoreTest.php';
require_once QTEST_DIR . '/ConnectionManagerTest.php';
require_once QTEST_DIR . '/QueryParserTest.php';
2014-06-30 11:01:44 -04:00
$drivers = PDO::getAvailableDrivers();
$driverTestMap = [
'MySQL' => \in_array('mysql', $drivers, TRUE),
'SQLite' => \in_array('sqlite', $drivers, TRUE),
'PgSQL' => \in_array('pgsql', $drivers, TRUE),
];
// Determine which testcases to load
2023-03-17 15:30:36 -04:00
foreach ($driverTestMap as $name => $doLoad)
2014-06-30 11:01:44 -04:00
{
$path = $testPath . $name;
if ($doLoad)
{
require_once "{$path}/{$name}DriverTest.php";
require_once "{$path}/{$name}QueryBuilderTest.php";
}
2014-06-30 11:01:44 -04:00
}
}
2018-01-19 13:43:19 -05:00
// End of index.php