Skip to content

Commit 58fc094

Browse files
committed
feat: Refactor SQLServer test suites to utilize centralized MSSQLConnection configuration for improved maintainability and consistency.
1 parent ff9229e commit 58fc094

12 files changed

+142
-198
lines changed

tests/mssql/CacheManagementTest.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +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;
910

1011
/**
1112
* Test suite for cache invalidation in nested sets tree behaviors using SQL Server.
@@ -31,23 +32,13 @@
3132
#[Group('mssql')]
3233
final class CacheManagementTest extends AbstractCacheManagement
3334
{
34-
/**
35-
* Database driver name for SQL Server.
36-
*/
37-
protected string $driverName = 'sqlsrv';
35+
protected function setUp(): void
36+
{
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;
3841

39-
/**
40-
* Data Source Name (DSN) for SQL Server connection.
41-
*/
42-
protected string|null $dsn = 'sqlsrv:Server=127.0.0.1,1433;Database=yiitest;Encrypt=no';
43-
44-
/**
45-
* Password for SQL Server connection.
46-
*/
47-
protected string $password = 'YourStrong!Passw0rd';
48-
49-
/**
50-
* Username for SQL Server connection.
51-
*/
52-
protected string $username = 'SA';
42+
parent::setUp();
43+
}
5344
}

tests/mssql/ExceptionHandlingTest.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +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;
910

1011
/**
1112
* Test suite for exception handling in nested sets tree behaviors using SQL Server.
@@ -31,23 +32,13 @@
3132
#[Group('mssql')]
3233
final class ExceptionHandlingTest extends AbstractExceptionHandling
3334
{
34-
/**
35-
* Database driver name for SQL Server.
36-
*/
37-
protected string $driverName = 'sqlsrv';
35+
protected function setUp(): void
36+
{
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;
3841

39-
/**
40-
* Data Source Name (DSN) for SQL Server connection.
41-
*/
42-
protected string|null $dsn = 'sqlsrv:Server=127.0.0.1,1433;Database=yiitest;Encrypt=no';
43-
44-
/**
45-
* Password for SQL Server connection.
46-
*/
47-
protected string $password = 'YourStrong!Passw0rd';
48-
49-
/**
50-
* Username for SQL Server connection.
51-
*/
52-
protected string $username = 'SA';
42+
parent::setUp();
43+
}
5344
}

tests/mssql/ExtensibilityTest.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +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;
910

1011
/**
1112
* Test suite for extensibility in nested sets tree behaviors using SQL Server.
@@ -31,23 +32,13 @@
3132
#[Group('mssql')]
3233
final class ExtensibilityTest extends AbstractExtensibility
3334
{
34-
/**
35-
* Database driver name for SQL Server.
36-
*/
37-
protected string $driverName = 'sqlsrv';
35+
protected function setUp(): void
36+
{
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;
3841

39-
/**
40-
* Data Source Name (DSN) for SQL Server connection.
41-
*/
42-
protected string|null $dsn = 'sqlsrv:Server=127.0.0.1,1433;Database=yiitest;Encrypt=no';
43-
44-
/**
45-
* Password for SQL Server connection.
46-
*/
47-
protected string $password = 'YourStrong!Passw0rd';
48-
49-
/**
50-
* Username for SQL Server connection.
51-
*/
52-
protected string $username = 'SA';
42+
parent::setUp();
43+
}
5344
}

tests/mssql/NodeAppendTest.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +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;
910

1011
/**
1112
* Test suite for node append and root promotion in nested sets tree behaviors using SQL Server.
@@ -34,23 +35,13 @@
3435
#[Group('mssql')]
3536
final class NodeAppendTest extends AbstractNodeAppend
3637
{
37-
/**
38-
* Database driver name for SQL Server.
39-
*/
40-
protected string $driverName = 'sqlsrv';
38+
protected function setUp(): void
39+
{
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;
4144

42-
/**
43-
* Data Source Name (DSN) for SQL Server connection.
44-
*/
45-
protected string|null $dsn = 'sqlsrv:Server=127.0.0.1,1433;Database=yiitest;Encrypt=no';
46-
47-
/**
48-
* Password for SQL Server connection.
49-
*/
50-
protected string $password = 'YourStrong!Passw0rd';
51-
52-
/**
53-
* Username for SQL Server connection.
54-
*/
55-
protected string $username = 'SA';
45+
parent::setUp();
46+
}
5647
}

tests/mssql/NodeDeleteTest.php

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +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;
910

1011
/**
1112
* Test suite for node deletion in nested sets tree behaviors using SQL Server.
@@ -35,23 +36,13 @@
3536
#[Group('mssql')]
3637
final class NodeDeleteTest extends AbstractNodeDelete
3738
{
38-
/**
39-
* Database driver name for SQL Server.
40-
*/
41-
protected string $driverName = 'sqlsrv';
39+
protected function setUp(): void
40+
{
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;
4245

43-
/**
44-
* Data Source Name (DSN) for SQL Server connection.
45-
*/
46-
protected string|null $dsn = 'sqlsrv:Server=127.0.0.1,1433;Database=yiitest;Encrypt=no';
47-
48-
/**
49-
* Password for SQL Server connection.
50-
*/
51-
protected string $password = 'YourStrong!Passw0rd';
52-
53-
/**
54-
* Username for SQL Server connection.
55-
*/
56-
protected string $username = 'SA';
46+
parent::setUp();
47+
}
5748
}

tests/mssql/NodeInsertTest.php

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

77
use PHPUnit\Framework\Attributes\Group;
88
use yii2\extensions\nestedsets\tests\base\AbstractNodeInsert;
9+
use yii2\extensions\nestedsets\tests\support\MSSQLConnection;
910

1011
/**
1112
* Test suite for node insertion in nested sets tree behaviors using SQL Server.
@@ -33,23 +34,13 @@
3334
#[Group('mssql')]
3435
final class NodeInsertTest extends AbstractNodeInsert
3536
{
36-
/**
37-
* Database driver name for SQL Server.
38-
*/
39-
protected string $driverName = 'sqlsrv';
37+
protected function setUp(): void
38+
{
39+
$this->driverName = MSSQLConnection::DRIVER_NAME->value;
40+
$this->dsn = MSSQLConnection::DSN->value;
41+
$this->password = MSSQLConnection::PASSWORD->value;
42+
$this->username = MSSQLConnection::USERNAME->value;
4043

41-
/**
42-
* Data Source Name (DSN) for SQL Server connection.
43-
*/
44-
protected string|null $dsn = 'sqlsrv:Server=127.0.0.1,1433;Database=yiitest;Encrypt=no';
45-
46-
/**
47-
* Password for SQL Server connection.
48-
*/
49-
protected string $password = 'YourStrong!Passw0rd';
50-
51-
/**
52-
* Username for SQL Server connection.
53-
*/
54-
protected string $username = 'SA';
44+
parent::setUp();
45+
}
5546
}

tests/mssql/NodePrependTest.php

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

77
use PHPUnit\Framework\Attributes\Group;
88
use yii2\extensions\nestedsets\tests\base\AbstractNodePrepend;
9+
use yii2\extensions\nestedsets\tests\support\MSSQLConnection;
910

1011
/**
1112
* Test suite for node prepend operations in nested sets tree behaviors using SQL Server.
@@ -32,23 +33,13 @@
3233
#[Group('mssql')]
3334
final class NodePrependTest extends AbstractNodePrepend
3435
{
35-
/**
36-
* Database driver name for SQL Server.
37-
*/
38-
protected string $driverName = 'sqlsrv';
36+
protected function setUp(): void
37+
{
38+
$this->driverName = MSSQLConnection::DRIVER_NAME->value;
39+
$this->dsn = MSSQLConnection::DSN->value;
40+
$this->password = MSSQLConnection::PASSWORD->value;
41+
$this->username = MSSQLConnection::USERNAME->value;
3942

40-
/**
41-
* Data Source Name (DSN) for SQL Server connection.
42-
*/
43-
protected string|null $dsn = 'sqlsrv:Server=127.0.0.1,1433;Database=yiitest;Encrypt=no';
44-
45-
/**
46-
* Password for SQL Server connection.
47-
*/
48-
protected string $password = 'YourStrong!Passw0rd';
49-
50-
/**
51-
* Username for SQL Server connection.
52-
*/
53-
protected string $username = 'SA';
43+
parent::setUp();
44+
}
5445
}

tests/mssql/NodeStateTest.php

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

77
use PHPUnit\Framework\Attributes\Group;
88
use yii2\extensions\nestedsets\tests\base\AbstractNodeState;
9+
use yii2\extensions\nestedsets\tests\support\MSSQLConnection;
910

1011
/**
1112
* Test suite for node state and relationship in nested sets tree behaviors using SQL Server.
@@ -31,23 +32,13 @@
3132
#[Group('mssql')]
3233
final class NodeStateTest extends AbstractNodeState
3334
{
34-
/**
35-
* Database driver name for SQL Server.
36-
*/
37-
protected string $driverName = 'sqlsrv';
35+
protected function setUp(): void
36+
{
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;
3841

39-
/**
40-
* Data Source Name (DSN) for SQL Server connection.
41-
*/
42-
protected string|null $dsn = 'sqlsrv:Server=127.0.0.1,1433;Database=yiitest;Encrypt=no';
43-
44-
/**
45-
* Password for SQL Server connection.
46-
*/
47-
protected string $password = 'YourStrong!Passw0rd';
48-
49-
/**
50-
* Username for SQL Server connection.
51-
*/
52-
protected string $username = 'SA';
42+
parent::setUp();
43+
}
5344
}

tests/mssql/QueryBehaviorTest.php

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

77
use PHPUnit\Framework\Attributes\Group;
88
use yii2\extensions\nestedsets\tests\base\AbstractQueryBehavior;
9+
use yii2\extensions\nestedsets\tests\support\MSSQLConnection;
910

1011
/**
1112
* Test suite for query behavior in nested sets tree behaviors using SQL Server.
@@ -33,23 +34,13 @@
3334
#[Group('mssql')]
3435
final class QueryBehaviorTest extends AbstractQueryBehavior
3536
{
36-
/**
37-
* Database driver name for SQL Server.
38-
*/
39-
protected string $driverName = 'sqlsrv';
37+
protected function setUp(): void
38+
{
39+
$this->driverName = MSSQLConnection::DRIVER_NAME->value;
40+
$this->dsn = MSSQLConnection::DSN->value;
41+
$this->password = MSSQLConnection::PASSWORD->value;
42+
$this->username = MSSQLConnection::USERNAME->value;
4043

41-
/**
42-
* Data Source Name (DSN) for SQL Server connection.
43-
*/
44-
protected string|null $dsn = 'sqlsrv:Server=127.0.0.1,1433;Database=yiitest;Encrypt=no';
45-
46-
/**
47-
* Password for SQL Server connection.
48-
*/
49-
protected string $password = 'YourStrong!Passw0rd';
50-
51-
/**
52-
* Username for SQL Server connection.
53-
*/
54-
protected string $username = 'SA';
44+
parent::setUp();
45+
}
5546
}

tests/mssql/TreeTraversalTest.php

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

77
use PHPUnit\Framework\Attributes\Group;
88
use yii2\extensions\nestedsets\tests\base\AbstractTreeTraversal;
9+
use yii2\extensions\nestedsets\tests\support\MSSQLConnection;
910

1011
/**
1112
* Test suite for tree traversal and relationship methods in nested sets tree behaviors using SQL Server.
@@ -31,23 +32,13 @@
3132
#[Group('mssql')]
3233
final class TreeTraversalTest extends AbstractTreeTraversal
3334
{
34-
/**
35-
* Database driver name for SQL Server.
36-
*/
37-
protected string $driverName = 'sqlsrv';
35+
protected function setUp(): void
36+
{
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;
3841

39-
/**
40-
* Data Source Name (DSN) for SQL Server connection.
41-
*/
42-
protected string|null $dsn = 'sqlsrv:Server=127.0.0.1,1433;Database=yiitest;Encrypt=no';
43-
44-
/**
45-
* Password for SQL Server connection.
46-
*/
47-
protected string $password = 'YourStrong!Passw0rd';
48-
49-
/**
50-
* Username for SQL Server connection.
51-
*/
52-
protected string $username = 'SA';
42+
parent::setUp();
43+
}
5344
}

0 commit comments

Comments
 (0)