Skip to content

Commit ab353a3

Browse files
jnahmiasfguillot
authored andcommitted
tests: configure unit tests to run on MSSQL [odbc/dblib]
1 parent 33852e9 commit ab353a3

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

tests/units.mssql.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<phpunit stopOnError="false" stopOnFailure="false" colors="true">
2+
<testsuites>
3+
<testsuite name="Kanboard">
4+
<directory>units</directory>
5+
</testsuite>
6+
</testsuites>
7+
</phpunit>

tests/units/Base.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@ protected function setUp(): void
3636
$pdo->exec('DROP DATABASE '.DB_NAME);
3737
$pdo->exec('CREATE DATABASE '.DB_NAME.' WITH OWNER '.DB_USERNAME);
3838
$pdo = null;
39+
} elseif (DB_DRIVER === 'dblib') {
40+
$dsn = 'dblib:host='.DB_HOSTNAME;
41+
if (! empty(DB_PORT) ) { $dsn .= ','.DB_PORT; }
42+
$dsn .= ";dbname=master;appname=Kanboard Unit Tests [$test]";
43+
$pdo = new PDO($dsn, DB_USERNAME, DB_PASSWORD);
44+
$pdo->exec('use master;');
45+
$pdo->exec('DROP DATABASE IF EXISTS ['.DB_NAME.'];');
46+
$pdo->exec('CREATE DATABASE ['.DB_NAME.'];');
47+
$pdo->exec('ALTER DATABASE ['.DB_NAME.'] SET ALLOW_SNAPSHOT_ISOLATION ON;');
48+
$pdo->exec('ALTER DATABASE ['.DB_NAME.'] SET READ_COMMITTED_SNAPSHOT ON;');
49+
$pdo->exec('ALTER DATABASE ['.DB_NAME.'] SET ANSI_NULL_DEFAULT ON;');
50+
$pdo->exec('USE ['.DB_NAME.'];');
51+
$pdo = null;
52+
} elseif (DB_DRIVER === 'odbc') {
53+
$pdo = new PDO('odbc:'.DB_ODBC_DSN, DB_USERNAME, DB_PASSWORD);
54+
$pdo->exec('use master;');
55+
$pdo->exec('DROP DATABASE IF EXISTS ['.DB_NAME.'];');
56+
$pdo->exec('CREATE DATABASE ['.DB_NAME.'];');
57+
$pdo->exec('ALTER DATABASE ['.DB_NAME.'] SET ALLOW_SNAPSHOT_ISOLATION ON;');
58+
$pdo->exec('ALTER DATABASE ['.DB_NAME.'] SET READ_COMMITTED_SNAPSHOT ON;');
59+
$pdo->exec('ALTER DATABASE ['.DB_NAME.'] SET ANSI_NULL_DEFAULT ON;');
60+
$pdo->exec('USE ['.DB_NAME.'];');
61+
$pdo = null;
3962
}
4063

4164
$this->container = new Pimple\Container;

0 commit comments

Comments
 (0)