diff --git a/src/test/php/rdbms/unittest/integration/MsSQLIntegrationTest.class.php b/src/test/php/rdbms/unittest/integration/MsSQLIntegrationTest.class.php index 42b0ef49..573fdf2d 100755 --- a/src/test/php/rdbms/unittest/integration/MsSQLIntegrationTest.class.php +++ b/src/test/php/rdbms/unittest/integration/MsSQLIntegrationTest.class.php @@ -21,7 +21,7 @@ class MsSQLIntegrationTest extends RdbmsIntegrationTest { * @return void */ #[Before] - public static function setMinimumServerSeverity() { + public function setMinimumServerSeverity() { if (function_exists('mssql_min_message_severity')) { mssql_min_message_severity(12); } diff --git a/src/test/php/rdbms/unittest/integration/RdbmsIntegrationTest.class.php b/src/test/php/rdbms/unittest/integration/RdbmsIntegrationTest.class.php index b7fc62af..96fc5a75 100755 --- a/src/test/php/rdbms/unittest/integration/RdbmsIntegrationTest.class.php +++ b/src/test/php/rdbms/unittest/integration/RdbmsIntegrationTest.class.php @@ -2,35 +2,29 @@ use lang\{MethodNotImplementedException, Throwable}; use rdbms\{DBEvent, DSN, DriverManager, ResultSet, SQLConnectException, SQLException, SQLStateException, SQLStatementFailedException}; -use unittest\Assert; -use unittest\{Expect, PrerequisitesNotMetError, Test, TestCase}; +use unittest\{Assert, Before, Expect, PrerequisitesNotMetError, Test}; use util\{Bytes, Date, Observer}; /** * Base class for all RDBMS integration tests */ abstract class RdbmsIntegrationTest { - private $dsn, $conn; + private $dsn; + private $close= []; - /** @return void */ #[Before] - public function setUp() { + public function verify() { $env= strtoupper($this->driverName()).'_DSN'; if (!($this->dsn= getenv($env))) { throw new PrerequisitesNotMetError('No credentials for '.nameof($this).', use '.$env.' to set'); } - - try { - $this->conn= DriverManager::getConnection($this->dsn); - } catch (Throwable $t) { - throw new PrerequisitesNotMetError($t->getMessage(), $t); - } } - /** @return void */ #[After] - public function tearDown() { - $this->conn && $this->conn->close(); + public function disconnect() { + foreach ($this->close as $conn) { + $conn->close(); + } } /** @@ -54,8 +48,9 @@ abstract protected function driverName(); * @return rdbms.DBConnection */ protected function db($connect= true) { - $connect && $this->conn->connect(); - return $this->conn; + $conn= DriverManager::getConnection($this->dsn); + $connect && $conn->connect(); + return $conn; } /** diff --git a/src/test/php/rdbms/unittest/integration/SybaseIntegrationTest.class.php b/src/test/php/rdbms/unittest/integration/SybaseIntegrationTest.class.php index 16e32fc3..8f8ef5e3 100755 --- a/src/test/php/rdbms/unittest/integration/SybaseIntegrationTest.class.php +++ b/src/test/php/rdbms/unittest/integration/SybaseIntegrationTest.class.php @@ -1,8 +1,7 @@ getMethod($this->name); - if ($m->hasAnnotation('version')) { - $server= $this->db()->query('select @@version_number as v')->next('v'); - if ($server < ($required= $m->getAnnotation('version'))) { - throw new PrerequisitesNotMetError('Server version not sufficient: '.$server, null, [$required]); - } - } - } - /** @return string */ protected function tableName() { return '#unittest'; } @@ -123,37 +107,55 @@ public function selectNullUniVarChar() { Assert::equals(null, $this->db()->query('select cast(NULL as univarchar(255)) as value')->next('value')); } - #[Test, Version(15000)] + private function runOn($version, $callable) { + $conn= $this->db(); + $server= $conn->query('select @@version_number as v')->next('v'); + $server >= $version && $callable($conn); + } + + #[Test] public function selectEmptyUniText() { - Assert::equals(' ', $this->db()->query('select cast("" as unitext) as value')->next('value')); + $this->runOn(15000, function($conn) { + Assert::equals(' ', $conn->query('select cast("" as unitext) as value')->next('value')); + }); } - #[Test, Version(15000)] + #[Test] public function selectUniText() { - Assert::equals('test', $this->db()->query('select cast("test" as unitext) as value')->next('value')); + $this->runOn(15000, function($conn) { + Assert::equals('test', $this->db()->query('select cast("test" as unitext) as value')->next('value')); + }); } - #[Test, Version(15000)] + #[Test] public function selectUmlautUniText() { - Assert::equals( - new Bytes("\303\234bercoder"), - new Bytes($this->db()->query('select cast("Übercoder" as unitext) as value')->next('value')) - ); + $this->runOn(15000, function($conn) { + Assert::equals( + new Bytes("\303\234bercoder"), + new Bytes($this->db()->query('select cast("Übercoder" as unitext) as value')->next('value')) + ); + }); } - #[Test, Version(15000)] + #[Test] public function selectNullUniText() { - Assert::equals(null, $this->db()->query('select cast(NULL as unitext) as value')->next('value')); + $this->runOn(15000, function($conn) { + Assert::equals(null, $this->db()->query('select cast(NULL as unitext) as value')->next('value')); + }); } - #[Test, Version(15000)] + #[Test] public function selectUnsignedInt() { - parent::selectUnsignedInt(); + $this->runOn(15000, function($conn) { + parent::selectUnsignedInt(); + }); } - #[Test, Version(15000)] + #[Test] public function selectMaxUnsignedBigInt() { - parent::selectMaxUnsignedBigInt(); + $this->runOn(15000, function($conn) { + parent::selectMaxUnsignedBigInt(); + }); } #[Test, Expect(['class' => SQLStatementFailedException::class, 'withMessage' => '/More power/'])]