Skip to content

Commit

Permalink
Fix handling of cases only to be run on Sybase 15+
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Nov 19, 2023
1 parent 4276199 commit 7cd4531
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

/**
Expand All @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php namespace rdbms\unittest\integration;

use rdbms\SQLStatementFailedException;
use unittest\Assert;
use unittest\{BeforeClass, Expect, PrerequisitesNotMetError, Test, Version};
use unittest\{Assert, Before, Expect, PrerequisitesNotMetError, Test};
use util\{Bytes, Date};

/**
Expand All @@ -22,28 +21,13 @@ class SybaseIntegrationTest extends RdbmsIntegrationTest {
*
* @return void
*/
#[BeforeClass]
#[Before]
public static function setMinimumServerSeverity() {
if (function_exists('sybase_min_server_severity')) {
sybase_min_server_severity(12);
}
}

/**
* Skip tests which require a specific minimum server version
*/
#[Before]
public function setUp() {
parent::setUp();
$m= typeof($this)->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'; }

Expand Down Expand Up @@ -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/'])]
Expand Down

0 comments on commit 7cd4531

Please sign in to comment.