From b76569b81ae76b642e8a578a9e27a618e76cc9ef Mon Sep 17 00:00:00 2001 From: Timm Friebe Date: Sun, 19 Nov 2023 14:04:21 +0100 Subject: [PATCH] Migrate unit and integration tests to new testing library See xp-framework/rfc#344 --- .github/workflows/ci.yml | 4 +- ChangeLog.md | 2 +- composer.json | 2 +- .../AbstractDeadlockTest.class.php | 86 +++++++------- .../MsSQLIntegrationTest.class.php | 6 +- .../integration/MySQLDeadlockTest.class.php | 22 +--- .../MySQLIntegrationTest.class.php | 8 +- .../PostgreSQLDeadlockTest.class.php | 9 +- .../PostgreSQLIntegrationTest.class.php | 10 +- .../RdbmsIntegrationTest.class.php | 32 +++--- .../unittest/integration/SQLRunner.class.php | 8 +- .../SQLiteIntegrationTest.class.php | 11 +- .../integration/SybaseDeadlockTest.class.php | 14 +-- .../SybaseIntegrationTest.class.php | 6 +- .../php/rdbms/util/DBXmlGenerator.class.php | 6 +- .../ConfiguredConnectionManagerTest.class.php | 9 -- .../unittest/ConnectionManagerTest.class.php | 22 +++- .../php/rdbms/unittest/CriteriaTest.class.php | 2 +- src/test/php/rdbms/unittest/DBTest.class.php | 4 +- .../unittest/DBXmlGeneratorTest.class.php | 40 ++----- src/test/php/rdbms/unittest/DSNTest.class.php | 4 +- .../php/rdbms/unittest/DataSetTest.class.php | 4 +- .../unittest/DriverManagerTest.class.php | 4 +- .../php/rdbms/unittest/FinderTest.class.php | 7 +- .../rdbms/unittest/JoinIteratorTest.class.php | 4 +- .../php/rdbms/unittest/JoinPartTest.class.php | 9 +- .../unittest/JoinProcessorTest.class.php | 10 +- .../unittest/ProfilingObserverTest.class.php | 19 +-- .../rdbms/unittest/ProjectionTest.class.php | 22 ++-- .../unittest/QuerySucceededTest.class.php | 4 +- .../php/rdbms/unittest/QueryTest.class.php | 2 +- .../QueuedConnectionManagerTest.class.php | 6 +- .../RegisteredConnectionManagerTest.class.php | 6 +- .../rdbms/unittest/ResultSetTest.class.php | 6 +- .../rdbms/unittest/SQLDialectTest.class.php | 108 ++++++++++-------- .../rdbms/unittest/SQLFunctionTest.class.php | 21 +--- .../rdbms/unittest/StatementTest.class.php | 2 +- .../rdbms/unittest/TokenizerTest.class.php | 13 +-- .../DefaultMySQLTokenizerTest.class.php | 2 +- .../drivers/InterBaseTokenizerTest.class.php | 2 +- .../drivers/MssqlTokenizerTest.class.php | 2 +- .../MySQLImprovedTokenizerTest.class.php | 2 +- .../drivers/MySQLTokenizerTest.class.php | 4 +- .../drivers/PostgreSQLTokenizerTest.class.php | 4 +- .../drivers/SQLite3TokenizerTest.class.php | 2 +- .../drivers/SqlSrvTokenizerTest.class.php | 2 +- .../drivers/SybaseTokenizerTest.class.php | 18 +-- .../drivers/TDSTokenizerTest.class.php | 11 +- .../mock/RegisterMockConnection.class.php | 33 ------ .../mysql/MySqlPasswordTest.class.php | 4 +- .../MySqlxBufferedResultSetTest.class.php | 8 +- .../mysql/TableDescriptionTest.class.php | 4 +- .../sqlite3/SQLite3ConnectionTest.class.php | 6 +- .../sqlite3/SQLite3CreationTest.class.php | 7 +- .../tds/FreeTdsConfigLocationTest.class.php | 4 +- .../unittest/tds/FreeTdsLookupTest.class.php | 13 +-- .../tds/InterfacesLookupTest.class.php | 13 +-- .../unittest/tds/SqlIniLookupTest.class.php | 13 +-- .../tds/TdsBufferedResultSetTest.class.php | 13 +-- .../unittest/tds/TdsDataStreamTest.class.php | 9 +- 60 files changed, 278 insertions(+), 452 deletions(-) delete mode 100755 src/test/php/rdbms/unittest/mock/RegisterMockConnection.class.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0439b39a..fc7d3b24 100755 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -54,9 +54,9 @@ jobs: echo "vendor/autoload.php" > composer.pth - name: Run test suite - run: sh xp-run xp.unittest.TestRunner src/test/php + run: sh xp-run xp.test.Runner -r Dots src/test/php - name: SQLite integration test suite env: SQLITE_DSN: sqlite://./unittest.db - run: sh xp-run xp.unittest.TestRunner src/it/php + run: sh xp-run xp.test.Runner -r Dots src/it/php diff --git a/ChangeLog.md b/ChangeLog.md index 95ec43eb..5947b157 100755 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -12,7 +12,7 @@ RDBMS support for the XP Framework: MySQL, Sybase, MSSQL, PostgreSQL, SQLite3, I * Fixed handling of MySQL error code 1927 ("Connection was killed") (@thekid) * Overhauled test suite: - . Migrated tests to baseless + . Migrated tests to new testing library, see xp-framework/rfc#344 . Split unit and integration tests . Added PHP 8.3 and PHP 8.4 to the test matrix . Fixed integration tests to no longer reuse connections diff --git a/composer.json b/composer.json index d1c80dd8..d3775bd9 100755 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php" : ">=7.0.0" }, "require-dev" : { - "xp-framework/unittest": "^11.0 | ^10.0 | ^9.0 | ^8.0 | ^7.05" + "xp-framework/test": "^1.0" }, "autoload" : { "files" : ["src/main/php/autoload.php"] diff --git a/src/it/php/rdbms/unittest/integration/AbstractDeadlockTest.class.php b/src/it/php/rdbms/unittest/integration/AbstractDeadlockTest.class.php index 8cb22e33..22d1f0a7 100755 --- a/src/it/php/rdbms/unittest/integration/AbstractDeadlockTest.class.php +++ b/src/it/php/rdbms/unittest/integration/AbstractDeadlockTest.class.php @@ -1,47 +1,43 @@ dsn= self::testDsnSet(); + } /** * Retrieve database connection object * - * @param bool connect default TRUE - * @return rdbms.DBConnection + * @param bool $connect default TRUE + * @return rdbms.DBConnection */ protected function db($connect= true) { - with ($db= DriverManager::getConnection($this->dsn)); { - if ($connect) $db->connect(); - return $db; - } + $conn= DriverManager::getConnection($this->dsn); + $connect && $conn->connect(); + return $conn; } /** @return void */ #[Before] public function setUp() { - $env= strtoupper($this->driverName()).'_DSN'; - if (!($this->dsn= getenv($env))) { - throw new PrerequisitesNotMetError('No credentials for '.nameof($this).', use '.$env.' to set'); - } - - try { - $this->dropTables(); - $this->createTables(); - } catch (Throwable $e) { - throw new PrerequisitesNotMetError($e->getMessage(), $e); - } + $this->dropTables(); + $this->createTables(); } /** @return void */ @@ -76,11 +72,11 @@ protected function dropTables() { try { $db->query('drop table table_a'); - } catch (\rdbms\SQLStatementFailedException $ignored) {} + } catch (SQLStatementFailedException $ignored) {} try { $db->query('drop table table_b'); - } catch (\rdbms\SQLStatementFailedException $ignored) {} + } catch (SQLStatementFailedException $ignored) {} $db->close(); } @@ -91,29 +87,29 @@ protected function dropTables() { * @return lang.Process */ protected function newProcess() { - with ($rt= Runtime::getInstance()); { - $proc= $rt->newInstance( - $rt->startupOptions(), - 'class', - 'rdbms.unittest.integration.SQLRunner', - [$this->dsn] - ); - Assert::equals('! Started', $proc->out->readLine()); - return $proc; - } + $rt= Runtime::getInstance(); + $proc= $rt->newInstance( + $rt->startupOptions(), + 'class', + 'rdbms.unittest.integration.SQLRunner', + [$this->dsn] + ); + Assert::equals('! Started', $proc->out->readLine()); + return $proc; } #[Test] public function provokeDeadlock() { $a= $this->newProcess(); $b= $this->newProcess(); + $result= []; $a->in->write("update table_a set pk= pk+1\n"); $b->in->write("update table_b set pk= pk+1\n"); // Reads "+ OK", on each process - $a->out->readLine(); - $b->out->readLine(); + $result[]= $a->out->readLine(); + $result[]= $b->out->readLine(); // Now, process a hangs, waiting for lock to table_b $a->in->write("update table_b set pk= pk+1\n"); @@ -125,10 +121,8 @@ public function provokeDeadlock() { $a->in->close(); $b->in->close(); - $result= [ - $a->out->readLine(), - $b->out->readLine() - ]; + $result[]= $a->out->readLine(); + $result[]= $b->out->readLine(); sort($result); // Cleanup @@ -136,6 +130,6 @@ public function provokeDeadlock() { // Assert one process succeeds, the other catches a deadlock exception // We can't tell which one will do what, though. - Assert::equals(['+ OK', '- rdbms.SQLDeadlockException'], $result); + Assert::equals(['+ OK', '+ OK', '+ OK', '- rdbms.SQLDeadlockException'], $result); } } \ No newline at end of file diff --git a/src/it/php/rdbms/unittest/integration/MsSQLIntegrationTest.class.php b/src/it/php/rdbms/unittest/integration/MsSQLIntegrationTest.class.php index 1c0e2760..7d18f845 100755 --- a/src/it/php/rdbms/unittest/integration/MsSQLIntegrationTest.class.php +++ b/src/it/php/rdbms/unittest/integration/MsSQLIntegrationTest.class.php @@ -1,7 +1,7 @@ $errors) { - if (strstr($file, 'MySQLConnection')) { - unset(\xp::$errors[$file]); - } - } - } + protected static $DRIVER= 'mysql'; } \ No newline at end of file diff --git a/src/it/php/rdbms/unittest/integration/MySQLIntegrationTest.class.php b/src/it/php/rdbms/unittest/integration/MySQLIntegrationTest.class.php index 5050c9b9..b12a3212 100755 --- a/src/it/php/rdbms/unittest/integration/MySQLIntegrationTest.class.php +++ b/src/it/php/rdbms/unittest/integration/MySQLIntegrationTest.class.php @@ -1,13 +1,11 @@ db(); $before= $conn->query('select pg_backend_pid() as id')->next('id'); diff --git a/src/it/php/rdbms/unittest/integration/RdbmsIntegrationTest.class.php b/src/it/php/rdbms/unittest/integration/RdbmsIntegrationTest.class.php index 7e4a3a80..88c3bb9a 100755 --- a/src/it/php/rdbms/unittest/integration/RdbmsIntegrationTest.class.php +++ b/src/it/php/rdbms/unittest/integration/RdbmsIntegrationTest.class.php @@ -1,23 +1,26 @@ driverName()).'_DSN'; - if (!($this->dsn= getenv($env))) { - throw new PrerequisitesNotMetError('No credentials for '.nameof($this).', use '.$env.' to set'); - } + /** Verifies [NAME]_DSN */ + public static function testDsnSet() { + return getenv(strtoupper(static::$DRIVER).'_DSN'); + } + + /** Initialize DSN */ + public function __construct() { + $this->dsn= self::testDsnSet(); } #[After] @@ -34,13 +37,6 @@ public function disconnect() { */ protected function tableName() { return 'unittest'; } - /** - * Retrieve driver name - * - * @return string - */ - abstract protected function driverName(); - /** * Retrieve database connection object * diff --git a/src/it/php/rdbms/unittest/integration/SQLRunner.class.php b/src/it/php/rdbms/unittest/integration/SQLRunner.class.php index 06695442..001b822d 100755 --- a/src/it/php/rdbms/unittest/integration/SQLRunner.class.php +++ b/src/it/php/rdbms/unittest/integration/SQLRunner.class.php @@ -1,12 +1,12 @@ connect(); - $tran= $db->begin(new \rdbms\Transaction('process')); + $tran= $db->begin(new Transaction('process')); Console::$out->writeLine('! Started'); while ($sql= Console::$in->readLine()) { @@ -28,7 +28,7 @@ public static function main(array $args) { } $tran->commit(); - } catch (\rdbms\SQLException $e) { + } catch (SQLException $e) { Console::$out->writeLine('- ', nameof($e)); } } diff --git a/src/it/php/rdbms/unittest/integration/SQLiteIntegrationTest.class.php b/src/it/php/rdbms/unittest/integration/SQLiteIntegrationTest.class.php index d1adf1bc..85df54c3 100755 --- a/src/it/php/rdbms/unittest/integration/SQLiteIntegrationTest.class.php +++ b/src/it/php/rdbms/unittest/integration/SQLiteIntegrationTest.class.php @@ -1,18 +1,11 @@ doc->root()->setAttribute('created_at', date('r')); - $g->doc->root()->setAttribute('created_by', System::getProperty('user.name')); + $g->doc->root()->setAttribute('created_by', getenv('USER')); $g->doc->root()->addChild(new \xml\Node('table', null, [ 'name' => $table->name, diff --git a/src/test/php/rdbms/unittest/ConfiguredConnectionManagerTest.class.php b/src/test/php/rdbms/unittest/ConfiguredConnectionManagerTest.class.php index 819039b7..01cfb18d 100755 --- a/src/test/php/rdbms/unittest/ConfiguredConnectionManagerTest.class.php +++ b/src/test/php/rdbms/unittest/ConfiguredConnectionManagerTest.class.php @@ -2,17 +2,8 @@ use io\streams\MemoryInputStream; use rdbms\ConnectionManager; -use rdbms\unittest\mock\RegisterMockConnection; -use unittest\Assert; use util\Properties; -/** - * Tests for configured connection managers - * - * @see xp://rdbms.ConnectionManager#configure - * @see xp://net.xp_framework.unittest.rdbms.ConnectionManagerTest - */ -#[Action(eval: 'new RegisterMockConnection()')] class ConfiguredConnectionManagerTest extends ConnectionManagerTest { /** diff --git a/src/test/php/rdbms/unittest/ConnectionManagerTest.class.php b/src/test/php/rdbms/unittest/ConnectionManagerTest.class.php index 251a15a1..8d61caeb 100755 --- a/src/test/php/rdbms/unittest/ConnectionManagerTest.class.php +++ b/src/test/php/rdbms/unittest/ConnectionManagerTest.class.php @@ -1,7 +1,15 @@ pool= []; diff --git a/src/test/php/rdbms/unittest/CriteriaTest.class.php b/src/test/php/rdbms/unittest/CriteriaTest.class.php index 0d609b7a..d7e1bffd 100755 --- a/src/test/php/rdbms/unittest/CriteriaTest.class.php +++ b/src/test/php/rdbms/unittest/CriteriaTest.class.php @@ -5,7 +5,7 @@ use rdbms\unittest\dataset\Job; use rdbms\unittest\mock\MockConnection; use rdbms\{Criteria, DriverManager, SQLStateException}; -use unittest\{Assert, After, Before, Expect, Test}; +use test\{After, Assert, Before, Expect, Test}; class CriteriaTest { public $conn, $peer; diff --git a/src/test/php/rdbms/unittest/DBTest.class.php b/src/test/php/rdbms/unittest/DBTest.class.php index ac8d117f..54533543 100755 --- a/src/test/php/rdbms/unittest/DBTest.class.php +++ b/src/test/php/rdbms/unittest/DBTest.class.php @@ -1,9 +1,9 @@ newTable('deviceinfo', [ - 'deviceinfo_id' => [DB_ATTRTYPE_INT, 255], - 'serial_number' => [DB_ATTRTYPE_INT, 16], - 'text' => [DB_ATTRTYPE_TEXT, 255] + 'deviceinfo_id' => [DBTableAttribute::DB_ATTRTYPE_INT, 255], + 'serial_number' => [DBTableAttribute::DB_ATTRTYPE_INT, 16], + 'text' => [DBTableAttribute::DB_ATTRTYPE_TEXT, 255] ]), 'localhost', 'FOOBAR' @@ -51,7 +35,7 @@ public function setUp() { public function newTable($name, $attr) { $t= new DBTable($name); foreach ($attr as $key => $definitions) { - $t->attributes[]= new \rdbms\DBTableAttribute( + $t->attributes[]= new DBTableAttribute( $key, $definitions[0], // Type true, diff --git a/src/test/php/rdbms/unittest/DSNTest.class.php b/src/test/php/rdbms/unittest/DSNTest.class.php index 7588fe89..6c4395a9 100755 --- a/src/test/php/rdbms/unittest/DSNTest.class.php +++ b/src/test/php/rdbms/unittest/DSNTest.class.php @@ -2,8 +2,8 @@ use lang\FormatException; use rdbms\DSN; -use unittest\Assert; -use unittest\{Expect, Test}; +use test\Assert; +use test\{Expect, Test}; /** * Tests the DSN class diff --git a/src/test/php/rdbms/unittest/DataSetTest.class.php b/src/test/php/rdbms/unittest/DataSetTest.class.php index c64d6b70..2e62902d 100755 --- a/src/test/php/rdbms/unittest/DataSetTest.class.php +++ b/src/test/php/rdbms/unittest/DataSetTest.class.php @@ -2,9 +2,9 @@ use lang\{IllegalArgumentException, XPClass}; use rdbms\unittest\dataset\Job; -use rdbms\unittest\mock\{MockResultSet, MockConnection}; +use rdbms\unittest\mock\{MockConnection, MockResultSet}; use rdbms\{Column, DBEvent, DriverManager, Peer, ResultIterator, SQLException, Statement}; -use unittest\{Assert, After, Before, Expect, Test}; +use test\{After, Assert, Before, Expect, Test}; use util\log\BoundLogObserver; use util\{Date, NoSuchElementException}; diff --git a/src/test/php/rdbms/unittest/DriverManagerTest.class.php b/src/test/php/rdbms/unittest/DriverManagerTest.class.php index f727beaf..9e24b041 100755 --- a/src/test/php/rdbms/unittest/DriverManagerTest.class.php +++ b/src/test/php/rdbms/unittest/DriverManagerTest.class.php @@ -2,8 +2,8 @@ use lang\{FormatException, IllegalArgumentException}; use rdbms\{DriverManager, DriverNotSupportedException}; -use unittest\Assert; -use unittest\{Expect, Test}; +use test\Assert; +use test\{Expect, Test}; /** * TestCase diff --git a/src/test/php/rdbms/unittest/FinderTest.class.php b/src/test/php/rdbms/unittest/FinderTest.class.php index 7ae441fc..573c52ea 100755 --- a/src/test/php/rdbms/unittest/FinderTest.class.php +++ b/src/test/php/rdbms/unittest/FinderTest.class.php @@ -3,10 +3,9 @@ use lang\{IllegalArgumentException, MethodNotImplementedException, XPClass}; use rdbms\finder\{FinderException, FinderMethod, GenericFinder, NoSuchEntityException}; use rdbms\unittest\dataset\{Job, JobFinder}; -use rdbms\unittest\mock\{MockResultSet, MockConnection}; +use rdbms\unittest\mock\{MockConnection, MockResultSet}; use rdbms\{DriverManager, Peer, SQLExpression}; -use unittest\Assert; -use unittest\{Expect, Test, TestCase}; +use test\{Assert, Before, After, Expect, Test}; class FinderTest { protected $fixture; @@ -317,7 +316,7 @@ public function findAllWrapsSQLException() { $this->fixture->findAll(new \rdbms\Criteria()); } - #[Test, Expect(['class' => FinderException::class, 'withMessage' => '/No such method nonExistantMethod/'])] + #[Test, Expect(class: FinderException::class, message: '/No such method nonExistantMethod/')] public function fluentNonExistantFinder() { $this->fixture->findAll()->nonExistantMethod(new \rdbms\Criteria()); } diff --git a/src/test/php/rdbms/unittest/JoinIteratorTest.class.php b/src/test/php/rdbms/unittest/JoinIteratorTest.class.php index 3cf9946b..b0c54279 100755 --- a/src/test/php/rdbms/unittest/JoinIteratorTest.class.php +++ b/src/test/php/rdbms/unittest/JoinIteratorTest.class.php @@ -5,8 +5,8 @@ use rdbms\unittest\dataset\{Job, Person}; use rdbms\unittest\mock\MockResultSet; use rdbms\{CachedResults, ConnectionManager, Criteria, DSN}; -use unittest\Assert; -use unittest\{BeforeClass, Expect, Test, TestCase}; +use test\Assert; +use test\{BeforeClass, Expect, Test, TestCase}; use util\{Date, NoSuchElementException}; /** diff --git a/src/test/php/rdbms/unittest/JoinPartTest.class.php b/src/test/php/rdbms/unittest/JoinPartTest.class.php index e9c78dce..a75a540e 100755 --- a/src/test/php/rdbms/unittest/JoinPartTest.class.php +++ b/src/test/php/rdbms/unittest/JoinPartTest.class.php @@ -4,8 +4,7 @@ use rdbms\mysql\MySQLConnection; use rdbms\unittest\dataset\{Department, Job, Person}; use rdbms\{Criteria, DSN}; -use unittest\Assert; -use unittest\{Test, TestCase}; +use test\{Assert, Before, Test}; /** * Test JoinPart class @@ -17,12 +16,8 @@ * @see xp://rdbms.Criteria */ class JoinPartTest { - public $conn= null; - public $peer= null; + public $conn, $peer= null; - /** - * Setup test - */ #[Before] public function setUp() { $this->conn= new MySQLConnection(new DSN('mysql://localhost:3306/')); diff --git a/src/test/php/rdbms/unittest/JoinProcessorTest.class.php b/src/test/php/rdbms/unittest/JoinProcessorTest.class.php index b162f19c..36a650e8 100755 --- a/src/test/php/rdbms/unittest/JoinProcessorTest.class.php +++ b/src/test/php/rdbms/unittest/JoinProcessorTest.class.php @@ -4,9 +4,8 @@ use rdbms\join\JoinProcessor; use rdbms\mysql\MySQLConnection; use rdbms\unittest\dataset\Job; -use rdbms\{Criteria, DriverManager}; -use unittest\Assert; -use unittest\{Expect, Test, TestCase}; +use rdbms\{Criteria, DriverManager, DSN}; +use test\{Assert, Before, Expect, Test, TestCase}; /** * Test JoinProcessor class @@ -19,12 +18,9 @@ */ class JoinProcessorTest { - /** - * Make Job's peer use mysql - */ #[Before] public function setUp() { - Job::getPeer()->setConnection(new MySQLConnection(new \rdbms\DSN('mysql://localhost:3306/'))); + Job::getPeer()->setConnection(new MySQLConnection(new DSN('mysql://localhost:3306/'))); } #[Test] diff --git a/src/test/php/rdbms/unittest/ProfilingObserverTest.class.php b/src/test/php/rdbms/unittest/ProfilingObserverTest.class.php index f59fd75b..2cc636c9 100755 --- a/src/test/php/rdbms/unittest/ProfilingObserverTest.class.php +++ b/src/test/php/rdbms/unittest/ProfilingObserverTest.class.php @@ -3,24 +3,12 @@ use lang\IllegalArgumentException; use rdbms\sqlite3\SQLite3Connection; use rdbms\{DBEvent, DSN, ProfilingObserver}; -use unittest\Assert; -use unittest\{Expect, Ignore, Test, TestCase, Values}; +use test\{Assert, Before, Expect, Ignore, Test, Values}; use util\log\{BufferedAppender, LogCategory}; -/** - * Testcase for the profiling observer class - * - * @see xp://rdbms.ProfilingObserver - */ class ProfilingObserverTest { private $cat; - /** @return void */ - #[Before] - public function setUp() { - $this->cat= new LogCategory('test'); - } - /** @return rdbms.DBConnection */ private function conn() { return new SQLite3Connection(new DSN('sqlite+3:///foo.sqlite')); @@ -41,6 +29,11 @@ private function observerWithSelect() { return $o; } + #[Before] + public function setUp() { + $this->cat= new LogCategory('test'); + } + #[Test] public function create() { new ProfilingObserver($this->cat); diff --git a/src/test/php/rdbms/unittest/ProjectionTest.class.php b/src/test/php/rdbms/unittest/ProjectionTest.class.php index 6db0b487..11e09874 100755 --- a/src/test/php/rdbms/unittest/ProjectionTest.class.php +++ b/src/test/php/rdbms/unittest/ProjectionTest.class.php @@ -1,24 +1,30 @@ syconn= new SybaseConnection(new \rdbms\DSN('sybase://localhost:1999/')); diff --git a/src/test/php/rdbms/unittest/QuerySucceededTest.class.php b/src/test/php/rdbms/unittest/QuerySucceededTest.class.php index 26d27353..bb0e1ea7 100755 --- a/src/test/php/rdbms/unittest/QuerySucceededTest.class.php +++ b/src/test/php/rdbms/unittest/QuerySucceededTest.class.php @@ -1,8 +1,8 @@ 1], $q->next()); } - #[Test, Values('fixtures')] + #[Test, Values(from: 'fixtures')] public function can_be_used_in_foreach($records) { $q= self::$resultSet->newInstance($records); Assert::equals($records, iterator_to_array($q)); } - #[Test, Values('fixtures')] + #[Test, Values(from: 'fixtures')] public function can_be_iterated_twice($records) { $q= self::$resultSet->newInstance($records); iterator_to_array($q); diff --git a/src/test/php/rdbms/unittest/SQLDialectTest.class.php b/src/test/php/rdbms/unittest/SQLDialectTest.class.php index 429fc143..bc95b4cd 100755 --- a/src/test/php/rdbms/unittest/SQLDialectTest.class.php +++ b/src/test/php/rdbms/unittest/SQLDialectTest.class.php @@ -5,104 +5,120 @@ use rdbms\join\{JoinRelation, JoinTable}; use rdbms\mysql\MySQLConnection; use rdbms\sybase\SybaseConnection; -use rdbms\{SQLDialect, SQLFunction}; -use unittest\{Assert, Before, Expect, Test, Values}; +use rdbms\{SQLDialect, SQLFunction, DSN}; +use test\{Assert, Before, Expect, Test, Values}; use util\Date; class SQLDialectTest { - const SYBASE= 'sybase'; - const MYSQL= 'mysql'; - - protected $conn= []; + protected $dialects; #[Before] public function conn() { - $this->conn[self::MYSQL]= new MySQLConnection(new \rdbms\DSN('mysql://localhost:3306/')); - $this->conn[self::SYBASE]= new SybaseConnection(new \rdbms\DSN('sybase://localhost:1999/')); + $fixture= [ + 'mysql' => new MySQLConnection(new DSN('mysql://localhost:3306/')), + 'sybase' => new SybaseConnection(new DSN('sybase://localhost:1999/')), + ]; + foreach ($fixture as $name => $conn) { + $this->dialects[$name]= [$conn->getFormatter()->dialect, $name]; + } } - /** - * Provides values for next tests - * - * @return var[] - */ + /** @return iterable */ public function dialects() { - $r= []; - foreach ($this->conn as $name => $conn) { - $r[]= [$conn->getFormatter()->dialect, $name]; - } - return $r; + yield from $this->dialects; } - #[Test, Values('dialects')] + #[Test, Values(from: 'dialects')] public function dialect_member($dialect) { Assert::instance(SQLDialect::class, $dialect); } - #[Test, Values('dialects')] + #[Test, Values(from: 'dialects')] public function pi_function($dialect) { Assert::equals('pi()', $dialect->formatFunction(new SQLFunction('pi', '%s'))); } - #[Test, Values('dialects'), Expect(IllegalArgumentException::class)] + #[Test, Values(from: 'dialects'), Expect(IllegalArgumentException::class)] public function unknown_function($dialect) { $dialect->formatFunction(new SQLFunction('foo', '%s', [1, 2, 3, 4, 5])); } - #[Test, Values('dialects')] + #[Test, Values(from: 'dialects')] public function month_datepart($dialect) { Assert::equals('month', $dialect->datepart('month')); } - #[Test, Values('dialects'), Expect(IllegalArgumentException::class)] + #[Test, Values(from: 'dialects'), Expect(IllegalArgumentException::class)] public function unknown_datepart($dialect) { $dialect->datepart('month_foo_bar_buz'); } - #[Test, Values('dialects')] + #[Test, Values(from: 'dialects')] public function int_datatype($dialect) { Assert::equals('int', $dialect->datatype('int')); } - #[Test, Values('dialects'), Expect(IllegalArgumentException::class)] + #[Test, Values(from: 'dialects'), Expect(IllegalArgumentException::class)] public function unknown_datatype($dialect) { $dialect->datatype('int_foo_bar_buz'); } - #[Test, Values('dialects'), Expect(IllegalArgumentException::class)] + #[Test, Values(from: 'dialects'), Expect(IllegalArgumentException::class)] public function join_by_empty($dialect) { $dialect->makeJoinBy([]); } - #[Test, Values('dialects')] - public function join_two_tables($dialect, $name) { - static $asserts= [ - self::MYSQL => 'table0 as t0 LEFT OUTER JOIN table1 as t1 on (t0.id1_1 = t0.id1_1 and t0.id1_2 = t0.id1_2) where ', - self::SYBASE => 'table0 as t0, table1 as t1 where t0.id1_1 *= t0.id1_1 and t0.id1_2 *= t0.id1_2 and ', - ]; + #[Test] + public function join_two_tables_mysql() { + Assert::equals( + 'table0 as t0 LEFT OUTER JOIN table1 as t1 on (t0.id1_1 = t0.id1_1 and t0.id1_2 = t0.id1_2) where ', + $this->dialects['mysql'][0]->makeJoinBy([new JoinRelation( + new JoinTable('table0', 't0'), + new JoinTable('table1', 't1'), + ['t0.id1_1 = t0.id1_1', 't0.id1_2 = t0.id1_2'] + )]) + ); + } + #[Test] + public function join_two_tables_sybase() { + Assert::equals( + 'table0 as t0, table1 as t1 where t0.id1_1 *= t0.id1_1 and t0.id1_2 *= t0.id1_2 and ', + $this->dialects['sybase'][0]->makeJoinBy([new JoinRelation( + new JoinTable('table0', 't0'), + new JoinTable('table1', 't1'), + ['t0.id1_1 = t0.id1_1', 't0.id1_2 = t0.id1_2'] + )]) + ); + } + + #[Test] + public function join_three_tables_mysql() { $t0= new JoinTable('table0', 't0'); $t1= new JoinTable('table1', 't1'); + $t2= new JoinTable('table2', 't2'); - Assert::equals($asserts[$name], $dialect->makeJoinBy([ - new JoinRelation($t0, $t1, ['t0.id1_1 = t0.id1_1', 't0.id1_2 = t0.id1_2']) - ])); + Assert::equals( + 'table0 as t0 LEFT OUTER JOIN table1 as t1 on (t0.id1_1 = t0.id1_1 and t0.id1_2 = t0.id1_2) LEFT JOIN table2 as t2 on (t1.id2_1 = t2.id2_1) where ', + $this->dialects['mysql'][0]->makeJoinBy([ + new JoinRelation($t0, $t1, ['t0.id1_1 = t0.id1_1', 't0.id1_2 = t0.id1_2']), + new JoinRelation($t1, $t2, ['t1.id2_1 = t2.id2_1']) + ]) + ); } - #[Test, Values('dialects')] - public function join_three_tables($dialect, $name) { - static $asserts= [ - self::MYSQL => 'table0 as t0 LEFT OUTER JOIN table1 as t1 on (t0.id1_1 = t0.id1_1 and t0.id1_2 = t0.id1_2) LEFT JOIN table2 as t2 on (t1.id2_1 = t2.id2_1) where ', - self::SYBASE => 'table0 as t0, table1 as t1, table2 as t2 where t0.id1_1 *= t0.id1_1 and t0.id1_2 *= t0.id1_2 and t1.id2_1 *= t2.id2_1 and ', - ]; - + #[Test] + public function join_three_tables_sybase() { $t0= new JoinTable('table0', 't0'); $t1= new JoinTable('table1', 't1'); $t2= new JoinTable('table2', 't2'); - Assert::equals($asserts[$name], $dialect->makeJoinBy([ - new JoinRelation($t0, $t1, ['t0.id1_1 = t0.id1_1', 't0.id1_2 = t0.id1_2']), - new JoinRelation($t1, $t2, ['t1.id2_1 = t2.id2_1']) - ])); + Assert::equals( + 'table0 as t0, table1 as t1, table2 as t2 where t0.id1_1 *= t0.id1_1 and t0.id1_2 *= t0.id1_2 and t1.id2_1 *= t2.id2_1 and ', + $this->dialects['sybase'][0]->makeJoinBy([ + new JoinRelation($t0, $t1, ['t0.id1_1 = t0.id1_1', 't0.id1_2 = t0.id1_2']), + new JoinRelation($t1, $t2, ['t1.id2_1 = t2.id2_1']) + ]) + ); } } \ No newline at end of file diff --git a/src/test/php/rdbms/unittest/SQLFunctionTest.class.php b/src/test/php/rdbms/unittest/SQLFunctionTest.class.php index bc8ae36c..452a7ba6 100755 --- a/src/test/php/rdbms/unittest/SQLFunctionTest.class.php +++ b/src/test/php/rdbms/unittest/SQLFunctionTest.class.php @@ -7,27 +7,12 @@ use rdbms\sybase\SybaseConnection; use rdbms\unittest\dataset\Job; use rdbms\{Criteria, SQLFunctions}; -use unittest\Assert; -use unittest\{Test, TestCase}; +use test\{Assert, Before, Test}; use util\Date; -/** - * TestCase - * - * @see xp://rdbms.SQLFunction - */ class SQLFunctionTest { - public - $syconn = null, - $myconn = null, - $sqconn = null, - $pgconn = null, - $peer = null; - - /** - * Sets up a Database Object for the test - * - */ + public $syconn, $myconn, $sqconn, $pgconn, $peer; + #[Before] public function setUp() { $this->syconn= new SybaseConnection(new \rdbms\DSN('sybase://localhost:1999/')); diff --git a/src/test/php/rdbms/unittest/StatementTest.class.php b/src/test/php/rdbms/unittest/StatementTest.class.php index 58c670a9..5dea2d75 100755 --- a/src/test/php/rdbms/unittest/StatementTest.class.php +++ b/src/test/php/rdbms/unittest/StatementTest.class.php @@ -4,7 +4,7 @@ use rdbms\unittest\dataset\Job; use rdbms\unittest\mock\MockConnection; use rdbms\{DriverManager, Statement}; -use unittest\{Assert, Before, After, Test}; +use test\{After, Assert, Before, Test}; class StatementTest { public $conn, $peer; diff --git a/src/test/php/rdbms/unittest/TokenizerTest.class.php b/src/test/php/rdbms/unittest/TokenizerTest.class.php index f31b5ba1..e55d116c 100755 --- a/src/test/php/rdbms/unittest/TokenizerTest.class.php +++ b/src/test/php/rdbms/unittest/TokenizerTest.class.php @@ -1,16 +1,10 @@ fixture= $this->fixture(); diff --git a/src/test/php/rdbms/unittest/drivers/DefaultMySQLTokenizerTest.class.php b/src/test/php/rdbms/unittest/drivers/DefaultMySQLTokenizerTest.class.php index b228e733..87d54aec 100755 --- a/src/test/php/rdbms/unittest/drivers/DefaultMySQLTokenizerTest.class.php +++ b/src/test/php/rdbms/unittest/drivers/DefaultMySQLTokenizerTest.class.php @@ -1,6 +1,6 @@ next()); } - #[Test, Expect(['class' => SQLException::class, 'withMessage' => 'Cannot seek to offset 1, out of bounds'])] + #[Test, Expect(class: SQLException::class, message: 'Cannot seek to offset 1, out of bounds')] public function seek_to_offset_exceeding_length() { $fixture= $this->newResultSet([])->seek(1); } - #[Test, Expect(['class' => SQLException::class, 'withMessage' => 'Cannot seek to offset -1, out of bounds'])] + #[Test, Expect(class: SQLException::class, message: 'Cannot seek to offset -1, out of bounds')] public function seek_to_negative_offset() { $fixture= $this->newResultSet([])->seek(-1); } - #[Test, Expect(['class' => SQLException::class, 'withMessage' => 'Cannot seek to offset 0, out of bounds'])] + #[Test, Expect(class: SQLException::class, message: 'Cannot seek to offset 0, out of bounds')] public function seek_to_zero_offset_on_empty() { $fixture= $this->newResultSet([])->seek(0); } diff --git a/src/test/php/rdbms/unittest/mysql/TableDescriptionTest.class.php b/src/test/php/rdbms/unittest/mysql/TableDescriptionTest.class.php index bdad8fb7..916c6a61 100755 --- a/src/test/php/rdbms/unittest/mysql/TableDescriptionTest.class.php +++ b/src/test/php/rdbms/unittest/mysql/TableDescriptionTest.class.php @@ -2,8 +2,8 @@ use rdbms\mysql\MySQLDBAdapter; use rdbms\{DBTableAttribute, FieldType}; -use unittest\Assert; -use unittest\Test; +use test\Assert; +use test\Test; /** * TestCase diff --git a/src/test/php/rdbms/unittest/sqlite3/SQLite3ConnectionTest.class.php b/src/test/php/rdbms/unittest/sqlite3/SQLite3ConnectionTest.class.php index ce7a31bf..7ab63e8b 100755 --- a/src/test/php/rdbms/unittest/sqlite3/SQLite3ConnectionTest.class.php +++ b/src/test/php/rdbms/unittest/sqlite3/SQLite3ConnectionTest.class.php @@ -3,10 +3,10 @@ use lang\IllegalStateException; use rdbms\sqlite3\{SQLite3Connection, SQLite3ResultSet}; use rdbms\{DSN, SQLStateException, SQLStatementFailedException}; -use unittest\actions\ExtensionAvailable; -use unittest\{Assert, After, Expect, Test}; +use test\verify\Runtime; +use test\{After, Assert, Expect, Test}; -#[Action(eval: 'new ExtensionAvailable("sqlite3")')] +#[Runtime(extensions: ['sqlite3'])] class SQLite3ConnectionTest { private $close= []; diff --git a/src/test/php/rdbms/unittest/sqlite3/SQLite3CreationTest.class.php b/src/test/php/rdbms/unittest/sqlite3/SQLite3CreationTest.class.php index 5578f029..99bed10f 100755 --- a/src/test/php/rdbms/unittest/sqlite3/SQLite3CreationTest.class.php +++ b/src/test/php/rdbms/unittest/sqlite3/SQLite3CreationTest.class.php @@ -2,9 +2,8 @@ use rdbms\sqlite3\SQLite3Connection; use rdbms\{DSN, SQLConnectException}; -use unittest\Assert; -use unittest\actions\ExtensionAvailable; -use unittest\{Expect, Test, TestCase}; +use test\verify\Runtime; +use test\{Assert, Expect, Test}; /** * Testcase for rdbms.sqlite3.SQLite3Connection @@ -14,7 +13,7 @@ * @see https://github.com/xp-framework/xp-framework/issues/111 * @see https://bugs.php.net/bug.php?id=55154 */ -#[Action(eval: 'new ExtensionAvailable("sqlite3")')] +#[Runtime(extensions: ['sqlite3'])] class SQLite3CreationTest { #[Test] diff --git a/src/test/php/rdbms/unittest/tds/FreeTdsConfigLocationTest.class.php b/src/test/php/rdbms/unittest/tds/FreeTdsConfigLocationTest.class.php index 3a8c5142..31de3909 100755 --- a/src/test/php/rdbms/unittest/tds/FreeTdsConfigLocationTest.class.php +++ b/src/test/php/rdbms/unittest/tds/FreeTdsConfigLocationTest.class.php @@ -3,8 +3,8 @@ use io\File; use rdbms\DSN; use rdbms\tds\FreeTdsLookup; -use unittest\Assert; -use unittest\Test; +use test\Assert; +use test\Test; /** * TestCase diff --git a/src/test/php/rdbms/unittest/tds/FreeTdsLookupTest.class.php b/src/test/php/rdbms/unittest/tds/FreeTdsLookupTest.class.php index bb29883a..5232e272 100755 --- a/src/test/php/rdbms/unittest/tds/FreeTdsLookupTest.class.php +++ b/src/test/php/rdbms/unittest/tds/FreeTdsLookupTest.class.php @@ -2,20 +2,11 @@ use rdbms\DSN; use rdbms\tds\FreeTdsLookup; -use unittest\Assert; -use unittest\Test; +use test\{Assert, Before, Test}; -/** - * TestCase - * - * @see xp://rdbms.tds.FreeTdsLookup - */ class FreeTdsLookupTest { - protected $fixture= null; + protected $fixture; - /** - * Sets up test case - */ #[Before] public function setUp() { $this->fixture= new FreeTdsLookup(typeof($this)->getPackage()->getResourceAsStream('freetds.conf')); diff --git a/src/test/php/rdbms/unittest/tds/InterfacesLookupTest.class.php b/src/test/php/rdbms/unittest/tds/InterfacesLookupTest.class.php index 4caf9411..d32c69d0 100755 --- a/src/test/php/rdbms/unittest/tds/InterfacesLookupTest.class.php +++ b/src/test/php/rdbms/unittest/tds/InterfacesLookupTest.class.php @@ -2,20 +2,11 @@ use rdbms\DSN; use rdbms\tds\InterfacesLookup; -use unittest\Assert; -use unittest\Test; +use test\{Assert, Before, Test}; -/** - * TestCase - * - * @see xp://rdbms.tds.InterfacesLookup - */ class InterfacesLookupTest { - protected $fixture= null; + protected $fixture; - /** - * Sets up test case - */ #[Before] public function setUp() { $this->fixture= new InterfacesLookup(typeof($this)->getPackage()->getResourceAsStream('interfaces')); diff --git a/src/test/php/rdbms/unittest/tds/SqlIniLookupTest.class.php b/src/test/php/rdbms/unittest/tds/SqlIniLookupTest.class.php index 06d8c536..9160c546 100755 --- a/src/test/php/rdbms/unittest/tds/SqlIniLookupTest.class.php +++ b/src/test/php/rdbms/unittest/tds/SqlIniLookupTest.class.php @@ -2,20 +2,11 @@ use rdbms\DSN; use rdbms\tds\SqlIniLookup; -use unittest\Assert; -use unittest\Test; +use test\{Assert, Before, Test}; -/** - * TestCase - * - * @see xp://rdbms.tds.SqlIniLookup - */ class SqlIniLookupTest { - protected $fixture= null; + protected $fixture; - /** - * Sets up test case - */ #[Before] public function setUp() { $this->fixture= new SqlIniLookup(typeof($this)->getPackage()->getResourceAsStream('sql.ini')); diff --git a/src/test/php/rdbms/unittest/tds/TdsBufferedResultSetTest.class.php b/src/test/php/rdbms/unittest/tds/TdsBufferedResultSetTest.class.php index f87e6f81..b06a2dd4 100755 --- a/src/test/php/rdbms/unittest/tds/TdsBufferedResultSetTest.class.php +++ b/src/test/php/rdbms/unittest/tds/TdsBufferedResultSetTest.class.php @@ -3,15 +3,14 @@ use lang\ClassLoader; use rdbms\SQLException; use rdbms\tds\{TdsBufferedResultSet, TdsProtocol}; -use unittest\{Assert, Before, Expect, Test}; +use test\{Assert, Before, Expect, Test}; class TdsBufferedResultSetTest { protected static $proto; #[Before] - public static function mockProtocol() { - $parent= class_exists('\\lang\\Object', false) ? 'lang.Object' : null; - self::$proto= ClassLoader::defineClass('rdbms.unittest.tds.MockTdsProtocol', $parent, [], '{ + public function mockProtocol() { + self::$proto= ClassLoader::defineClass('rdbms.unittest.tds.MockTdsProtocol', null, [], '{ private $records= []; public function __construct($records) { @@ -158,17 +157,17 @@ public function seek_to_1() { Assert::equals($records[1], $fixture->next()); } - #[Test, Expect(['class' => SQLException::class, 'withMessage' => 'Cannot seek to offset 1, out of bounds'])] + #[Test, Expect(class: SQLException::class, message: 'Cannot seek to offset 1, out of bounds')] public function seek_to_offset_exceeding_length() { $fixture= $this->newResultSet([])->seek(1); } - #[Test, Expect(['class' => SQLException::class, 'withMessage' => 'Cannot seek to offset -1, out of bounds'])] + #[Test, Expect(class: SQLException::class, message: 'Cannot seek to offset -1, out of bounds')] public function seek_to_negative_offset() { $fixture= $this->newResultSet([])->seek(-1); } - #[Test, Expect(['class' => SQLException::class, 'withMessage' => 'Cannot seek to offset 0, out of bounds'])] + #[Test, Expect(class: SQLException::class, message: 'Cannot seek to offset 0, out of bounds')] public function seek_to_zero_offset_on_empty() { $fixture= $this->newResultSet([])->seek(0); } diff --git a/src/test/php/rdbms/unittest/tds/TdsDataStreamTest.class.php b/src/test/php/rdbms/unittest/tds/TdsDataStreamTest.class.php index 67bae3fc..93fd8027 100755 --- a/src/test/php/rdbms/unittest/tds/TdsDataStreamTest.class.php +++ b/src/test/php/rdbms/unittest/tds/TdsDataStreamTest.class.php @@ -3,14 +3,9 @@ use lang\{ClassLoader, IllegalArgumentException}; use peer\Socket; use rdbms\tds\{TdsDataStream, TdsProtocolException}; -use unittest\{Assert, Before, Expect, Test}; +use test\{Assert, Before, Expect, Test}; use util\Bytes; -/** - * TestCase - * - * @see xp://rdbms.tds.TdsDataStream - */ class TdsDataStreamTest { protected static $sock; @@ -187,7 +182,7 @@ public function beginDoesNotDiscardFirstBytes() { Assert::equals("\xA2", $str->getToken()); } - #[Test, Expect(['class' => IllegalArgumentException::class, 'withMessage' => '/must be at least 9/'])] + #[Test, Expect(class: IllegalArgumentException::class, message: '/must be at least 9/')] public function illegalPacketSize() { $this->newDataStream('', 1); }