Skip to content

Commit a8a7742

Browse files
refactor: Consolidate database connection enums into unified configuration. (#72)
1 parent 08ca012 commit a8a7742

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+463
-263
lines changed

.github/workflows/build-mssql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
{
3030
"ACCEPT_EULA": "Y",
3131
"SA_PASSWORD": "YourStrong!Passw0rd",
32-
"MSSQL_PID": "Developer"
32+
"MSSQL_PID": "Developer",
3333
}
3434
database-health-cmd: "/opt/mssql-tools18/bin/sqlcmd -C -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'SELECT 1'"
3535
database-health-retries: 5

.github/workflows/build-oracle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
database-env: |
2929
{
3030
"ORACLE_DATABASE": "yiitest",
31-
"ORACLE_PASSWORD": "root"
31+
"ORACLE_PASSWORD": "root",
3232
}
3333
database-health-cmd: "healthcheck.sh"
3434
database-health-retries: 10

.github/workflows/build-pgsql.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
{
3030
"POSTGRES_DB": "yiitest",
3131
"POSTGRES_USER": "root",
32-
"POSTGRES_PASSWORD": "root"
32+
"POSTGRES_PASSWORD": "root",
3333
}
3434
database-health-cmd: "pg_isready -U postgres"
3535
database-health-retries: 3

ecs.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
'constant_public',
2727
'constant_protected',
2828
'constant_private',
29+
'case',
2930
'property_public',
3031
'property_protected',
3132
'property_private',

tests/TestCase.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
class TestCase extends \PHPUnit\Framework\TestCase
4141
{
4242
use SchemaBuilderTrait;
43-
protected string $driverName = 'sqlite';
4443

45-
protected string|null $dsn = null;
44+
/**
45+
* @phpstan-var string[]
46+
*/
47+
protected array $connection = [];
4648
protected string $fixtureDirectory = __DIR__ . '/support/data/';
47-
protected string $password = '';
48-
protected string $username = '';
4949

5050
protected function setUp(): void
5151
{
@@ -341,12 +341,7 @@ protected function mockConsoleApplication(): void
341341
'id' => 'testapp',
342342
'basePath' => dirname(__DIR__),
343343
'components' => [
344-
'db' => [
345-
'class' => Connection::class,
346-
'dsn' => $this->dsn !== null ? $this->dsn : 'sqlite::memory:',
347-
'password' => $this->password,
348-
'username' => $this->username,
349-
],
344+
'db' => $this->connection,
350345
],
351346
],
352347
);
@@ -361,7 +356,7 @@ protected function mockConsoleApplication(): void
361356
*/
362357
protected function replaceQuotes(string $sql): string
363358
{
364-
return match ($this->driverName) {
359+
return match ($this->getDb()->driverName) {
365360
'mysql', 'sqlite' => str_replace(
366361
['[[', ']]'],
367362
'`',

tests/mssql/CacheManagementTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use PHPUnit\Framework\Attributes\Group;
88
use yii2\extensions\nestedsets\tests\base\AbstractCacheManagement;
9-
use yii2\extensions\nestedsets\tests\support\MSSQLConnection;
9+
use yii2\extensions\nestedsets\tests\support\DatabaseConnection;
1010

1111
/**
1212
* Test suite for cache invalidation in nested sets tree behaviors using SQL Server.
@@ -34,10 +34,7 @@ final class CacheManagementTest extends AbstractCacheManagement
3434
{
3535
protected function setUp(): void
3636
{
37-
$this->driverName = MSSQLConnection::DRIVER_NAME->value;
38-
$this->dsn = MSSQLConnection::DSN->value;
39-
$this->password = MSSQLConnection::PASSWORD->value;
40-
$this->username = MSSQLConnection::USERNAME->value;
37+
$this->connection = DatabaseConnection::MSSQL->connection();
4138

4239
parent::setUp();
4340
}

tests/mssql/ExceptionHandlingTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use PHPUnit\Framework\Attributes\Group;
88
use yii2\extensions\nestedsets\tests\base\AbstractExceptionHandling;
9-
use yii2\extensions\nestedsets\tests\support\MSSQLConnection;
9+
use yii2\extensions\nestedsets\tests\support\DatabaseConnection;
1010

1111
/**
1212
* Test suite for exception handling in nested sets tree behaviors using SQL Server.
@@ -34,10 +34,7 @@ final class ExceptionHandlingTest extends AbstractExceptionHandling
3434
{
3535
protected function setUp(): void
3636
{
37-
$this->driverName = MSSQLConnection::DRIVER_NAME->value;
38-
$this->dsn = MSSQLConnection::DSN->value;
39-
$this->password = MSSQLConnection::PASSWORD->value;
40-
$this->username = MSSQLConnection::USERNAME->value;
37+
$this->connection = DatabaseConnection::MSSQL->connection();
4138

4239
parent::setUp();
4340
}

tests/mssql/ExtensibilityTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use PHPUnit\Framework\Attributes\Group;
88
use yii2\extensions\nestedsets\tests\base\AbstractExtensibility;
9-
use yii2\extensions\nestedsets\tests\support\MSSQLConnection;
9+
use yii2\extensions\nestedsets\tests\support\DatabaseConnection;
1010

1111
/**
1212
* Test suite for extensibility in nested sets tree behaviors using SQL Server.
@@ -34,10 +34,7 @@ final class ExtensibilityTest extends AbstractExtensibility
3434
{
3535
protected function setUp(): void
3636
{
37-
$this->driverName = MSSQLConnection::DRIVER_NAME->value;
38-
$this->dsn = MSSQLConnection::DSN->value;
39-
$this->password = MSSQLConnection::PASSWORD->value;
40-
$this->username = MSSQLConnection::USERNAME->value;
37+
$this->connection = DatabaseConnection::MSSQL->connection();
4138

4239
parent::setUp();
4340
}

tests/mssql/NodeAppendTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use PHPUnit\Framework\Attributes\Group;
88
use yii2\extensions\nestedsets\tests\base\AbstractNodeAppend;
9-
use yii2\extensions\nestedsets\tests\support\MSSQLConnection;
9+
use yii2\extensions\nestedsets\tests\support\DatabaseConnection;
1010

1111
/**
1212
* Test suite for node append and root promotion in nested sets tree behaviors using SQL Server.
@@ -37,10 +37,7 @@ final class NodeAppendTest extends AbstractNodeAppend
3737
{
3838
protected function setUp(): void
3939
{
40-
$this->driverName = MSSQLConnection::DRIVER_NAME->value;
41-
$this->dsn = MSSQLConnection::DSN->value;
42-
$this->password = MSSQLConnection::PASSWORD->value;
43-
$this->username = MSSQLConnection::USERNAME->value;
40+
$this->connection = DatabaseConnection::MSSQL->connection();
4441

4542
parent::setUp();
4643
}

tests/mssql/NodeDeleteTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use PHPUnit\Framework\Attributes\Group;
88
use yii2\extensions\nestedsets\tests\base\AbstractNodeDelete;
9-
use yii2\extensions\nestedsets\tests\support\MSSQLConnection;
9+
use yii2\extensions\nestedsets\tests\support\DatabaseConnection;
1010

1111
/**
1212
* Test suite for node deletion in nested sets tree behaviors using SQL Server.
@@ -38,10 +38,7 @@ final class NodeDeleteTest extends AbstractNodeDelete
3838
{
3939
protected function setUp(): void
4040
{
41-
$this->driverName = MSSQLConnection::DRIVER_NAME->value;
42-
$this->dsn = MSSQLConnection::DSN->value;
43-
$this->password = MSSQLConnection::PASSWORD->value;
44-
$this->username = MSSQLConnection::USERNAME->value;
41+
$this->connection = DatabaseConnection::MSSQL->connection();
4542

4643
parent::setUp();
4744
}

0 commit comments

Comments
 (0)