Cleanup a bunch of Simpletest weirdness from the tests
This commit is contained in:
parent
282935d9f8
commit
2d80d8ea15
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" beStrictAboutOutputDuringTests="false" colors="true" stopOnFailure="false" bootstrap="./../tests/bootstrap.php" verbose="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" beStrictAboutOutputDuringTests="false" colors="true" stopOnFailure="false" bootstrap="./../tests/bootstrap.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache">
|
||||
<coverage>
|
||||
<include>
|
||||
<directory suffix=".php">./../src/</directory>
|
||||
|
@ -32,7 +32,7 @@
|
||||
"ext-pdo": "*"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^9.4"
|
||||
"phpunit/phpunit": "^10.0.16"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@ -51,7 +51,7 @@
|
||||
"build": "tools/vendor/bin/robo build",
|
||||
"clean": "tools/vendor/bin/robo clean",
|
||||
"docs": "php tools/phpDocumentor run --sourcecode",
|
||||
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
|
||||
"coverage": "php -dpcov.enabled=1 -dpcov.directory=. -dpcov.exclude=\"~vendor~\" ./vendor/bin/phpunit -c build",
|
||||
"pcov": "vendor/bin/phpunit -c build",
|
||||
"phpstan": "tools/vendor/bin/phpstan analyse -l 3 -c phpstan.neon src tests",
|
||||
"test": "phpunit -c build --no-coverage"
|
||||
|
@ -21,7 +21,7 @@ use Query\QueryBuilderInterface;
|
||||
/**
|
||||
* Parent Database Test Class
|
||||
*/
|
||||
abstract class BaseDriverTest extends TestCase
|
||||
abstract class BaseDriverTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var QueryBuilderInterface|null
|
||||
@ -80,7 +80,7 @@ abstract class BaseDriverTest extends TestCase
|
||||
]];
|
||||
|
||||
$keys = self::$db->getFks('testconstraints2');
|
||||
$this->assertEqual($expected, $keys);
|
||||
$this->assertEquals($expected, $keys);
|
||||
}
|
||||
|
||||
public function testGetIndexes(): void
|
||||
@ -119,7 +119,7 @@ abstract class BaseDriverTest extends TestCase
|
||||
$expected = ['newtable_seq'];
|
||||
|
||||
$this->assertIsArray($seqs);
|
||||
$this->assertEqual($expected, $seqs);
|
||||
$this->assertEquals($expected, $seqs);
|
||||
}
|
||||
|
||||
public function testGetProcedures(): void
|
||||
|
@ -24,7 +24,7 @@ use Query\QueryBuilderInterface;
|
||||
/**
|
||||
* Query builder parent test class
|
||||
*/
|
||||
abstract class BaseQueryBuilderTest extends TestCase
|
||||
abstract class BaseQueryBuilderTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var QueryBuilderInterface|null
|
||||
@ -91,7 +91,7 @@ abstract class BaseQueryBuilderTest extends TestCase
|
||||
$query = self::$db->get('test');
|
||||
$numrows = count($query->fetchAll(PDO::FETCH_NUM));
|
||||
|
||||
$this->assertEqual(self::$db->numRows(), $numrows);
|
||||
$this->assertEquals(self::$db->numRows(), $numrows);
|
||||
}
|
||||
|
||||
public function testGetLimit(): void
|
||||
@ -583,7 +583,7 @@ abstract class BaseQueryBuilderTest extends TestCase
|
||||
$row = $query->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
$this->assertEqual([
|
||||
$this->assertEquals([
|
||||
'id' => 99,
|
||||
'key' => 84,
|
||||
'val' => 120,
|
||||
@ -647,7 +647,7 @@ abstract class BaseQueryBuilderTest extends TestCase
|
||||
|
||||
$this->assertIsA($query, 'PDOStatement');
|
||||
$row = $query->fetch(PDO::FETCH_ASSOC);
|
||||
$this->assertEqual([
|
||||
$this->assertEquals([
|
||||
'key' => 'gogle',
|
||||
], $row, json_encode($query->errorInfo()));
|
||||
|
||||
@ -840,6 +840,6 @@ abstract class BaseQueryBuilderTest extends TestCase
|
||||
])->insert('test');
|
||||
|
||||
$res = self::$db->numRows();
|
||||
$this->assertEqual(NULL, $res);
|
||||
$this->assertNull($res);
|
||||
}
|
||||
}
|
||||
|
@ -13,35 +13,31 @@
|
||||
* @link https://git.timshomepage.net/aviat/Query
|
||||
* @version 4.0.0
|
||||
*/
|
||||
|
||||
namespace Query\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase as PHPUnit_TestCase;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Base class for TestCases
|
||||
*/
|
||||
class TestCase extends PHPUnit_TestCase {
|
||||
|
||||
abstract class BaseTestCase extends TestCase
|
||||
{
|
||||
/**
|
||||
* Wrapper for Simpletest's assertEqual
|
||||
*
|
||||
* @param mixed $expected
|
||||
* @param mixed $actual
|
||||
* @param string $message
|
||||
*/
|
||||
public function assertEqual($expected, $actual, $message='')
|
||||
{
|
||||
$this->assertEquals($expected, $actual, $message);
|
||||
}
|
||||
// public function assertEqual($expected, $actual, $message='')
|
||||
// {
|
||||
// $this->assertEquals($expected, $actual, $message);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Wrapper for SimpleTest's assertIsA
|
||||
*
|
||||
* @param mixed $object
|
||||
* @param string $type
|
||||
* @param string $message
|
||||
*/
|
||||
public function assertIsA($object, $type, $message='')
|
||||
public function assertIsA(mixed $object, string $type, string $message='')
|
||||
{
|
||||
$this->assertTrue(is_a($object, $type), $message);
|
||||
}
|
||||
@ -53,20 +49,20 @@ class TestCase extends PHPUnit_TestCase {
|
||||
* @param mixed $second
|
||||
* @param string $message
|
||||
*/
|
||||
public function assertReference($first, $second, $message='')
|
||||
{
|
||||
if (\is_object($first))
|
||||
{
|
||||
$res = ($first === $second);
|
||||
}
|
||||
else
|
||||
{
|
||||
$temp = $first;
|
||||
$first = uniqid('test', TRUE);
|
||||
$isRef = ($first === $second);
|
||||
$first = $temp;
|
||||
$res = $isRef;
|
||||
}
|
||||
$this->assertTrue($res, $message);
|
||||
}
|
||||
}
|
||||
// public function assertReference($first, $second, $message='')
|
||||
// {
|
||||
// if (\is_object($first))
|
||||
// {
|
||||
// $res = ($first === $second);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// $temp = $first;
|
||||
// $first = uniqid('test', TRUE);
|
||||
// $isRef = ($first === $second);
|
||||
// $first = $temp;
|
||||
// $res = $isRef;
|
||||
// }
|
||||
// $this->assertTrue($res, $message);
|
||||
// }
|
||||
}
|
@ -19,7 +19,7 @@ namespace Query\Tests;
|
||||
use DomainException;
|
||||
use Query\{ConnectionManager, QueryBuilderInterface};
|
||||
|
||||
class ConnectionManagerTest extends TestCase
|
||||
class ConnectionManagerTest extends BaseTestCase
|
||||
{
|
||||
protected static $instance;
|
||||
|
||||
@ -77,7 +77,7 @@ class ConnectionManagerTest extends TestCase
|
||||
['foo' => 'bar'],
|
||||
];
|
||||
|
||||
$this->assertEqual($expected, self::$instance->parseParams($params));
|
||||
$this->assertEquals($expected, self::$instance->parseParams($params));
|
||||
}
|
||||
|
||||
public function testConnect(): void
|
||||
@ -94,7 +94,7 @@ class ConnectionManagerTest extends TestCase
|
||||
$conn = self::$instance->connect($params);
|
||||
|
||||
// Check that the connection just made is returned from the get_connection method
|
||||
$this->assertEqual($conn, self::$instance->getConnection());
|
||||
$this->assertEquals($conn, self::$instance->getConnection());
|
||||
}
|
||||
|
||||
public function testGetConnection(): void
|
||||
@ -111,7 +111,7 @@ class ConnectionManagerTest extends TestCase
|
||||
|
||||
$conn = self::$instance->connect($params);
|
||||
|
||||
$this->assertEqual($conn, self::$instance->getConnection('conn_manager'));
|
||||
$this->assertEquals($conn, self::$instance->getConnection('conn_manager'));
|
||||
}
|
||||
}
|
||||
// End of connection_manager_test.php
|
||||
|
@ -22,10 +22,8 @@ use function regexInArray;
|
||||
|
||||
/**
|
||||
* CoreTest class - Compatibility and core functionality tests
|
||||
*
|
||||
* @extends UnitTestCase
|
||||
*/
|
||||
class CoreTest extends TestCase
|
||||
class CoreTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* TestHasPDO function.
|
||||
|
@ -79,7 +79,7 @@ INSERT INTO "create_test" ("id","key","val") VALUES (587,1,2);
|
||||
INSERT INTO "create_test" ("id","key","val") VALUES (999,'''ring''','''sale''');
|
||||
SQL;
|
||||
$expectedArray = explode("\n", $expected);
|
||||
$this->assertEqual($expectedArray, $sqlArray);
|
||||
$this->assertEquals($expectedArray, $sqlArray);
|
||||
}*/
|
||||
|
||||
public function testBackupStructure(): void
|
||||
@ -154,7 +154,7 @@ SQL;
|
||||
$expectedArray = explode("\n", $expected);
|
||||
$resultArray = explode("\n", $sql);
|
||||
|
||||
$this->assertEqual($expectedArray, $resultArray);
|
||||
$this->assertEquals($expectedArray, $resultArray);
|
||||
}
|
||||
|
||||
public function testDeleteTable(): void
|
||||
@ -254,7 +254,7 @@ SQL;
|
||||
public function testGetDBs(): void
|
||||
{
|
||||
$driverSQL = self::$db->getSql()->dbList();
|
||||
$this->assertEqual('', $driverSQL);
|
||||
$this->assertEquals('', $driverSQL);
|
||||
|
||||
$this->assertNull(self::$db->getDbs());
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ use Query\QueryParser;
|
||||
/**
|
||||
* Tests for the Query Parser
|
||||
*/
|
||||
class QueryParserTest extends TestCase
|
||||
class QueryParserTest extends BaseTestCase
|
||||
{
|
||||
/**
|
||||
* @var QueryParser
|
||||
@ -38,7 +38,7 @@ class QueryParserTest extends TestCase
|
||||
public function testGeneric(): void
|
||||
{
|
||||
$matches = $this->parser->parseJoin('table1.field1=table2.field2');
|
||||
$this->assertEqual($matches['combined'], [
|
||||
$this->assertEquals($matches['combined'], [
|
||||
'table1.field1', '=', 'table2.field2',
|
||||
]);
|
||||
}
|
||||
@ -46,7 +46,7 @@ class QueryParserTest extends TestCase
|
||||
public function testGeneric2(): void
|
||||
{
|
||||
$matches = $this->parser->parseJoin('db1.table1.field1!=db2.table2.field2');
|
||||
$this->assertEqual($matches['combined'], [
|
||||
$this->assertEquals($matches['combined'], [
|
||||
'db1.table1.field1', '!=', 'db2.table2.field2',
|
||||
]);
|
||||
}
|
||||
@ -54,7 +54,7 @@ class QueryParserTest extends TestCase
|
||||
public function testWUnderscore(): void
|
||||
{
|
||||
$matches = $this->parser->parseJoin('table_1.field1 = tab_le2.field_2');
|
||||
$this->assertEqual($matches['combined'], [
|
||||
$this->assertEquals($matches['combined'], [
|
||||
'table_1.field1', '=', 'tab_le2.field_2',
|
||||
]);
|
||||
}
|
||||
@ -62,7 +62,7 @@ class QueryParserTest extends TestCase
|
||||
public function testFunction(): void
|
||||
{
|
||||
$matches = $this->parser->parseJoin('table1.field1 > SUM(3+5)');
|
||||
$this->assertEqual($matches['combined'], [
|
||||
$this->assertEquals($matches['combined'], [
|
||||
'table1.field1', '>', 'SUM(3+5)',
|
||||
]);
|
||||
}
|
||||
|
@ -39,6 +39,6 @@ function get_json_config()
|
||||
$path = QTEST_DIR . QDS . 'db_files' . QDS . 'test_sqlite.db';
|
||||
@unlink($path);
|
||||
|
||||
require_once __DIR__ . '/TestCase.php';
|
||||
require_once __DIR__ . '/BaseTestCase.php';
|
||||
|
||||
// End of bootstrap.php
|
||||
|
164
tests/index.php
164
tests/index.php
@ -1,164 +0,0 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Query
|
||||
*
|
||||
* SQL Query Builder / Database Abstraction Layer
|
||||
*
|
||||
* PHP version 8.1
|
||||
*
|
||||
* @package Query
|
||||
* @author Timothy J. Warren <tim@timshome.page>
|
||||
* @copyright 2012 - 2023 Timothy J. Warren
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @link https://git.timshomepage.net/aviat/Query
|
||||
* @version 4.0.0
|
||||
*/
|
||||
|
||||
namespace {
|
||||
/**
|
||||
* Unit test bootstrap - Using php simpletest
|
||||
*/
|
||||
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';
|
||||
}
|
||||
|
||||
namespace Query\Tests {
|
||||
/**
|
||||
* Base class for TestCases
|
||||
*/
|
||||
abstract class TestCase extends \UnitTestCase
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$class = static::class;
|
||||
|
||||
if (PHP_SAPI !== 'cli')
|
||||
{
|
||||
echo 'Running test suite: ' . $class . '<br />';
|
||||
flush();
|
||||
}
|
||||
|
||||
if (method_exists($class, 'setupBeforeClass'))
|
||||
{
|
||||
$class::setupBeforeClass();
|
||||
}
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
$class = static::class;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
*/
|
||||
|
||||
namespace {
|
||||
function get_json_config()
|
||||
{
|
||||
$files = [
|
||||
__DIR__ . '/settings.json',
|
||||
__DIR__ . '/settings.json.dist',
|
||||
];
|
||||
|
||||
foreach ($files as $file)
|
||||
{
|
||||
if (is_file($file))
|
||||
{
|
||||
return json_decode(file_get_contents($file));
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
// Include db tests
|
||||
// Load db classes based on capability
|
||||
$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';
|
||||
|
||||
$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
|
||||
foreach ($driverTestMap as $name => $doLoad)
|
||||
{
|
||||
$path = $testPath . $name;
|
||||
|
||||
if ($doLoad)
|
||||
{
|
||||
require_once "{$path}/{$name}DriverTest.php";
|
||||
require_once "{$path}/{$name}QueryBuilderTest.php";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// End of index.php
|
Loading…
Reference in New Issue
Block a user