From fef456873db77ed2f97dcffa2aea0e003b705ad9 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Wed, 19 Nov 2025 15:40:28 +0300 Subject: [PATCH 1/7] Refactor tests --- composer.json | 3 +- ...derTest.php => InConditionBuilderTest.php} | 13 +- tests/ColumnBuilderTest.php | 7 +- tests/ColumnFactoryTest.php | 7 +- tests/ColumnTest.php | 10 +- tests/CommandTest.php | 65 ++++++---- tests/ConnectionTest.php | 27 +++-- tests/PdoCommandTest.php | 6 +- tests/PdoConnectionTest.php | 14 +-- tests/Provider/CommandProvider.php | 5 - tests/Provider/QueryBuilderProvider.php | 32 +++-- tests/QueryBuilderTest.php | 111 ++++++++++-------- tests/QueryGetTableAliasTest.php | 10 +- tests/QueryTest.php | 19 ++- tests/QuoterTest.php | 8 +- tests/SchemaTest.php | 23 ++-- tests/SqlParserTest.php | 8 +- tests/Support/IntegrationTestTrait.php | 29 +++++ tests/Support/TestConnection.php | 68 +++++++++++ tests/Support/TestTrait.php | 110 ----------------- tests/TableSchemaTest.php | 5 - tests/Type/BigIntTest.php | 75 +++--------- tests/Type/BinaryTest.php | 66 ++--------- tests/Type/BitTest.php | 78 +++--------- tests/Type/CharTest.php | 72 ++---------- tests/Type/DateTest.php | 68 ++--------- tests/Type/DecimalTest.php | 89 +++----------- tests/Type/FloatTest.php | 89 +++----------- tests/Type/GeometryTest.php | 56 ++------- tests/Type/ImageTest.php | 60 ++-------- tests/Type/IntTest.php | 40 ++++--- tests/Type/JsonTest.php | 82 +++---------- tests/Type/MoneyTest.php | 89 +++----------- tests/Type/NTextTest.php | 58 ++------- tests/Type/NumericTest.php | 78 +++--------- tests/Type/RealTest.php | 89 +++----------- tests/Type/RowversionTest.php | 22 ++-- tests/Type/SmallIntTest.php | 89 +++----------- tests/Type/SmallMoneyTest.php | 89 +++----------- tests/Type/TextTest.php | 62 +++------- tests/Type/TinyIntTest.php | 91 +++----------- tests/Type/UniqueidentifierTest.php | 79 +++---------- tests/Type/VarBinaryTest.php | 94 ++------------- tests/Type/VarCharTest.php | 75 +++--------- 44 files changed, 634 insertions(+), 1636 deletions(-) rename tests/Builder/{InconditionBuilderTest.php => InConditionBuilderTest.php} (75%) create mode 100644 tests/Support/IntegrationTestTrait.php create mode 100644 tests/Support/TestConnection.php delete mode 100644 tests/Support/TestTrait.php diff --git a/composer.json b/composer.json index a731c7554..2f5544ec7 100644 --- a/composer.json +++ b/composer.json @@ -45,7 +45,8 @@ "vimeo/psalm": "^5.26.1 || ^6.8.8", "vlucas/phpdotenv": "^5.6.1", "yiisoft/aliases": "^2.0", - "yiisoft/cache-file": "^3.2", + "yiisoft/psr-dummy-provider": "^1.0", + "yiisoft/test-support": "^3.0", "yiisoft/var-dumper": "^1.7" }, "provide": { diff --git a/tests/Builder/InconditionBuilderTest.php b/tests/Builder/InConditionBuilderTest.php similarity index 75% rename from tests/Builder/InconditionBuilderTest.php rename to tests/Builder/InConditionBuilderTest.php index 38ed40013..b1c765783 100644 --- a/tests/Builder/InconditionBuilderTest.php +++ b/tests/Builder/InConditionBuilderTest.php @@ -4,25 +4,24 @@ namespace Yiisoft\Db\Mssql\Tests\Builder; -use PHPUnit\Framework\TestCase; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Mssql\Builder\InBuilder; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Query\Query; use Yiisoft\Db\QueryBuilder\Condition\In; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql - * - * @psalm-suppress PropertyNotSetInConstructor */ -final class InconditionBuilderTest extends TestCase +final class InConditionBuilderTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; public function testBuildSubqueryInCondition(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); + $inCondition = new In( ['id'], (new Query($db))->select('id')->from('users')->where(['active' => 1]), diff --git a/tests/ColumnBuilderTest.php b/tests/ColumnBuilderTest.php index 85ba62dd5..02fcf419d 100644 --- a/tests/ColumnBuilderTest.php +++ b/tests/ColumnBuilderTest.php @@ -6,16 +6,13 @@ use PHPUnit\Framework\Attributes\DataProviderExternal; use Yiisoft\Db\Mssql\Tests\Provider\ColumnBuilderProvider; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; -use Yiisoft\Db\Tests\AbstractColumnBuilderTest; +use Yiisoft\Db\Tests\Common\CommonColumnBuilderTest; /** * @group mssql */ -class ColumnBuilderTest extends AbstractColumnBuilderTest +class ColumnBuilderTest extends CommonColumnBuilderTest { - use TestTrait; - #[DataProviderExternal(ColumnBuilderProvider::class, 'buildingMethods')] public function testBuildingMethods( string $buildingMethod, diff --git a/tests/ColumnFactoryTest.php b/tests/ColumnFactoryTest.php index 552ec33f8..2930f3cf8 100644 --- a/tests/ColumnFactoryTest.php +++ b/tests/ColumnFactoryTest.php @@ -7,17 +7,14 @@ use PHPUnit\Framework\Attributes\DataProviderExternal; use Yiisoft\Db\Mssql\Column\ColumnFactory; use Yiisoft\Db\Mssql\Tests\Provider\ColumnFactoryProvider; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; use Yiisoft\Db\Schema\Column\ColumnInterface; -use Yiisoft\Db\Tests\AbstractColumnFactoryTest; +use Yiisoft\Db\Tests\Common\CommonColumnFactoryTest; /** * @group mssql */ -final class ColumnFactoryTest extends AbstractColumnFactoryTest +final class ColumnFactoryTest extends CommonColumnFactoryTest { - use TestTrait; - #[DataProviderExternal(ColumnFactoryProvider::class, 'dbTypes')] public function testFromDbType(string $dbType, string $expectedType, string $expectedInstanceOf): void { diff --git a/tests/ColumnTest.php b/tests/ColumnTest.php index da7e8f8ba..5e5aa83c8 100644 --- a/tests/ColumnTest.php +++ b/tests/ColumnTest.php @@ -13,7 +13,7 @@ use Yiisoft\Db\Expression\Value\Param; use Yiisoft\Db\Mssql\Column\BinaryColumn; use Yiisoft\Db\Mssql\Tests\Provider\ColumnProvider; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Schema\Column\BooleanColumn; use Yiisoft\Db\Schema\Column\ColumnInterface; use Yiisoft\Db\Schema\Column\DoubleColumn; @@ -30,11 +30,11 @@ */ final class ColumnTest extends CommonColumnTest { - use TestTrait; + use IntegrationTestTrait; public function testSelectWithPhpTypecasting(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $sql = "SELECT null AS [null], 1 AS [1], 2.5 AS [2.5], 'string' AS [string]"; @@ -80,7 +80,9 @@ public function testSelectWithPhpTypecasting(): void public function testColumnInstance() { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); + $schema = $db->getSchema(); $tableSchema = $schema->getTableSchema('type'); diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 51302715d..750a588d3 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\Mssql\Tests; +use Closure; use PHPUnit\Framework\Attributes\DataProviderExternal; use Yiisoft\Db\Constraint\Index; use Yiisoft\Db\Exception\IntegrityException; @@ -13,7 +14,8 @@ use Yiisoft\Db\Mssql\Column\ColumnBuilder; use Yiisoft\Db\Mssql\IndexType; use Yiisoft\Db\Mssql\Tests\Provider\CommandProvider; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Mssql\Tests\Support\TestConnection; use Yiisoft\Db\Query\Query; use Yiisoft\Db\Tests\Common\CommonCommandTest; @@ -25,13 +27,12 @@ */ final class CommandTest extends CommonCommandTest { - use TestTrait; - - protected string $upsertTestCharCast = 'CAST([[address]] AS VARCHAR(255))'; + use IntegrationTestTrait; public function testAlterColumn(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $command = $db->createCommand(); $command->alterColumn('{{customer}}', 'email', 'ntext')->execute(); @@ -44,7 +45,7 @@ public function testAlterColumn(): void public function testCheckIntegrity(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); $command->checkIntegrity('{{dbo}}', '{{customer}}'); @@ -60,7 +61,8 @@ public function testCheckIntegrity(): void public function testCheckIntegrityExecuteException(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $command = $db->createCommand(); $command->checkIntegrity('{{dbo}}', '{{T_constraints_3}}', false)->execute(); @@ -84,7 +86,8 @@ public function testGetRawSql(string $sql, array $params, string $expectedRawSql #[DataProviderExternal(CommandProvider::class, 'dataInsertVarbinary')] public function testInsertVarbinary(mixed $expectedData, mixed $testData): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $command = $db->createCommand(); @@ -99,7 +102,8 @@ public function testInsertVarbinary(mixed $expectedData, mixed $testData): void public function testInsertReturningPksWithComputedColumn(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $command = $db->createCommand(); $command->setSql( @@ -132,7 +136,8 @@ public function testInsertReturningPksWithComputedColumn(): void public function testInsertReturningPksWithRowVersionColumn(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $command = $db->createCommand(); $command->setSql( @@ -148,7 +153,8 @@ public function testInsertReturningPksWithRowVersionColumn(): void public function testInsertReturningPksWithRowVersionNullColumn(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $command = $db->createCommand(); $command->setSql( @@ -167,7 +173,8 @@ public function testInsertReturningPksWithRowVersionNullColumn(): void public function testResetSequence(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $command = $db->createCommand(); $oldRow = $command->insertReturningPks('{{item}}', ['name' => 'insert_value_for_sequence', 'category_id' => 1]); @@ -183,7 +190,7 @@ public function testUpdate( string $table, array $columns, array|ExpressionInterface|string $conditions, - array|ExpressionInterface|string|null $from, + Closure|array|ExpressionInterface|string|null $from, array $params, array $expectedValues, int $expectedCount, @@ -198,14 +205,15 @@ public function testUpdate( } #[DataProviderExternal(CommandProvider::class, 'upsert')] - public function testUpsert(array $firstData, array $secondData): void + public function testUpsert(Closure|array $firstData, Closure|array $secondData): void { parent::testUpsert($firstData, $secondData); } public function testQueryScalarWithBlob(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $value = json_encode(['test'], JSON_THROW_ON_ERROR); $db->createCommand()->insert('{{%T_upsert_varbinary}}', ['id' => 1, 'blob_col' => $value])->execute(); @@ -216,7 +224,7 @@ public function testQueryScalarWithBlob(): void public function testAddDefaultValueSql(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); @@ -230,7 +238,7 @@ public function testAddDefaultValueSql(): void public function testDropDefaultValueSql(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); @@ -244,7 +252,7 @@ public function testDropDefaultValueSql(): void public function testDropTableCascade(): void { - $command = $this->getConnection()->createCommand(); + $command = $this->getSharedConnection()->createCommand(); $this->expectException(NotSupportedException::class); $this->expectExceptionMessage('MSSQL doesn\'t support cascade drop table.'); @@ -254,19 +262,21 @@ public function testDropTableCascade(): void public function testShowDatabases(): void { $expectedDatabases = []; - if (self::getDatabaseName() !== 'tempdb') { - $expectedDatabases[] = self::getDatabaseName(); + if (TestConnection::databaseName() !== 'tempdb') { + $expectedDatabases[] = TestConnection::databaseName(); } - $actualDatabases = self::getDb()->createCommand()->showDatabases(); + $actualDatabases = $this->getSharedConnection()->createCommand()->showDatabases(); $this->assertSame($expectedDatabases, $actualDatabases); } - /** @link https://github.com/yiisoft/db-migration/issues/11 */ + /** + * @link https://github.com/yiisoft/db-migration/issues/11 + */ public function testAlterColumnWithDefaultNull() { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); if ($db->getTableSchema('column_with_constraint', true) !== null) { @@ -295,7 +305,7 @@ public function testCreateIndex(array $columns, array $indexColumns, ?string $in public function testCreateClusteredColumnstoreIndex(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); $schema = $db->getSchema(); @@ -320,7 +330,7 @@ public function testCreateClusteredColumnstoreIndex(): void public function testCreateXmlIndex(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); $schema = $db->getSchema(); @@ -357,4 +367,9 @@ public function testBatchInsert( ): void { parent::testBatchInsert($table, $values, $columns, $expected, $expectedParams, $insertedRow); } + + protected function getUpsertTestCharCast(): string + { + return 'CAST([[address]] AS VARCHAR(255))'; + } } diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php index 17cc196df..2b1684a12 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -9,9 +9,10 @@ use Yiisoft\Db\Mssql\Column\ColumnBuilder; use Yiisoft\Db\Mssql\Column\ColumnFactory; use Yiisoft\Db\Mssql\Connection; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Mssql\Tests\Support\TestConnection; use Yiisoft\Db\Tests\Common\CommonConnectionTest; -use Yiisoft\Db\Tests\Support\DbHelper; +use Yiisoft\Db\Tests\Support\TestHelper; use Yiisoft\Db\Transaction\TransactionInterface; /** @@ -19,11 +20,11 @@ */ final class ConnectionTest extends CommonConnectionTest { - use TestTrait; + use IntegrationTestTrait; public function testTransactionIsolation(): void { - $db = $this->getConnection(true); + $db = $this->createConnection(); $transaction = $db->beginTransaction(TransactionInterface::READ_UNCOMMITTED); $transaction->commit(); @@ -39,11 +40,13 @@ public function testTransactionIsolation(): void /* should not be any exception so far */ $this->assertTrue(true); + + $db->close(); } public function testTransactionShortcutCustom(): void { - $db = $this->getConnection(); + $db = $this->createConnection(); $result = $db->transaction( static function (PdoConnectionInterface $db): bool { @@ -62,18 +65,20 @@ static function (PdoConnectionInterface $db): bool { )->queryScalar(); $this->assertSame('1', $profilesCount, 'profile should be inserted in transaction shortcut'); + + $db->close(); } public function testSettingDefaultAttributes(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $this->assertSame(PDO::ERRMODE_EXCEPTION, $db->getActivePDO()?->getAttribute(PDO::ATTR_ERRMODE)); } public function getColumnBuilderClass(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $this->assertSame(ColumnBuilder::class, $db->getColumnBuilderClass()); @@ -82,7 +87,7 @@ public function getColumnBuilderClass(): void public function testGetColumnFactory(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $this->assertInstanceOf(ColumnFactory::class, $db->getColumnFactory()); @@ -93,7 +98,11 @@ public function testUserDefinedColumnFactory(): void { $columnFactory = new ColumnFactory(); - $db = new Connection($this->getDriver(), DbHelper::getSchemaCache(), $columnFactory); + $db = new Connection( + TestConnection::createDriver(), + TestHelper::createMemorySchemaCache(), + $columnFactory, + ); $this->assertSame($columnFactory, $db->getColumnFactory()); diff --git a/tests/PdoCommandTest.php b/tests/PdoCommandTest.php index 166619ef5..004182db8 100644 --- a/tests/PdoCommandTest.php +++ b/tests/PdoCommandTest.php @@ -4,17 +4,15 @@ namespace Yiisoft\Db\Mssql\Tests; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Common\CommonPdoCommandTest; /** * @group mssql - * - * @psalm-suppress PropertyNotSetInConstructor */ final class PdoCommandTest extends CommonPdoCommandTest { - use TestTrait; + use IntegrationTestTrait; /** * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\CommandPDOProvider::bindParam diff --git a/tests/PdoConnectionTest.php b/tests/PdoConnectionTest.php index 6802e9ae1..5f568f190 100644 --- a/tests/PdoConnectionTest.php +++ b/tests/PdoConnectionTest.php @@ -9,27 +9,19 @@ use Yiisoft\Db\Exception\InvalidCallException; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Expression\Expression; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Common\CommonPdoConnectionTest; /** * @group mssql - * - * @psalm-suppress PropertyNotSetInConstructor */ final class PdoConnectionTest extends CommonPdoConnectionTest { - use TestTrait; + use IntegrationTestTrait; - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidCallException - * @throws Throwable - */ public function testGetLastInsertID(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); // One sequence, two tables $tableName1 = 'seqtable1'; diff --git a/tests/Provider/CommandProvider.php b/tests/Provider/CommandProvider.php index e05192850..4ae61bcae 100644 --- a/tests/Provider/CommandProvider.php +++ b/tests/Provider/CommandProvider.php @@ -9,7 +9,6 @@ use Yiisoft\Db\Mssql\Column\ColumnBuilder; use Yiisoft\Db\Mssql\IndexMethod; use Yiisoft\Db\Mssql\IndexType; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; use function json_encode; use function preg_replace; @@ -18,10 +17,6 @@ final class CommandProvider extends \Yiisoft\Db\Tests\Provider\CommandProvider { - use TestTrait; - - protected static string $driverName = 'sqlsrv'; - public static function batchInsert(): array { $batchInsert = parent::batchInsert(); diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index ddb634cbd..9de04fc7e 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\Mssql\Tests\Provider; +use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Constant\DataType; use Yiisoft\Db\Constant\PseudoType; use Yiisoft\Db\Constant\ReferentialAction; @@ -13,7 +14,7 @@ use Yiisoft\Db\Expression\Function\ArrayMerge; use Yiisoft\Db\Expression\Value\Param; use Yiisoft\Db\Mssql\Column\ColumnBuilder; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\TestConnection; use Yiisoft\Db\Query\Query; use Yiisoft\Db\QueryBuilder\Condition\In; use Yiisoft\Db\Tests\Support\TraversableObject; @@ -26,10 +27,6 @@ final class QueryBuilderProvider extends \Yiisoft\Db\Tests\Provider\QueryBuilderProvider { - use TestTrait; - - protected static string $driverName = 'sqlsrv'; - /** * @var string ` ESCAPE 'char'` part of a LIKE condition SQL. */ @@ -397,7 +394,7 @@ public static function insertReturningPks(): array ], 'carry passed params (query)' => [ 'customer', - (new Query(self::getDb())) + static fn(ConnectionInterface $db) => $db ->select(['email', 'name', 'address', 'is_active', 'related_id']) ->from('customer') ->where( @@ -516,7 +513,7 @@ public static function upsert(): array ], 'query, values and expressions with update part' => [ - 1 => (new Query(self::getDb())) + 1 => static fn(ConnectionInterface $db) => $db ->select( [ 'email' => new Expression(':phEmail', [':phEmail' => 'dynamic@example.com']), @@ -530,7 +527,7 @@ public static function upsert(): array ], 'query, values and expressions without update part' => [ - 1 => (new Query(self::getDb())) + 1 => static fn(ConnectionInterface $db) => $db ->select( [ 'email' => new Expression(':phEmail', [':phEmail' => 'dynamic@example.com']), @@ -858,7 +855,7 @@ public static function prepareValue(): array public static function caseXBuilder(): array { - $data = parent::caseXBuilder(); + $data = iterator_to_array(parent::caseXBuilder()); unset($data['with case condition']); @@ -893,11 +890,9 @@ public static function multiOperandFunctionClasses(): array public static function multiOperandFunctionBuilder(): array { - $data = parent::multiOperandFunctionBuilder(); + $data = iterator_to_array(parent::multiOperandFunctionBuilder()); - $db = self::getDb(); - $serverVersion = $db->getServerInfo()->getVersion(); - $db->close(); + $serverVersion = TestConnection::getShared()->getServerInfo()->getVersion(); if (version_compare($serverVersion, '16', '<')) { $data['Greatest with 2 operands'][2] = '(SELECT MAX(value) FROM (SELECT 1 AS value UNION SELECT (1 + 2) AS value) AS t)'; @@ -936,7 +931,12 @@ public static function multiOperandFunctionBuilder(): array ], 'ArrayMerge with 4 operands' => [ ArrayMerge::class, - [[1, 2, 3], new ArrayValue([5, 6, 7]), $stringParam, self::getDb()->select(new ArrayValue([9, 10]))], + static fn(ConnectionInterface $db) => [ + [1, 2, 3], + new ArrayValue([5, 6, 7]), + $stringParam, + $db->select(new ArrayValue([9, 10])), + ], <<getServerInfo()->getVersion(); - $db->close(); + $serverVersion = TestConnection::getShared()->getServerInfo()->getVersion(); if (version_compare($serverVersion, '16', '<')) { $data[0][3] = 'MERGE [test_upsert_with_functions] WITH (HOLDLOCK)' diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 7d1cae2ba..410518b61 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\Mssql\Tests; +use Closure; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\Attributes\DataProviderExternal; use Yiisoft\Db\Constant\DataType; @@ -19,7 +20,7 @@ use Yiisoft\Db\Expression\Value\Param; use Yiisoft\Db\Mssql\Column\ColumnBuilder; use Yiisoft\Db\Mssql\Tests\Provider\QueryBuilderProvider; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Query\Query; use Yiisoft\Db\Query\QueryInterface; use Yiisoft\Db\Schema\Column\ColumnInterface; @@ -33,7 +34,7 @@ */ final class QueryBuilderTest extends CommonQueryBuilderTest { - use TestTrait; + use IntegrationTestTrait; public function getBuildColumnDefinitionProvider(): array { @@ -42,7 +43,7 @@ public function getBuildColumnDefinitionProvider(): array public function testAddCommentOnColumn(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); $sql = " @@ -59,7 +60,7 @@ public function testAddCommentOnColumn(): void public function testAddCommentOnColumnException(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); @@ -71,7 +72,7 @@ public function testAddCommentOnColumnException(): void public function testAddCommentOnTable(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); $sql = " @@ -88,7 +89,7 @@ public function testAddCommentOnTable(): void public function testAddCommentOnTableException(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); @@ -100,7 +101,7 @@ public function testAddCommentOnTableException(): void public function testAddDefaultValue(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); @@ -114,7 +115,7 @@ public function testAddDefaultValue(): void #[DataProviderExternal(QueryBuilderProvider::class, 'buildCondition')] public function testBuildCondition( - array|ExpressionInterface|string $condition, + Closure|array|ExpressionInterface|string $condition, ?string $expected, array $expectedParams, ): void { @@ -123,7 +124,7 @@ public function testBuildCondition( public function testBuildFrom(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); $query = (new Query($db))->from('admin_user'); @@ -157,7 +158,7 @@ public function testBuildLikeCondition( public function testBuildWithLimit(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); $query = (new Query($db))->limit(10); @@ -175,7 +176,7 @@ public function testBuildWithLimit(): void public function testBuildWithOffset(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); $query = (new Query($db))->offset(10); @@ -194,7 +195,7 @@ public function testBuildWithOffset(): void public function testBuildOrderByAndLimit(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); $query = (new Query($db)) @@ -220,7 +221,7 @@ public function testBuildOrderByAndLimit(): void public function testCheckIntegrity(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); @@ -234,7 +235,7 @@ public function testCheckIntegrity(): void public function testCreateTable(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); @@ -263,7 +264,8 @@ public function testCreateTable(): void public function testDropCommentFromColumn(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $qb = $db->getQueryBuilder(); @@ -281,7 +283,7 @@ public function testDropCommentFromColumn(): void public function testDropCommentFromColumnException(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); @@ -293,7 +295,7 @@ public function testDropCommentFromColumnException(): void public function testDropCommentFromTable(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); @@ -311,7 +313,7 @@ public function testDropCommentFromTable(): void public function testDropCommentFromTableException(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); @@ -323,7 +325,8 @@ public function testDropCommentFromTableException(): void public function testDropDefaultValue(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $qb = $db->getQueryBuilder(); @@ -337,7 +340,7 @@ public function testDropDefaultValue(): void public function testDropUnique(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); @@ -352,7 +355,7 @@ public function testDropUnique(): void #[DataProviderExternal(QueryBuilderProvider::class, 'insert')] public function testInsert( string $table, - array|QueryInterface $columns, + Closure|array|QueryInterface $columns, array $params, string $expectedSQL, array $expectedParams, @@ -374,7 +377,7 @@ public function testBatchInsert( #[DataProviderExternal(QueryBuilderProvider::class, 'insertReturningPks')] public function testInsertReturningPks( string $table, - array|QueryInterface $columns, + Closure|array|QueryInterface $columns, array $params, string $expectedSQL, array $expectedParams, @@ -384,7 +387,7 @@ public function testInsertReturningPks( public function testRenameColumn(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); @@ -398,7 +401,7 @@ public function testRenameColumn(): void public function testRenameTable(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); @@ -412,7 +415,8 @@ public function testRenameTable(): void public function testResetSequence(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $qb = $db->getQueryBuilder(); @@ -433,7 +437,7 @@ public function testResetSequence(): void public function testSelectExists(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); $sql = 'SELECT 1 FROM [customer] WHERE [id] = 1'; @@ -448,7 +452,7 @@ public function testUpdate( string $table, array $columns, array|ExpressionInterface|string $condition, - array|ExpressionInterface|string|null $from, + Closure|array|ExpressionInterface|string|null $from, array $params, string $expectedSql, array $expectedParams = [], @@ -465,7 +469,7 @@ public function testUpdate( #[DataProviderExternal(QueryBuilderProvider::class, 'upsert')] public function testUpsert( string $table, - array|QueryInterface $insertColumns, + Closure|array|QueryInterface $insertColumns, array|bool $updateColumns, string $expectedSql, array $expectedParams, @@ -475,7 +479,7 @@ public function testUpsert( public function testUpsertVarbinary(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); $testData = json_encode(['test' => 'string', 'test2' => 'integer'], JSON_THROW_ON_ERROR); @@ -502,7 +506,7 @@ public function testUpsertVarbinary(): void #[DataProviderExternal(QueryBuilderProvider::class, 'upsertReturning')] public function testUpsertReturning( string $table, - array|QueryInterface $insertColumns, + Closure|array|QueryInterface $insertColumns, array|bool $updateColumns, ?array $returnColumns, string $expectedSql, @@ -519,7 +523,8 @@ public function testAlterColumn(string|ColumnInterface $type, string $expected): public function testAlterColumnOnDb(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $sql = $db->getQueryBuilder()->alterColumn('foo1', 'bar', 'varchar(255)'); $db->createCommand($sql)->execute(); @@ -554,7 +559,8 @@ public function testAlterColumnOnDb(): void public function testAlterColumnWithCheckConstraintOnDb(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $sql = $db->getQueryBuilder()->alterColumn( 'foo1', @@ -573,7 +579,8 @@ public function testAlterColumnWithCheckConstraintOnDb(): void public function testAlterColumnWithCheckConstraintOnDbWithException(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $sql = $db->getQueryBuilder()->alterColumn( 'foo1', @@ -589,7 +596,8 @@ public function testAlterColumnWithCheckConstraintOnDbWithException(): void public function testAlterColumnWithUniqueConstraintOnDbWithException(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $sql = $db->getQueryBuilder()->alterColumn( 'foo1', @@ -607,7 +615,8 @@ public function testAlterColumnWithUniqueConstraintOnDbWithException(): void public function testDropColumn(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $qb = $db->getQueryBuilder(); @@ -664,7 +673,8 @@ public function testDropColumn(): void public function testDropColumnOnDb(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $sql = $db->getQueryBuilder()->alterColumn( 'foo1', @@ -685,7 +695,7 @@ public function testDropColumnOnDb(): void public function testAlterColumnWithNull(): void { - $qb = $this->getConnection()->getQueryBuilder(); + $qb = $this->getSharedConnection()->getQueryBuilder(); $expected = <<getConnection()->getQueryBuilder(); + $qb = $this->getSharedConnection()->getQueryBuilder(); $expected = <<getConnection()->getQueryBuilder(); + $qb = $this->getSharedConnection()->getQueryBuilder(); $this->expectException(NotSupportedException::class); $this->expectExceptionMessage('MSSQL doesn\'t support cascade drop table.'); @@ -843,7 +853,7 @@ public function testDropTable(string $expected, ?bool $ifExists, ?bool $cascade) #[DataProviderExternal(QueryBuilderProvider::class, 'caseXBuilder')] public function testCaseXBuilder( - CaseX $case, + Closure|CaseX $case, string $expectedSql, array $expectedParams, string|int $expectedResult, @@ -852,14 +862,19 @@ public function testCaseXBuilder( } #[DataProviderExternal(QueryBuilderProvider::class, 'delete')] - public function testDelete(string $table, array|string $condition, string $expectedSQL, array $expectedParams): void + public function testDelete( + string $table, + array|string $condition, + Closure|string $expectedSql, + array $expectedParams + ): void { - parent::testDelete($table, $condition, $expectedSQL, $expectedParams); + parent::testDelete($table, $condition, $expectedSql, $expectedParams); } #[DataProviderExternal(QueryBuilderProvider::class, 'lengthBuilder')] public function testLengthBuilder( - string|ExpressionInterface $operand, + Closure|string|ExpressionInterface $operand, string $expectedSql, int $expectedResult, array $expectedParams = [], @@ -869,7 +884,7 @@ public function testLengthBuilder( public function testLengthBuilderWithColumnName(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); $length = new Length('column_name'); @@ -882,7 +897,7 @@ public function testLengthBuilderWithColumnName(): void #[DataProviderExternal(QueryBuilderProvider::class, 'multiOperandFunctionBuilder')] public function testMultiOperandFunctionBuilder( string $class, - array $operands, + Closure|array $operands, string $expectedSql, array|string|int $expectedResult, array $expectedParams = [], @@ -910,7 +925,7 @@ public function testUpsertWithMultiOperandFunctions( public function testArrayMergeWithOrdering(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); $stringParam = new Param('[4,3,5]', DataType::STRING); @@ -918,7 +933,7 @@ public function testArrayMergeWithOrdering(): void [2, 1, 3], new ArrayValue([6, 5, 7]), $stringParam, - self::getDb()->select(new ArrayValue([10, 9])), + $db->select(new ArrayValue([10, 9])), ))->ordered(); $params = []; diff --git a/tests/QueryGetTableAliasTest.php b/tests/QueryGetTableAliasTest.php index d78e988ac..b26904155 100644 --- a/tests/QueryGetTableAliasTest.php +++ b/tests/QueryGetTableAliasTest.php @@ -4,15 +4,13 @@ namespace Yiisoft\Db\Mssql\Tests; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; -use Yiisoft\Db\Tests\AbstractQueryGetTableAliasTest; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Common\CommonQueryGetTableAliasTest; /** * @group mssql - * - * @psalm-suppress PropertyNotSetInConstructor */ -final class QueryGetTableAliasTest extends AbstractQueryGetTableAliasTest +final class QueryGetTableAliasTest extends CommonQueryGetTableAliasTest { - use TestTrait; + use IntegrationTestTrait; } diff --git a/tests/QueryTest.php b/tests/QueryTest.php index 773a84998..bffda727a 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -9,18 +9,16 @@ use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Query\Query; use Yiisoft\Db\Tests\Common\CommonQueryTest; /** * @group mssql - * - * @psalm-suppress PropertyNotSetInConstructor */ final class QueryTest extends CommonQueryTest { - use TestTrait; + use IntegrationTestTrait; /** * Ensure no ambiguous column error occurs on indexBy with JOIN. @@ -29,7 +27,8 @@ final class QueryTest extends CommonQueryTest */ public function testAmbiguousColumnIndexBy(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $selectExpression = 'CONCAT(customer.name, \' in \', p.description) name'; @@ -43,14 +42,9 @@ public function testAmbiguousColumnIndexBy(): void $this->assertSame([1 => 'user1 in profile customer 1', 3 => 'user3 in profile customer 3'], $result); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws Throwable - */ public function testUnion(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $subQueryFromItem = (new Query($db))->select(['id', 'name'])->from('item')->limit(2); $subQueryFromCategory = (new Query($db))->select(['id', 'name'])->from(['category'])->limit(2); @@ -65,7 +59,8 @@ public function testUnion(): void #[DataProvider('dataLikeCaseSensitive')] public function testLikeCaseSensitive(mixed $expected, string $value): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $query = (new Query($db)) ->select('name') diff --git a/tests/QuoterTest.php b/tests/QuoterTest.php index 7e6c58515..d75789309 100644 --- a/tests/QuoterTest.php +++ b/tests/QuoterTest.php @@ -6,15 +6,15 @@ use PHPUnit\Framework\Attributes\DataProviderExternal; use Yiisoft\Db\Mssql\Tests\Provider\QuoterProvider; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; -use Yiisoft\Db\Tests\AbstractQuoterTest; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Common\CommonQuoterTest; /** * @group mssql */ -final class QuoterTest extends AbstractQuoterTest +final class QuoterTest extends CommonQuoterTest { - use TestTrait; + use IntegrationTestTrait; #[DataProviderExternal(QuoterProvider::class, 'columnNames')] public function testQuoteColumnName(string $columnName, string $expected): void diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index a8f37a755..593344e89 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -11,17 +11,17 @@ use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Mssql\Schema; use Yiisoft\Db\Mssql\Tests\Provider\SchemaProvider; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Schema\Column\ColumnInterface; use Yiisoft\Db\Tests\Common\CommonSchemaTest; -use Yiisoft\Db\Tests\Support\DbHelper; +use Yiisoft\Db\Tests\Support\TestHelper; /** * @group mssql */ final class SchemaTest extends CommonSchemaTest { - use TestTrait; + use IntegrationTestTrait; #[DataProviderExternal(SchemaProvider::class, 'columns')] public function testColumns(array $columns, string $tableName): void @@ -31,7 +31,7 @@ public function testColumns(array $columns, string $tableName): void public function testGetDefaultSchema(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $schema = $db->getSchema(); @@ -40,7 +40,8 @@ public function testGetDefaultSchema(): void public function testGetSchemaNames(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $schema = $db->getSchema(); $schemas = $schema->getSchemaNames(); @@ -50,7 +51,8 @@ public function testGetSchemaNames(): void public function testGetViewNames(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $schema = $db->getSchema(); @@ -80,7 +82,7 @@ public function testTableSchemaConstraintsWithPdoUppercase(string $tableName, st #[DataProviderExternal(SchemaProvider::class, 'tableSchemaWithDbSchemes')] public function testTableSchemaWithDbSchemes(string $tableName, string $expectedTableName): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $commandMock = $this->createMock(CommandInterface::class); $commandMock->method('queryAll')->willReturn([]); @@ -99,7 +101,7 @@ function ($params) use ($expectedTableName) { ), ) ->willReturn($commandMock); - $schema = new Schema($mockDb, DbHelper::getSchemaCache()); + $schema = new Schema($mockDb, TestHelper::createMemorySchemaCache()); $schema->getTablePrimaryKey($tableName, true); $db->close(); @@ -108,7 +110,7 @@ function ($params) use ($expectedTableName) { public function testNotConnectionPDO(): void { $db = $this->createMock(ConnectionInterface::class); - $schema = new Schema($db, DbHelper::getSchemaCache()); + $schema = new Schema($db, TestHelper::createMemorySchemaCache()); $this->expectException(NotSupportedException::class); $this->expectExceptionMessage('Only PDO connections are supported.'); @@ -118,7 +120,8 @@ public function testNotConnectionPDO(): void public function testNegativeDefaultValues(): void { - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(); $schema = $db->getSchema(); $table = $schema->getTableSchema('negative_default_values'); diff --git a/tests/SqlParserTest.php b/tests/SqlParserTest.php index 593506f7f..8b0189e28 100644 --- a/tests/SqlParserTest.php +++ b/tests/SqlParserTest.php @@ -4,15 +4,17 @@ namespace Yiisoft\Db\Mssql\Tests; +use PHPUnit\Framework\Attributes\DataProviderExternal; use Yiisoft\Db\Mssql\SqlParser; -use Yiisoft\Db\Tests\AbstractSqlParserTest; +use Yiisoft\Db\Mssql\Tests\Provider\SqlParserProvider; +use Yiisoft\Db\Tests\Common\CommonSqlParserTest; /** * @group mssql */ -final class SqlParserTest extends AbstractSqlParserTest +final class SqlParserTest extends CommonSqlParserTest { - /** @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\SqlParserProvider::getNextPlaceholder */ + #[DataProviderExternal(SqlParserProvider::class, 'getNextPlaceholder')] public function testGetNextPlaceholder(string $sql, ?string $expectedPlaceholder, ?int $expectedPosition): void { parent::testGetNextPlaceholder($sql, $expectedPlaceholder, $expectedPosition); diff --git a/tests/Support/IntegrationTestTrait.php b/tests/Support/IntegrationTestTrait.php new file mode 100644 index 000000000..deb845f4a --- /dev/null +++ b/tests/Support/IntegrationTestTrait.php @@ -0,0 +1,29 @@ +getSchema()->refresh(); + return $db; + } + + public static function dsn(): string + { + return self::$dsn ??= (string) new Dsn( + host: self::host(), + databaseName: self::databaseName(), + port: self::port(), + options: ['Encrypt' => 'no'], + ); + } + + public static function create(?string $dsn = null): Connection + { + return new Connection(self::createDriver($dsn), TestHelper::createMemorySchemaCache()); + } + + public static function createDriver(?string $dsn = null): Driver + { + return new Driver($dsn ?? self::dsn(), self::username(), self::password()); + } + + public static function databaseName(): string + { + return getenv('YII_MSSQL_DATABASE') ?: 'yiitest'; + } + + private static function host(): string + { + return getenv('YII_MSSQL_HOST') ?: '127.0.0.1'; + } + + private static function port(): string + { + return getenv('YII_MSSQL_PORT') ?: '1433'; + } + + private static function username(): string + { + return getenv('YII_MSSQL_USER') ?: 'SA'; + } + + private static function password(): string + { + return getenv('YII_MSSQL_PASSWORD') ?: 'YourStrong!Passw0rd'; + } +} diff --git a/tests/Support/TestTrait.php b/tests/Support/TestTrait.php deleted file mode 100644 index 6997b799e..000000000 --- a/tests/Support/TestTrait.php +++ /dev/null @@ -1,110 +0,0 @@ -close(); - } - - protected function getConnection(bool $fixture = false): Connection - { - $db = new Connection($this->getDriver(), DbHelper::getSchemaCache()); - - if ($fixture) { - DbHelper::loadFixture($db, __DIR__ . "/Fixture/$this->fixture"); - } - - return $db; - } - - protected static function getDb(): Connection - { - $dsn = (string) new Dsn( - host: self::getHost(), - databaseName: self::getDatabaseName(), - port: self::getPort(), - options: ['Encrypt' => 'no'], - ); - - return new Connection( - new Driver($dsn, self::getUsername(), self::getPassword()), - DbHelper::getSchemaCache(), - ); - } - - protected function getDsn(): string - { - if ($this->dsn === '') { - $this->dsn = (string) new Dsn( - host: self::getHost(), - databaseName: self::getDatabaseName(), - port: self::getPort(), - options: ['Encrypt' => 'no'], - ); - } - - return $this->dsn; - } - - protected static function getDriverName(): string - { - return 'sqlsrv'; - } - - protected function setDsn(string $dsn): void - { - $this->dsn = $dsn; - } - - protected function setFixture(string $fixture): void - { - $this->fixture = $fixture; - } - - protected function getDriver(): Driver - { - return new Driver($this->getDsn(), self::getUsername(), self::getPassword()); - } - - private static function getDatabaseName(): string - { - return getenv('YII_MSSQL_DATABASE') ?: 'yiitest'; - } - - private static function getHost(): string - { - return getenv('YII_MSSQL_HOST') ?: '127.0.0.1'; - } - - private static function getPort(): string - { - return getenv('YII_MSSQL_PORT') ?: '1433'; - } - - private static function getUsername(): string - { - return getenv('YII_MSSQL_USER') ?: 'SA'; - } - - private static function getPassword(): string - { - return getenv('YII_MSSQL_PASSWORD') ?: 'YourStrong!Passw0rd'; - } -} diff --git a/tests/TableSchemaTest.php b/tests/TableSchemaTest.php index d8a443304..282b7b3c3 100644 --- a/tests/TableSchemaTest.php +++ b/tests/TableSchemaTest.php @@ -6,17 +6,12 @@ use PHPUnit\Framework\TestCase; use Yiisoft\Db\Mssql\TableSchema; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; /** * @group mssql - * - * @psalm-suppress PropertyNotSetInConstructor */ final class TableSchemaTest extends TestCase { - use TestTrait; - public function testConstructorWithTableSchemaCatalogServer(): void { $tableSchema = new TableSchema('test', 'dbo', 'catalog', 'server'); diff --git a/tests/Type/BigIntTest.php b/tests/Type/BigIntTest.php index 276c19e1f..e11b844bc 100644 --- a/tests/Type/BigIntTest.php +++ b/tests/Type/BigIntTest.php @@ -4,33 +4,21 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; -use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; + +use function dirname; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/int-bigint-smallint-and-tinyint-transact-sql?view=sql-server-ver16 */ -final class BigIntTest extends TestCase +final class BigIntTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithDefaultValue(): void { $db = $this->buildTable(); @@ -43,13 +31,6 @@ public function testCreateTableWithDefaultValue(): void $db->createCommand()->dropTable('bigint_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -69,18 +50,11 @@ public function testCreateTableWithInsert(): void $db->createCommand()->dropTable('bigint_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValue(): void { - $this->setFixture('Type/bigint.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bigint.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('bigint_default'); $this->assertSame('bigint', $tableSchema?->getColumn('Mybigint')->getDbType()); @@ -89,18 +63,11 @@ public function testDefaultValue(): void $db->createCommand()->dropTable('bigint_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/bigint.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bigint.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('bigint_default', [])->execute(); @@ -119,18 +86,12 @@ public function testDefaultValueWithInsert(): void /** * Max value is `9223372036854775807`, but when the value is greater than `9223372036854775807` it is out of range * and save as `9223372036854775807`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMaxValue(): void { - $this->setFixture('Type/bigint.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bigint.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('bigint', ['Mybigint1' => '9223372036854775807', 'Mybigint2' => '0'])->execute(); @@ -168,18 +129,12 @@ public function testMaxValue(): void /** * Min value is `-9223372036854775808`, but when the value is less than `-9223372036854775808` it is out of range * and save as `-9223372036854775808`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMinValue(): void { - $this->setFixture('Type/bigint.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bigint.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('bigint', ['Mybigint1' => '-9223372036854775808', 'Mybigint2' => '0'])->execute(); @@ -216,7 +171,7 @@ public function testMinValue(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/BinaryTest.php b/tests/Type/BinaryTest.php index f26e85ce3..73c85c135 100644 --- a/tests/Type/BinaryTest.php +++ b/tests/Type/BinaryTest.php @@ -12,27 +12,20 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/binary-and-varbinary-transact-sql?view=sql-server-ver16 */ -final class BinaryTest extends TestCase +final class BinaryTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; /** * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Type\BinaryProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testCreateTableWithDefaultValue( string $column, @@ -52,13 +45,6 @@ public function testCreateTableWithDefaultValue( $db->createCommand()->dropTable('binary_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -80,12 +66,6 @@ public function testCreateTableWithInsert(): void /** * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Type\BinaryProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testDefaultValue( string $column, @@ -94,9 +74,9 @@ public function testDefaultValue( int $size, Expression $defaultValue, ): void { - $this->setFixture('Type/binary.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/binary.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('binary_default'); $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); @@ -106,18 +86,11 @@ public function testDefaultValue( $db->createCommand()->dropTable('binary_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/binary.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/binary.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('binary_default', [])->execute(); @@ -135,18 +108,12 @@ public function testDefaultValueWithInsert(): void /** * When the value is greater than the maximum value, the value is truncated. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMaxValue(): void { - $this->setFixture('Type/binary.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/binary.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('binary', [ 'Mybinary1' => new Expression('CONVERT(binary(10), \'binary_default_value\')'), @@ -171,18 +138,11 @@ public function testMaxValue(): void $db->createCommand()->dropTable('binary')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testValue(): void { - $this->setFixture('Type/binary.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/binary.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('binary', [ 'Mybinary1' => new Expression('CONVERT(binary(10), \'binary\')'), @@ -211,7 +171,7 @@ public function testValue(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/BitTest.php b/tests/Type/BitTest.php index 078af730b..fd1418530 100644 --- a/tests/Type/BitTest.php +++ b/tests/Type/BitTest.php @@ -11,27 +11,20 @@ use InvalidArgumentException; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/bit-transact-sql?view=sql-server-ver16 */ -final class BitTest extends TestCase +final class BitTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; /** * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Type\BitProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testCreateTableWithDefaultValue( string $column, @@ -49,13 +42,6 @@ public function testCreateTableWithDefaultValue( $db->createCommand()->dropTable('bit_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -77,12 +63,6 @@ public function testCreateTableWithInsert(): void /** * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Type\BitProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testDefaultValue( string $column, @@ -90,9 +70,9 @@ public function testDefaultValue( string $phpType, bool $defaultValue, ): void { - $this->setFixture('Type/bit.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bit.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('bit_default'); $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); @@ -101,18 +81,11 @@ public function testDefaultValue( $db->createCommand()->dropTable('bit_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/bit.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bit.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('bit_default', [])->execute(); @@ -128,18 +101,11 @@ public function testDefaultValueWithInsert(): void $db->createCommand()->dropTable('bit_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testBoolean(): void { - $this->setFixture('Type/bit.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bit.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('bit', ['Mybit1' => true, 'Mybit2' => false, 'Mybit3' => true])->execute(); @@ -162,18 +128,12 @@ public function testBoolean(): void /** * Max value is `1`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMaxValue(): void { - $this->setFixture('Type/bit.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bit.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('bit', ['Mybit1' => 1, 'Mybit2' => 1, 'Mybit3' => 1])->execute(); @@ -213,19 +173,13 @@ public function testMaxValue(): void /** * Min value is `0`. * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - * - * @https://learn.microsoft.com/en-us/sql/t-sql/data-types/bit-transact-sql?view=sql-server-ver16#remarks + * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/bit-transact-sql?view=sql-server-ver16#remarks */ public function testMinValue(): void { - $this->setFixture('Type/bit.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bit.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('bit', ['Mybit1' => 0, 'Mybit2' => 0, 'Mybit3' => 0])->execute(); @@ -264,7 +218,7 @@ public function testMinValue(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/CharTest.php b/tests/Type/CharTest.php index c71d95186..214fa0f94 100644 --- a/tests/Type/CharTest.php +++ b/tests/Type/CharTest.php @@ -4,34 +4,22 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/char-and-varchar-transact-sql?view=sql-server-ver16 */ -final class CharTest extends TestCase +final class CharTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; /** * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Type\CharProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testCreateTableWithDefaultValue( string $column, @@ -51,13 +39,6 @@ public function testCreateTableWithDefaultValue( $db->createCommand()->dropTable('char_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -79,12 +60,6 @@ public function testCreateTableWithInsert(): void /** * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Type\CharProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testDefaultValue( string $column, @@ -93,9 +68,9 @@ public function testDefaultValue( int $size, string $defaultValue, ): void { - $this->setFixture('Type/char.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/char.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('char_default'); $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); @@ -105,18 +80,11 @@ public function testDefaultValue( $db->createCommand()->dropTable('char_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/char.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/char.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('char_default', [])->execute(); @@ -132,18 +100,11 @@ public function testDefaultValueWithInsert(): void $db->createCommand()->dropTable('char_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testValue(): void { - $this->setFixture('Type/char.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/char.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'char', @@ -173,18 +134,11 @@ public function testValue(): void $db->createCommand()->dropTable('char')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testValueException(): void { - $this->setFixture('Type/char.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/char.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -197,7 +151,7 @@ public function testValueException(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/DateTest.php b/tests/Type/DateTest.php index 011149ed4..4508f15bd 100644 --- a/tests/Type/DateTest.php +++ b/tests/Type/DateTest.php @@ -14,27 +14,20 @@ use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Mssql\Column\ColumnBuilder; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/date-transact-sql?view=sql-server-ver16 */ -final class DateTest extends TestCase +final class DateTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; /** * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Type\DateProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testCreateTableWithDefaultValue( string $column, @@ -52,13 +45,6 @@ public function testCreateTableWithDefaultValue( $db->createCommand()->insert('date_default', [])->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -80,12 +66,6 @@ public function testCreateTableWithInsert(): void /** * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Type\DateProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testDefaultValue( string $column, @@ -93,9 +73,9 @@ public function testDefaultValue( string $phpType, DateTimeImmutable $defaultValue, ): void { - $this->setFixture('Type/date.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/date.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('date_default'); $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); @@ -104,18 +84,11 @@ public function testDefaultValue( $db->createCommand()->dropTable('date_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/date.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/date.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('date_default', [])->execute(); @@ -131,18 +104,11 @@ public function testDefaultValueWithInsert(): void $db->createCommand()->dropTable('date_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testValue(): void { - $this->setFixture('Type/date.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/date.sql'); - $db = $this->getConnection(true); $command = $db->createCommand()->withDbTypecasting(false); $command->insert('date', [ 'Mydate1' => '2007-05-08', @@ -177,18 +143,10 @@ public function testValue(): void $db->createCommand()->dropTable('date')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testValueException(): void { - $this->setFixture('Type/date.sql'); - - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/date.sql'); $this->expectException(Exception::class); $this->expectExceptionMessage( @@ -200,7 +158,7 @@ public function testValueException(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/DecimalTest.php b/tests/Type/DecimalTest.php index 7cf8b446d..e699a8d75 100644 --- a/tests/Type/DecimalTest.php +++ b/tests/Type/DecimalTest.php @@ -12,26 +12,18 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/decimal-and-numeric-transact-sql?view=sql-server-ver16 */ -final class DecimalTest extends TestCase +final class DecimalTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithDefaultValue(): void { $db = $this->buildTable(); @@ -45,13 +37,6 @@ public function testCreateTableWithDefaultValue(): void $db->createCommand()->insert('decimal_default', [])->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -71,18 +56,11 @@ public function testCreateTableWithInsert(): void $db->createCommand()->dropTable('decimal_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValue(): void { - $this->setFixture('Type/decimal.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/decimal.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('decimal_default'); $this->assertSame('decimal', $tableSchema?->getColumn('Mydecimal')->getDbType()); @@ -92,18 +70,11 @@ public function testDefaultValue(): void $db->createCommand()->dropTable('decimal_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/decimal.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/decimal.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('decimal_default', [])->execute(); @@ -121,18 +92,12 @@ public function testDefaultValueWithInsert(): void /** * Max value is `99999999999999997748809823456034029568`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMaxValue(): void { - $this->setFixture('Type/decimal.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/decimal.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'decimal', @@ -171,18 +136,11 @@ public function testMaxValue(): void ); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testMaxValueException(): void { - $this->setFixture('Type/decimal.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/decimal.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -198,18 +156,12 @@ public function testMaxValueException(): void /** * Min value is `-99999999999999997748809823456034029569`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMinValue(): void { - $this->setFixture('Type/decimal.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/decimal.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'decimal', @@ -248,18 +200,11 @@ public function testMinValue(): void ); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testMinValueException(): void { - $this->setFixture('Type/decimal.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/decimal.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -275,7 +220,7 @@ public function testMinValueException(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/FloatTest.php b/tests/Type/FloatTest.php index 045c42e30..a2fa1ef5b 100644 --- a/tests/Type/FloatTest.php +++ b/tests/Type/FloatTest.php @@ -12,26 +12,18 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/float-and-real-transact-sql?view=sql-server-ver16 */ -final class FloatTest extends TestCase +final class FloatTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithDefaultValue(): void { $db = $this->buildTable(); @@ -44,13 +36,6 @@ public function testCreateTableWithDefaultValue(): void $db->createCommand()->insert('float_default', [])->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -70,18 +55,11 @@ public function testCreateTableWithInsert(): void $db->createCommand()->dropTable('float_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValue(): void { - $this->setFixture('Type/float.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/float.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('float_default'); $this->assertSame('float', $tableSchema?->getColumn('Myfloat')->getDbType()); @@ -93,18 +71,11 @@ public function testDefaultValue(): void $db->createCommand()->insert('float_default', [])->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/float.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/float.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('float_default', [])->execute(); @@ -122,18 +93,12 @@ public function testDefaultValueWithInsert(): void /** * Max value is `1.79E+308`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMaxValue(): void { - $this->setFixture('Type/float.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/float.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('float', ['Myfloat1' => '1.79E+308', 'Myfloat2' => '0'])->execute(); @@ -168,18 +133,11 @@ public function testMaxValue(): void $db->createCommand()->dropTable('float')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testMaxValueException(): void { - $this->setFixture('Type/float.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/float.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -192,18 +150,12 @@ public function testMaxValueException(): void /** * Min value is `-1.79E+308`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMinValue(): void { - $this->setFixture('Type/float.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/float.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('float', ['Myfloat1' => '-1.79E+308', 'Myfloat2' => '0'])->execute(); @@ -238,18 +190,11 @@ public function testMinValue(): void $db->createCommand()->dropTable('float')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testMinValueException(): void { - $this->setFixture('Type/float.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/float.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -262,7 +207,7 @@ public function testMinValueException(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/GeometryTest.php b/tests/Type/GeometryTest.php index 9ff6f4010..0182343ec 100644 --- a/tests/Type/GeometryTest.php +++ b/tests/Type/GeometryTest.php @@ -12,27 +12,20 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/spatial-geometry/spatial-types-geometry-transact-sql?view=sql-server-ver16 */ -final class GeometryTest extends TestCase +final class GeometryTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; /** * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Type\GeometryProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testCreateTableWithDefaultValue( string $column, @@ -50,13 +43,6 @@ public function testCreateTableWithDefaultValue( $db->createCommand()->dropTable('geometry_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -78,12 +64,6 @@ public function testCreateTableWithInsert(): void /** * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Type\GeometryProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testDefaultValue( string $column, @@ -91,9 +71,9 @@ public function testDefaultValue( string $phpType, ?Expression $defaultValue, ): void { - $this->setFixture('Type/geometry.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/geometry.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('geometry_default'); $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); @@ -102,18 +82,11 @@ public function testDefaultValue( $db->createCommand()->dropTable('geometry_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/geometry.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/geometry.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('geometry_default', [])->execute(); @@ -129,18 +102,11 @@ public function testDefaultValueWithInsert(): void $db->createCommand()->dropTable('geometry_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testValue(): void { - $this->setFixture('Type/geometry.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/geometry.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'geometry', @@ -167,7 +133,7 @@ public function testValue(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/ImageTest.php b/tests/Type/ImageTest.php index 0c8c14842..419c577c0 100644 --- a/tests/Type/ImageTest.php +++ b/tests/Type/ImageTest.php @@ -12,26 +12,18 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/ntext-text-and-image-transact-sql?view=sql-server-ver16 */ -final class ImageTest extends TestCase +final class ImageTest extends IntegrationTestCase { - use TestTrait; - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ + use IntegrationTestTrait; + public function testCreateTableWithDefaultValue(): void { $db = $this->buildTable(); @@ -44,13 +36,6 @@ public function testCreateTableWithDefaultValue(): void $db->createCommand()->dropTable('image_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -70,18 +55,11 @@ public function testCreateTableWithInsert(): void $db->createCommand()->dropTable('image_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValue(): void { - $this->setFixture('Type/image.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/image.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('image_default'); $this->assertSame('image', $tableSchema?->getColumn('Myimage')->getDbType()); @@ -90,18 +68,11 @@ public function testDefaultValue(): void $db->createCommand()->dropTable('image_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/image.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/image.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('image_default', [])->execute(); @@ -117,18 +88,11 @@ public function testDefaultValueWithInsert(): void $db->createCommand()->dropTable('image_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testValue(): void { - $this->setFixture('Type/image.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/image.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'image', @@ -153,7 +117,7 @@ public function testValue(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/IntTest.php b/tests/Type/IntTest.php index 804853200..befe6a874 100644 --- a/tests/Type/IntTest.php +++ b/tests/Type/IntTest.php @@ -7,16 +7,19 @@ use PHPUnit\Framework\TestCase; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; + +use function dirname; /** * @group mssql * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/int-bigint-smallint-and-tinyint-transact-sql?view=sql-server-ver16 */ -final class IntTest extends TestCase +final class IntTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; public function testCreateTableWithDefaultValue(): void { @@ -51,9 +54,9 @@ public function testCreateTableWithInsert(): void public function testDefaultValue(): void { - $this->setFixture('Type/int.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/int.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('int_default'); $this->assertSame('int', $tableSchema?->getColumn('Myint')->getDbType()); @@ -64,9 +67,9 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/int.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/int.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('int_default', [])->execute(); @@ -87,9 +90,9 @@ public function testDefaultValueWithInsert(): void */ public function testMaxValue(): void { - $this->setFixture('Type/int.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/int.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('int', ['Myint1' => 2_147_483_647, 'Myint2' => 0])->execute(); @@ -126,9 +129,9 @@ public function testMaxValue(): void public function testMaxValueException(): void { - $this->setFixture('Type/int.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/int.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -144,9 +147,9 @@ public function testMaxValueException(): void */ public function testMinValue(): void { - $this->setFixture('Type/int.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/int.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('int', ['Myint1' => -2_147_483_648, 'Myint2' => 0])->execute(); @@ -183,9 +186,9 @@ public function testMinValue(): void public function testMinValueException(): void { - $this->setFixture('Type/int.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/int.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -198,8 +201,9 @@ public function testMinValueException(): void public function testIdentityTypecasting(): void { - $this->setFixture('Type/int.sql'); - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/int.sql'); + $db->createCommand()->insert('int', ['Myint1' => 1])->execute(); $result = $db @@ -214,7 +218,7 @@ public function testIdentityTypecasting(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/JsonTest.php b/tests/Type/JsonTest.php index 0093fa219..962dc6dda 100644 --- a/tests/Type/JsonTest.php +++ b/tests/Type/JsonTest.php @@ -11,26 +11,18 @@ use InvalidArgumentException; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/date-transact-sql?view=sql-server-ver16 */ -final class JsonTest extends TestCase +final class JsonTest extends IntegrationTestCase { - use TestTrait; - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ + use IntegrationTestTrait; + public function testCreateTableWithDefaultValue(): void { $db = $this->buildTable(); @@ -43,13 +35,6 @@ public function testCreateTableWithDefaultValue(): void $db->createCommand()->dropTable('json_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -69,18 +54,11 @@ public function testCreateTableWithInsert(): void $db->createCommand()->dropTable('json_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValue(): void { - $this->setFixture('Type/json.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/json.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('json_default'); $this->assertSame('nvarchar', $tableSchema?->getColumn('Myjson')->getDbType()); @@ -89,18 +67,11 @@ public function testDefaultValue(): void $db->createCommand()->dropTable('json_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/json.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/json.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('json_default', [])->execute(); @@ -116,18 +87,11 @@ public function testDefaultValueWithInsert(): void $db->createCommand()->dropTable('json_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testInvalidValue(): void { - $this->setFixture('Type/json.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/json.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('json', ['Myjson' => 'invalid'])->execute(); @@ -141,18 +105,11 @@ public function testInvalidValue(): void ); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testValidValue(): void { - $this->setFixture('Type/json.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/json.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('json', ['Myjson' => '{"a":1,"b":2,"c":3,"d":4,"e":5}'])->execute(); @@ -166,18 +123,11 @@ public function testValidValue(): void ); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testValue(): void { - $this->setFixture('Type/json.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/json.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('json', ['Myjson' => '{"a":1,"b":2,"c":3,"d":4,"e":5}'])->execute(); @@ -242,7 +192,7 @@ public function testValue(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/MoneyTest.php b/tests/Type/MoneyTest.php index a7ab787d0..0c2c3e597 100644 --- a/tests/Type/MoneyTest.php +++ b/tests/Type/MoneyTest.php @@ -11,26 +11,18 @@ use InvalidArgumentException; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/money-and-smallmoney-transact-sql?view=sql-server-ver16 */ -final class MoneyTest extends TestCase +final class MoneyTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithDefaultValue(): void { $db = $this->buildTable(); @@ -43,13 +35,6 @@ public function testCreateTableWithDefaultValue(): void $db->createCommand()->dropTable('money_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -69,18 +54,11 @@ public function testCreateTableWithInsert(): void $db->createCommand()->dropTable('money_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValue(): void { - $this->setFixture('Type/money.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/money.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('money_default'); $this->assertSame('money', $tableSchema->getColumn('Mymoney')->getDbType()); @@ -89,18 +67,11 @@ public function testDefaultValue(): void $db->createCommand()->dropTable('money_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/money.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/money.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('money_default', [])->execute(); @@ -118,18 +89,12 @@ public function testDefaultValueWithInsert(): void /** * Max value is `922337203685477.5807`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMaxValue(): void { - $this->setFixture('Type/money.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/money.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('money', ['Mymoney1' => '922337203685477.5807', 'Mymoney2' => '0'])->execute(); @@ -164,18 +129,11 @@ public function testMaxValue(): void $db->createCommand()->dropTable('money')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testMaxValueException(): void { - $this->setFixture('Type/money.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/money.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -188,18 +146,12 @@ public function testMaxValueException(): void /** * Min value is `-922337203685477.5808`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMinValue(): void { - $this->setFixture('Type/money.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/money.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('money', ['Mymoney1' => '-922337203685477.5808', 'Mymoney2' => 0])->execute(); @@ -234,18 +186,11 @@ public function testMinValue(): void $db->createCommand()->dropTable('money')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testMinValueException(): void { - $this->setFixture('Type/money.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/money.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -258,7 +203,7 @@ public function testMinValueException(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/NTextTest.php b/tests/Type/NTextTest.php index 9898ff8af..3791238d1 100644 --- a/tests/Type/NTextTest.php +++ b/tests/Type/NTextTest.php @@ -11,7 +11,8 @@ use InvalidArgumentException; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql @@ -20,17 +21,10 @@ * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/ntext-text-and-image-transact-sql?view=sql-server-ver16 */ -final class NTextTest extends TestCase +final class NTextTest extends IntegrationTestCase { - use TestTrait; - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ + use IntegrationTestTrait; + public function testCreateTableWithDefaultValue(): void { $db = $this->buildTable(); @@ -43,13 +37,6 @@ public function testCreateTableWithDefaultValue(): void $db->createCommand()->dropTable('ntext_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -69,18 +56,11 @@ public function testCreateTableWithInsert(): void $db->createCommand()->dropTable('ntext_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValue(): void { - $this->setFixture('Type/ntext.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/ntext.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('ntext_default'); $this->assertSame('ntext', $tableSchema?->getColumn('Myntext')->getDbType()); @@ -89,18 +69,11 @@ public function testDefaultValue(): void $db->createCommand()->dropTable('ntext_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/ntext.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/ntext.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('ntext_default', [])->execute(); @@ -116,18 +89,11 @@ public function testDefaultValueWithInsert(): void $db->createCommand()->dropTable('ntext_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testValue(): void { - $this->setFixture('Type/ntext.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/ntext.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('ntext', ['Myntext1' => '0123456789', 'Myntext2' => null])->execute(); @@ -149,7 +115,7 @@ public function testValue(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/NumericTest.php b/tests/Type/NumericTest.php index b25e427bb..2c85fd890 100644 --- a/tests/Type/NumericTest.php +++ b/tests/Type/NumericTest.php @@ -12,26 +12,18 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/decimal-and-numeric-transact-sql?view=sql-server-ver16 */ -final class NumericTest extends TestCase +final class NumericTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithDefaultValue(): void { $db = $this->buildTable(); @@ -45,13 +37,6 @@ public function testCreateTableWithDefaultValue(): void $db->createCommand()->dropTable('numeric_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -71,18 +56,11 @@ public function testCreateTableWithInsert(): void $db->createCommand()->dropTable('numeric_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValue(): void { - $this->setFixture('Type/numeric.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/numeric.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('numeric_default'); $this->assertSame('numeric', $tableSchema?->getColumn('Mynumeric')->getDbType()); @@ -92,18 +70,11 @@ public function testDefaultValue(): void $db->createCommand()->dropTable('numeric_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/numeric.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/numeric.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('numeric_default', [])->execute(); @@ -121,18 +92,12 @@ public function testDefaultValueWithInsert(): void /** * Max value is `99999999999999997748809823456034029568`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMaxValue(): void { - $this->setFixture('Type/numeric.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/numeric.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'numeric', @@ -175,18 +140,12 @@ public function testMaxValue(): void /** * Min value is `-99999999999999997748809823456034029569`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMinValue(): void { - $this->setFixture('Type/numeric.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/numeric.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'numeric', @@ -227,18 +186,11 @@ public function testMinValue(): void $db->createCommand()->dropTable('numeric')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testMinValueException(): void { - $this->setFixture('Type/numeric.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/numeric.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -254,7 +206,7 @@ public function testMinValueException(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/RealTest.php b/tests/Type/RealTest.php index 5bb6de0bc..1e2c86eb3 100644 --- a/tests/Type/RealTest.php +++ b/tests/Type/RealTest.php @@ -12,26 +12,18 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/float-and-real-transact-sql?view=sql-server-ver16 */ -final class RealTest extends TestCase +final class RealTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithDefaultValue(): void { $db = $this->buildtable(); @@ -44,13 +36,6 @@ public function testCreateTableWithDefaultValue(): void $db->createCommand()->dropTable('real_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -70,18 +55,11 @@ public function testCreateTableWithInsert(): void $db->createCommand()->dropTable('real_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValue(): void { - $this->setFixture('Type/real.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/real.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('real_default'); $this->assertSame('real', $tableSchema?->getColumn('Myreal')->getDbType()); @@ -90,18 +68,11 @@ public function testDefaultValue(): void $db->createCommand()->dropTable('real_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/real.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/real.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('real_default', [])->execute(); @@ -119,18 +90,12 @@ public function testDefaultValueWithInsert(): void /** * Max value is `3.4E+38`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMaxValue(): void { - $this->setFixture('Type/real.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/real.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('real', ['Myreal1' => '3.4E+38', 'Myreal2' => '0'])->execute(); @@ -165,18 +130,11 @@ public function testMaxValue(): void $db->createCommand()->dropTable('real')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testMaxValueException(): void { - $this->setFixture('Type/real.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/real.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -189,18 +147,12 @@ public function testMaxValueException(): void /** * Min value is `-3.40E+38`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMinValue(): void { - $this->setFixture('Type/real.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/real.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('real', ['Myreal1' => '-3.4E+38', 'Myreal2' => '0'])->execute(); @@ -235,18 +187,11 @@ public function testMinValue(): void $db->createCommand()->dropTable('real')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testMinValueException(): void { - $this->setFixture('Type/real.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/real.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -259,7 +204,7 @@ public function testMinValueException(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/RowversionTest.php b/tests/Type/RowversionTest.php index 276f5eee7..c10fe9300 100644 --- a/tests/Type/RowversionTest.php +++ b/tests/Type/RowversionTest.php @@ -10,31 +10,23 @@ use InvalidArgumentException; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/rowversion-transact-sql?view=sql-server-ver16 */ -final class RowversionTest extends TestCase +final class RowversionTest extends IntegrationTestCase { - use TestTrait; - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ + use IntegrationTestTrait; + public function testValue(): void { - $this->setFixture('Type/rowversion.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/rowversion.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('rowversion'); $this->assertSame('timestamp', $tableSchema?->getColumn('Myrowversion')->getDbType()); diff --git a/tests/Type/SmallIntTest.php b/tests/Type/SmallIntTest.php index 96ae8dd48..e638934cf 100644 --- a/tests/Type/SmallIntTest.php +++ b/tests/Type/SmallIntTest.php @@ -11,26 +11,18 @@ use InvalidArgumentException; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/int-bigint-smallint-and-tinyint-transact-sql?view=sql-server-ver16 */ -final class SmallIntTest extends TestCase +final class SmallIntTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithDefaultValue(): void { $db = $this->buildTable(); @@ -43,13 +35,6 @@ public function testCreateTableWithDefaultValue(): void $db->createCommand()->dropTable('smallint_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -69,18 +54,11 @@ public function testCreateTableWithInsert(): void $db->createCommand()->dropTable('smallint_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValue(): void { - $this->setFixture('Type/smallint.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallint.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('smallint_default'); $this->assertSame('smallint', $tableSchema?->getColumn('Mysmallint')->getDbType()); @@ -89,18 +67,11 @@ public function testDefaultValue(): void $db->createCommand()->dropTable('smallint_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/smallint.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallint.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('smallint_default', [])->execute(); @@ -118,18 +89,12 @@ public function testDefaultValueWithInsert(): void /** * Max value is `32767`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMaxValue(): void { - $this->setFixture('Type/smallint.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallint.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('smallint', ['Mysmallint1' => 32767, 'Mysmallint2' => 0])->execute(); @@ -164,18 +129,11 @@ public function testMaxValue(): void $db->createCommand()->dropTable('smallint')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testMaxValueException(): void { - $this->setFixture('Type/smallint.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallint.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -188,18 +146,12 @@ public function testMaxValueException(): void /** * Min value is `-32768`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMinValue(): void { - $this->setFixture('Type/smallint.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallint.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('smallint', ['Mysmallint1' => -32768, 'Mysmallint2' => 0])->execute(); @@ -234,18 +186,11 @@ public function testMinValue(): void $db->createCommand()->dropTable('smallint')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testMinValueException(): void { - $this->setFixture('Type/smallint.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallint.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -258,7 +203,7 @@ public function testMinValueException(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/SmallMoneyTest.php b/tests/Type/SmallMoneyTest.php index 5d822200f..554335d51 100644 --- a/tests/Type/SmallMoneyTest.php +++ b/tests/Type/SmallMoneyTest.php @@ -11,26 +11,18 @@ use InvalidArgumentException; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/money-and-smallmoney-transact-sql?view=sql-server-ver16 */ -final class SmallMoneyTest extends TestCase +final class SmallMoneyTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithDefaultValue(): void { $db = $this->buildTable(); @@ -43,13 +35,6 @@ public function testCreateTableWithDefaultValue(): void $db->createCommand()->dropTable('smallmoney_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -69,18 +54,11 @@ public function testCreateTableWithInsert(): void $db->createCommand()->dropTable('smallmoney_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValue(): void { - $this->setFixture('Type/smallmoney.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallmoney.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('smallmoney_default'); $this->assertSame('smallmoney', $tableSchema?->getColumn('Mysmallmoney')->getDbType()); @@ -89,18 +67,11 @@ public function testDefaultValue(): void $db->createCommand()->dropTable('smallmoney_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/smallmoney.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallmoney.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('smallmoney_default', [])->execute(); @@ -118,18 +89,12 @@ public function testDefaultValueWithInsert(): void /** * Max value is `214748.3647`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMaxValue(): void { - $this->setFixture('Type/smallmoney.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallmoney.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('smallmoney', ['Mysmallmoney1' => '214748.3647', 'Mysmallmoney2' => '0'])->execute(); @@ -164,18 +129,11 @@ public function testMaxValue(): void $db->createCommand()->dropTable('smallmoney')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testMaxValueException(): void { - $this->setFixture('Type/smallmoney.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallmoney.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -188,18 +146,12 @@ public function testMaxValueException(): void /** * Min value is `-214748.3648`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMinValue(): void { - $this->setFixture('Type/smallmoney.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallmoney.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('smallmoney', ['Mysmallmoney1' => '-214748.3648', 'Mysmallmoney2' => 0])->execute(); @@ -234,18 +186,11 @@ public function testMinValue(): void $db->createCommand()->dropTable('smallmoney')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testMinValueException(): void { - $this->setFixture('Type/smallmoney.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallmoney.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -258,7 +203,7 @@ public function testMinValueException(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/TextTest.php b/tests/Type/TextTest.php index ae9d305f5..044727adc 100644 --- a/tests/Type/TextTest.php +++ b/tests/Type/TextTest.php @@ -11,26 +11,20 @@ use InvalidArgumentException; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; + +use function dirname; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/ntext-text-and-image-transact-sql?view=sql-server-ver16 */ -final class TextTest extends TestCase +final class TextTest extends IntegrationTestCase { - use TestTrait; - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ + use IntegrationTestTrait; + public function testCreateTableWithDefaultValue(): void { $db = $this->buildTable(); @@ -43,13 +37,6 @@ public function testCreateTableWithDefaultValue(): void $db->createCommand()->dropTable('text_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -69,18 +56,11 @@ public function testCreateTableWithInsert(): void $db->createCommand()->dropTable('text_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValue(): void { - $this->setFixture('Type/text.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/text.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('text_default'); $this->assertSame('text', $tableSchema?->getColumn('Mytext')->getDbType()); @@ -89,18 +69,11 @@ public function testDefaultValue(): void $db->createCommand()->dropTable('text_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/text.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/text.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('text_default', [])->execute(); @@ -116,18 +89,11 @@ public function testDefaultValueWithInsert(): void $db->createCommand()->dropTable('text_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testValue(): void { - $this->setFixture('Type/text.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/text.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('text', ['Mytext1' => '0123456789', 'Mytext2' => null])->execute(); @@ -149,7 +115,7 @@ public function testValue(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/TinyIntTest.php b/tests/Type/TinyIntTest.php index 9c8c4cea0..f5c6b9b9c 100644 --- a/tests/Type/TinyIntTest.php +++ b/tests/Type/TinyIntTest.php @@ -11,26 +11,20 @@ use InvalidArgumentException; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; + +use function dirname; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/int-bigint-smallint-and-tinyint-transact-sql?view=sql-server-ver16 */ -final class TinyIntTest extends TestCase +final class TinyIntTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithDefaultValue(): void { $db = $this->buildTable(); @@ -43,13 +37,6 @@ public function testCreateTableWithDefaultValue(): void $db->createCommand()->dropTable('tinyint_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -69,18 +56,11 @@ public function testCreateTableWithInsert(): void $db->createCommand()->dropTable('tinyint_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValue(): void { - $this->setFixture('Type/tinyint.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/tinyint.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('tinyint_default'); $this->assertSame('tinyint', $tableSchema?->getColumn('Mytinyint')->getDbType()); @@ -89,18 +69,11 @@ public function testDefaultValue(): void $db->createCommand()->dropTable('tinyint_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/tinyint.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/tinyint.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('tinyint_default', [])->execute(); @@ -118,18 +91,12 @@ public function testDefaultValueWithInsert(): void /** * Max value is `255`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMaxValue(): void { - $this->setFixture('Type/tinyint.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/tinyint.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('tinyint', ['Mytinyint1' => 255, 'Mytinyint2' => 0])->execute(); @@ -179,18 +146,11 @@ public function testMaxValue(): void $db->createCommand()->dropTable('tinyint')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testMaxValueException(): void { - $this->setFixture('Type/tinyint.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/tinyint.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -203,18 +163,12 @@ public function testMaxValueException(): void /** * Min value is `0`. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMinValue(): void { - $this->setFixture('Type/tinyint.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/tinyint.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('tinyint', ['Mytinyint1' => 0, 'Mytinyint2' => null])->execute(); @@ -249,18 +203,11 @@ public function testMinValue(): void $db->createCommand()->dropTable('tinyint')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testMinValueException(): void { - $this->setFixture('Type/tinyint.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/tinyint.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -273,7 +220,7 @@ public function testMinValueException(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/UniqueidentifierTest.php b/tests/Type/UniqueidentifierTest.php index 79a823e61..d9a671df0 100644 --- a/tests/Type/UniqueidentifierTest.php +++ b/tests/Type/UniqueidentifierTest.php @@ -11,26 +11,18 @@ use InvalidArgumentException; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/uniqueidentifier-transact-sql?view=sql-server-ver16 */ -final class UniqueidentifierTest extends TestCase +final class UniqueidentifierTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithDefaultValue(): void { $db = $this->buildTable(); @@ -46,13 +38,6 @@ public function testCreateTableWithDefaultValue(): void $db->createCommand()->dropTable('uniqueidentifier_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -72,18 +57,11 @@ public function testCreateTableWithInsert(): void $db->createCommand()->dropTable('uniqueidentifier_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValue(): void { - $this->setFixture('Type/uniqueidentifier.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/uniqueidentifier.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('uniqueidentifier_default'); $this->assertSame('uniqueidentifier', $tableSchema?->getColumn('Myuniqueidentifier')->getDbType()); @@ -95,18 +73,11 @@ public function testDefaultValue(): void $db->createCommand()->dropTable('uniqueidentifier_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/uniqueidentifier.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/uniqueidentifier.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('uniqueidentifier_default', [])->execute(); @@ -124,18 +95,12 @@ public function testDefaultValueWithInsert(): void /** * Max value is 36 characters. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testValue(): void { - $this->setFixture('Type/uniqueidentifier.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/uniqueidentifier.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'uniqueidentifier', @@ -158,18 +123,10 @@ public function testValue(): void $db->createCommand()->dropTable('uniqueidentifier')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testValueException(): void { - $this->setFixture('Type/uniqueidentifier.sql'); - - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/uniqueidentifier.sql'); $this->expectException(Exception::class); $this->expectExceptionMessage( @@ -182,18 +139,12 @@ public function testValueException(): void /** * When you insert a value that is longer than 36 characters, the value is truncated to 36 characters. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testValueLength(): void { - $this->setFixture('Type/uniqueidentifier.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/uniqueidentifier.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'uniqueidentifier', @@ -218,7 +169,7 @@ public function testValueLength(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/VarBinaryTest.php b/tests/Type/VarBinaryTest.php index 4c4f5fba8..7bf36b515 100644 --- a/tests/Type/VarBinaryTest.php +++ b/tests/Type/VarBinaryTest.php @@ -12,29 +12,23 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; + +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; use function str_repeat; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/binary-and-varbinary-transact-sql?view=sql-server-ver16 */ -final class VarBinaryTest extends TestCase +final class VarBinaryTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; /** * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Type\VarBinaryProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testCreateTableWithDefaultValue( string $column, @@ -54,13 +48,6 @@ public function testCreateTableWithDefaultValue( $db->createCommand()->dropTable('varbinary_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -82,12 +69,6 @@ public function testCreateTableWithInsert(): void /** * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Type\VarBinaryProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testDefaultValue( string $column, @@ -96,9 +77,9 @@ public function testDefaultValue( int $size, Expression $defaultValue, ): void { - $this->setFixture('Type/varbinary.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/varbinary.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('varbinary_default'); $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); @@ -108,18 +89,11 @@ public function testDefaultValue( $db->createCommand()->dropTable('varbinary_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/varbinary.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/varbinary.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('varbinary_default', [])->execute(); @@ -137,18 +111,12 @@ public function testDefaultValueWithInsert(): void /** * When the value is greater than the maximum value, the value is truncated. - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testMaxValue(): void { - $this->setFixture('Type/varbinary.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/varbinary.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('varbinary', [ 'Myvarbinary1' => new Expression('CONVERT(varbinary(10), \'binary_default_value\')'), @@ -173,47 +141,9 @@ public function testMaxValue(): void $db->createCommand()->dropTable('varbinary')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testValue(): void - { - $this->setFixture('Type/binary.sql'); - - $db = $this->getConnection(true); - $command = $db->createCommand(); - $command->insert('binary', [ - 'Mybinary1' => new Expression('CONVERT(binary(10), \'binary\')'), - 'Mybinary2' => new Expression('CONVERT(binary(10), null)'), - 'Mybinary3' => new Expression('CONVERT(binary(1), \'b\')'), - 'Mybinary4' => new Expression('CONVERT(binary(1), null)'), - ])->execute(); - - $this->assertSame( - [ - 'id' => '1', - 'Mybinary1' => '0x62696E61727900000000', - 'Mybinary2' => null, - 'Mybinary3' => 'b', - 'Mybinary4' => null, - ], - $command->setSql( - <<queryOne(), - ); - - $db->createCommand()->dropTable('binary')->execute(); - } - private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); diff --git a/tests/Type/VarCharTest.php b/tests/Type/VarCharTest.php index e8f327176..622c7b0cd 100644 --- a/tests/Type/VarCharTest.php +++ b/tests/Type/VarCharTest.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\Mssql\Tests\Type; +use PHPUnit\Framework\Attributes\DataProviderExternal; use PHPUnit\Framework\TestCase; use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; @@ -12,28 +13,22 @@ use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Provider\Type\VarCharProvider; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; + +use function dirname; /** * @group mssql * - * @psalm-suppress PropertyNotSetInConstructor - * * @link https://learn.microsoft.com/en-us/sql/t-sql/data-types/char-and-varchar-transact-sql?view=sql-server-ver16 */ -final class VarCharTest extends TestCase +final class VarCharTest extends IntegrationTestCase { - use TestTrait; + use IntegrationTestTrait; - /** - * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Type\VarCharProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ + #[DataProviderExternal(VarCharProvider::class, 'columns')] public function testCreateTableWithDefaultValue( string $column, string $dbType, @@ -52,13 +47,6 @@ public function testCreateTableWithDefaultValue( $db->createCommand()->dropTable('varchar_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testCreateTableWithInsert(): void { $db = $this->buildTable(); @@ -80,12 +68,6 @@ public function testCreateTableWithInsert(): void /** * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Type\VarCharProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable */ public function testDefaultValue( string $column, @@ -94,9 +76,9 @@ public function testDefaultValue( int $size, string|Expression $defaultValue, ): void { - $this->setFixture('Type/varchar.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/varchar.sql'); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('varchar_default'); $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); @@ -106,18 +88,11 @@ public function testDefaultValue( $db->createCommand()->dropTable('varchar_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/varchar.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/varchar.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('varchar_default', [])->execute(); @@ -133,18 +108,11 @@ public function testDefaultValueWithInsert(): void $db->createCommand()->dropTable('varchar_default')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testValue(): void { - $this->setFixture('Type/varchar.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/varchar.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'varchar', @@ -174,18 +142,11 @@ public function testValue(): void $db->createCommand()->dropTable('varchar')->execute(); } - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ public function testValueException(): void { - $this->setFixture('Type/varchar.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/varchar.sql'); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -198,7 +159,7 @@ public function testValueException(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand(); From 1710c1e1331f1334ae18e27ef1e2263b5337db13 Mon Sep 17 00:00:00 2001 From: vjik <525501+vjik@users.noreply.github.com> Date: Wed, 19 Nov 2025 12:41:36 +0000 Subject: [PATCH 2/7] Apply PHP CS Fixer and Rector changes (CI) --- tests/PdoConnectionTest.php | 4 ---- tests/QueryBuilderTest.php | 5 ++--- tests/QueryTest.php | 3 --- tests/Type/BinaryTest.php | 6 ------ tests/Type/BitTest.php | 6 ------ tests/Type/DateTest.php | 5 ----- tests/Type/DecimalTest.php | 5 ----- tests/Type/FloatTest.php | 5 ----- tests/Type/GeometryTest.php | 6 ------ tests/Type/ImageTest.php | 6 ------ tests/Type/IntTest.php | 1 - tests/Type/JsonTest.php | 6 ------ tests/Type/MoneyTest.php | 5 ----- tests/Type/NTextTest.php | 6 ------ tests/Type/NumericTest.php | 5 ----- tests/Type/RealTest.php | 5 ----- tests/Type/RowversionTest.php | 6 ------ tests/Type/SmallIntTest.php | 5 ----- tests/Type/SmallMoneyTest.php | 5 ----- tests/Type/TextTest.php | 6 ------ tests/Type/TinyIntTest.php | 5 ----- tests/Type/UniqueidentifierTest.php | 5 ----- tests/Type/VarBinaryTest.php | 7 ------- tests/Type/VarCharTest.php | 5 ----- 24 files changed, 2 insertions(+), 121 deletions(-) diff --git a/tests/PdoConnectionTest.php b/tests/PdoConnectionTest.php index 5f568f190..60f230d03 100644 --- a/tests/PdoConnectionTest.php +++ b/tests/PdoConnectionTest.php @@ -4,10 +4,6 @@ namespace Yiisoft\Db\Mssql\Tests; -use Throwable; -use Yiisoft\Db\Exception\Exception; -use Yiisoft\Db\Exception\InvalidCallException; -use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Common\CommonPdoConnectionTest; diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 410518b61..435a82ee8 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -866,9 +866,8 @@ public function testDelete( string $table, array|string $condition, Closure|string $expectedSql, - array $expectedParams - ): void - { + array $expectedParams, + ): void { parent::testDelete($table, $condition, $expectedSql, $expectedParams); } diff --git a/tests/QueryTest.php b/tests/QueryTest.php index bffda727a..b155ba344 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -5,9 +5,6 @@ namespace Yiisoft\Db\Mssql\Tests; use PHPUnit\Framework\Attributes\DataProvider; -use Throwable; -use Yiisoft\Db\Exception\Exception; -use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Query\Query; diff --git a/tests/Type/BinaryTest.php b/tests/Type/BinaryTest.php index 73c85c135..ea1b07a40 100644 --- a/tests/Type/BinaryTest.php +++ b/tests/Type/BinaryTest.php @@ -4,13 +4,7 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; -use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/BitTest.php b/tests/Type/BitTest.php index fd1418530..1d9c5c219 100644 --- a/tests/Type/BitTest.php +++ b/tests/Type/BitTest.php @@ -4,13 +4,7 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; -use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/DateTest.php b/tests/Type/DateTest.php index 4508f15bd..3936f65d0 100644 --- a/tests/Type/DateTest.php +++ b/tests/Type/DateTest.php @@ -5,13 +5,8 @@ namespace Yiisoft\Db\Mssql\Tests\Type; use DateTimeImmutable; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Mssql\Column\ColumnBuilder; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; diff --git a/tests/Type/DecimalTest.php b/tests/Type/DecimalTest.php index e699a8d75..95aba4ee3 100644 --- a/tests/Type/DecimalTest.php +++ b/tests/Type/DecimalTest.php @@ -4,13 +4,8 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/FloatTest.php b/tests/Type/FloatTest.php index a2fa1ef5b..9f6f4eacc 100644 --- a/tests/Type/FloatTest.php +++ b/tests/Type/FloatTest.php @@ -4,13 +4,8 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/GeometryTest.php b/tests/Type/GeometryTest.php index 0182343ec..7824dee01 100644 --- a/tests/Type/GeometryTest.php +++ b/tests/Type/GeometryTest.php @@ -4,13 +4,7 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; -use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/ImageTest.php b/tests/Type/ImageTest.php index 419c577c0..2834c2f44 100644 --- a/tests/Type/ImageTest.php +++ b/tests/Type/ImageTest.php @@ -4,13 +4,7 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; -use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/IntTest.php b/tests/Type/IntTest.php index befe6a874..5dcdebb43 100644 --- a/tests/Type/IntTest.php +++ b/tests/Type/IntTest.php @@ -4,7 +4,6 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; diff --git a/tests/Type/JsonTest.php b/tests/Type/JsonTest.php index 962dc6dda..5fb4ddcd0 100644 --- a/tests/Type/JsonTest.php +++ b/tests/Type/JsonTest.php @@ -4,13 +4,7 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; -use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/MoneyTest.php b/tests/Type/MoneyTest.php index 0c2c3e597..7970c148b 100644 --- a/tests/Type/MoneyTest.php +++ b/tests/Type/MoneyTest.php @@ -4,13 +4,8 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/NTextTest.php b/tests/Type/NTextTest.php index 3791238d1..1829193c0 100644 --- a/tests/Type/NTextTest.php +++ b/tests/Type/NTextTest.php @@ -4,13 +4,7 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; -use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/NumericTest.php b/tests/Type/NumericTest.php index 2c85fd890..a8fe8dffb 100644 --- a/tests/Type/NumericTest.php +++ b/tests/Type/NumericTest.php @@ -4,13 +4,8 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/RealTest.php b/tests/Type/RealTest.php index 1e2c86eb3..f13fbce5e 100644 --- a/tests/Type/RealTest.php +++ b/tests/Type/RealTest.php @@ -4,13 +4,8 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/RowversionTest.php b/tests/Type/RowversionTest.php index c10fe9300..e4cbff45c 100644 --- a/tests/Type/RowversionTest.php +++ b/tests/Type/RowversionTest.php @@ -4,12 +4,6 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; -use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/SmallIntTest.php b/tests/Type/SmallIntTest.php index e638934cf..179106b47 100644 --- a/tests/Type/SmallIntTest.php +++ b/tests/Type/SmallIntTest.php @@ -4,13 +4,8 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/SmallMoneyTest.php b/tests/Type/SmallMoneyTest.php index 554335d51..b0cad09e2 100644 --- a/tests/Type/SmallMoneyTest.php +++ b/tests/Type/SmallMoneyTest.php @@ -4,13 +4,8 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/TextTest.php b/tests/Type/TextTest.php index 044727adc..e7773b12f 100644 --- a/tests/Type/TextTest.php +++ b/tests/Type/TextTest.php @@ -4,13 +4,7 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; -use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/TinyIntTest.php b/tests/Type/TinyIntTest.php index f5c6b9b9c..336bc85e8 100644 --- a/tests/Type/TinyIntTest.php +++ b/tests/Type/TinyIntTest.php @@ -4,13 +4,8 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/UniqueidentifierTest.php b/tests/Type/UniqueidentifierTest.php index d9a671df0..e8a4c03f9 100644 --- a/tests/Type/UniqueidentifierTest.php +++ b/tests/Type/UniqueidentifierTest.php @@ -4,13 +4,8 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/VarBinaryTest.php b/tests/Type/VarBinaryTest.php index 7bf36b515..321228f9d 100644 --- a/tests/Type/VarBinaryTest.php +++ b/tests/Type/VarBinaryTest.php @@ -4,15 +4,8 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; -use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; - use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; diff --git a/tests/Type/VarCharTest.php b/tests/Type/VarCharTest.php index 622c7b0cd..362be8ae8 100644 --- a/tests/Type/VarCharTest.php +++ b/tests/Type/VarCharTest.php @@ -5,13 +5,8 @@ namespace Yiisoft\Db\Mssql\Tests\Type; use PHPUnit\Framework\Attributes\DataProviderExternal; -use PHPUnit\Framework\TestCase; -use Throwable; use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; -use InvalidArgumentException; -use Yiisoft\Db\Exception\InvalidConfigException; -use Yiisoft\Db\Exception\NotSupportedException; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Mssql\Tests\Provider\Type\VarCharProvider; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; From 005bfef4ba3241c25f2e8d611fb8355bf3fe7eaa Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Wed, 19 Nov 2025 16:26:15 +0300 Subject: [PATCH 3/7] fix --- tests/SchemaTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/SchemaTest.php b/tests/SchemaTest.php index 593344e89..8bbfe468b 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -24,9 +24,9 @@ final class SchemaTest extends CommonSchemaTest use IntegrationTestTrait; #[DataProviderExternal(SchemaProvider::class, 'columns')] - public function testColumns(array $columns, string $tableName): void + public function testColumns(array $columns, string $tableName, ?string $dump = null): void { - parent::testColumns($columns, $tableName); + parent::testColumns($columns, $tableName, $dump); } public function testGetDefaultSchema(): void From 03cb0f33a13983433e265bff92b33a69a12b6683 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 20 Nov 2025 15:16:18 +0300 Subject: [PATCH 4/7] improve --- tests/ColumnTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/ColumnTest.php b/tests/ColumnTest.php index 5e5aa83c8..bcc6f08d7 100644 --- a/tests/ColumnTest.php +++ b/tests/ColumnTest.php @@ -165,4 +165,9 @@ protected function assertTypecastedValues(array $result, bool $allTypecasted = f $this->assertSame('[{"a":1,"b":null,"c":[1,3,5]}]', $result['json_col']); } } + + protected function createTimestampDefaultValue(): mixed + { + return new Expression('getdate()'); + } } From b5da7dcabfadc3f2cae15ce81657d4cc8e79a43b Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 20 Nov 2025 15:28:24 +0300 Subject: [PATCH 5/7] improve --- tests/Provider/QueryBuilderProvider.php | 8 ++------ tests/Support/TestConnection.php | 5 +++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 9de04fc7e..7955b375a 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -892,9 +892,7 @@ public static function multiOperandFunctionBuilder(): array { $data = iterator_to_array(parent::multiOperandFunctionBuilder()); - $serverVersion = TestConnection::getShared()->getServerInfo()->getVersion(); - - if (version_compare($serverVersion, '16', '<')) { + if (version_compare(TestConnection::getServerVersion(), '16', '<')) { $data['Greatest with 2 operands'][2] = '(SELECT MAX(value) FROM (SELECT 1 AS value UNION SELECT (1 + 2) AS value) AS t)'; $data['Greatest with 4 operands'][2] = '(SELECT MAX(value) FROM (SELECT 1 AS value UNION SELECT 1.5 AS value UNION SELECT (1 + 2) AS value UNION SELECT (SELECT 10) AS value) AS t)'; $data['Least with 2 operands'][2] = '(SELECT MIN(value) FROM (SELECT 1 AS value UNION SELECT (1 + 2) AS value) AS t)'; @@ -955,9 +953,7 @@ public static function upsertWithMultiOperandFunctions(): array { $data = parent::upsertWithMultiOperandFunctions(); - $serverVersion = TestConnection::getShared()->getServerInfo()->getVersion(); - - if (version_compare($serverVersion, '16', '<')) { + if (version_compare(TestConnection::getServerVersion(), '16', '<')) { $data[0][3] = 'MERGE [test_upsert_with_functions] WITH (HOLDLOCK)' . ' USING (VALUES (1, :qp0, 5, 5, :qp1, :qp2)) AS EXCLUDED' . ' ([id], [array_col], [greatest_col], [least_col], [longest_col], [shortest_col])' diff --git a/tests/Support/TestConnection.php b/tests/Support/TestConnection.php index 589a24450..2c44b154f 100644 --- a/tests/Support/TestConnection.php +++ b/tests/Support/TestConnection.php @@ -21,6 +21,11 @@ public static function getShared(): Connection return $db; } + public static function getServerVersion(): string + { + return self::getShared()->getServerInfo()->getVersion(); + } + public static function dsn(): string { return self::$dsn ??= (string) new Dsn( From 594c622c49c47ec0ad229c8e82cb67b29d916d4a Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Thu, 20 Nov 2025 15:42:05 +0300 Subject: [PATCH 6/7] improve --- tests/Support/Fixture/FixtureDump.php | 33 ++++++++++++++++++++++++++ tests/Support/IntegrationTestTrait.php | 3 ++- tests/Type/BigIntTest.php | 9 +++---- tests/Type/BinaryTest.php | 9 +++---- tests/Type/BitTest.php | 11 +++++---- tests/Type/CharTest.php | 9 +++---- tests/Type/DateTest.php | 9 +++---- tests/Type/DecimalTest.php | 13 +++++----- tests/Type/FloatTest.php | 13 +++++----- tests/Type/GeometryTest.php | 7 +++--- tests/Type/ImageTest.php | 7 +++--- tests/Type/IntTest.php | 15 ++++++------ tests/Type/JsonTest.php | 11 +++++---- tests/Type/MoneyTest.php | 13 +++++----- tests/Type/NTextTest.php | 7 +++--- tests/Type/NumericTest.php | 11 +++++---- tests/Type/RealTest.php | 13 +++++----- tests/Type/RowversionTest.php | 3 ++- tests/Type/SmallIntTest.php | 13 +++++----- tests/Type/SmallMoneyTest.php | 13 +++++----- tests/Type/TextTest.php | 7 +++--- tests/Type/TinyIntTest.php | 13 +++++----- tests/Type/UniqueidentifierTest.php | 11 +++++---- tests/Type/VarBinaryTest.php | 7 +++--- tests/Type/VarCharTest.php | 9 +++---- 25 files changed, 163 insertions(+), 106 deletions(-) create mode 100644 tests/Support/Fixture/FixtureDump.php diff --git a/tests/Support/Fixture/FixtureDump.php b/tests/Support/Fixture/FixtureDump.php new file mode 100644 index 000000000..8cad19fb8 --- /dev/null +++ b/tests/Support/Fixture/FixtureDump.php @@ -0,0 +1,33 @@ +getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bigint.sql'); + $this->loadFixture(FixtureDump::TYPE_BIGINT); $tableSchema = $db->getTableSchema('bigint_default'); @@ -66,7 +67,7 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bigint.sql'); + $this->loadFixture(FixtureDump::TYPE_BIGINT); $command = $db->createCommand(); $command->insert('bigint_default', [])->execute(); @@ -90,7 +91,7 @@ public function testDefaultValueWithInsert(): void public function testMaxValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bigint.sql'); + $this->loadFixture(FixtureDump::TYPE_BIGINT); $command = $db->createCommand(); $command->insert('bigint', ['Mybigint1' => '9223372036854775807', 'Mybigint2' => '0'])->execute(); @@ -133,7 +134,7 @@ public function testMaxValue(): void public function testMinValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bigint.sql'); + $this->loadFixture(FixtureDump::TYPE_BIGINT); $command = $db->createCommand(); $command->insert('bigint', ['Mybigint1' => '-9223372036854775808', 'Mybigint2' => '0'])->execute(); diff --git a/tests/Type/BinaryTest.php b/tests/Type/BinaryTest.php index ea1b07a40..46aaee169 100644 --- a/tests/Type/BinaryTest.php +++ b/tests/Type/BinaryTest.php @@ -6,6 +6,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Expression\Expression; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -69,7 +70,7 @@ public function testDefaultValue( Expression $defaultValue, ): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/binary.sql'); + $this->loadFixture(FixtureDump::TYPE_BINARY); $tableSchema = $db->getTableSchema('binary_default'); @@ -83,7 +84,7 @@ public function testDefaultValue( public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/binary.sql'); + $this->loadFixture(FixtureDump::TYPE_BINARY); $command = $db->createCommand(); $command->insert('binary_default', [])->execute(); @@ -106,7 +107,7 @@ public function testDefaultValueWithInsert(): void public function testMaxValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/binary.sql'); + $this->loadFixture(FixtureDump::TYPE_BINARY); $command = $db->createCommand(); $command->insert('binary', [ @@ -135,7 +136,7 @@ public function testMaxValue(): void public function testValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/binary.sql'); + $this->loadFixture(FixtureDump::TYPE_BINARY); $command = $db->createCommand(); $command->insert('binary', [ diff --git a/tests/Type/BitTest.php b/tests/Type/BitTest.php index 1d9c5c219..f1cb84255 100644 --- a/tests/Type/BitTest.php +++ b/tests/Type/BitTest.php @@ -5,6 +5,7 @@ namespace Yiisoft\Db\Mssql\Tests\Type; use Yiisoft\Db\Connection\ConnectionInterface; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -65,7 +66,7 @@ public function testDefaultValue( bool $defaultValue, ): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bit.sql'); + $this->loadFixture(FixtureDump::TYPE_BIT); $tableSchema = $db->getTableSchema('bit_default'); @@ -78,7 +79,7 @@ public function testDefaultValue( public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bit.sql'); + $this->loadFixture(FixtureDump::TYPE_BIT); $command = $db->createCommand(); $command->insert('bit_default', [])->execute(); @@ -98,7 +99,7 @@ public function testDefaultValueWithInsert(): void public function testBoolean(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bit.sql'); + $this->loadFixture(FixtureDump::TYPE_BIT); $command = $db->createCommand(); $command->insert('bit', ['Mybit1' => true, 'Mybit2' => false, 'Mybit3' => true])->execute(); @@ -126,7 +127,7 @@ public function testBoolean(): void public function testMaxValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bit.sql'); + $this->loadFixture(FixtureDump::TYPE_BIT); $command = $db->createCommand(); $command->insert('bit', ['Mybit1' => 1, 'Mybit2' => 1, 'Mybit3' => 1])->execute(); @@ -172,7 +173,7 @@ public function testMaxValue(): void public function testMinValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/bit.sql'); + $this->loadFixture(FixtureDump::TYPE_BIT); $command = $db->createCommand(); $command->insert('bit', ['Mybit1' => 0, 'Mybit2' => 0, 'Mybit3' => 0])->execute(); diff --git a/tests/Type/CharTest.php b/tests/Type/CharTest.php index 214fa0f94..9b6cad7d9 100644 --- a/tests/Type/CharTest.php +++ b/tests/Type/CharTest.php @@ -6,6 +6,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -69,7 +70,7 @@ public function testDefaultValue( string $defaultValue, ): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/char.sql'); + $this->loadFixture(FixtureDump::TYPE_CHAR); $tableSchema = $db->getTableSchema('char_default'); @@ -83,7 +84,7 @@ public function testDefaultValue( public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/char.sql'); + $this->loadFixture(FixtureDump::TYPE_CHAR); $command = $db->createCommand(); $command->insert('char_default', [])->execute(); @@ -103,7 +104,7 @@ public function testDefaultValueWithInsert(): void public function testValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/char.sql'); + $this->loadFixture(FixtureDump::TYPE_CHAR); $command = $db->createCommand(); $command->insert( @@ -137,7 +138,7 @@ public function testValue(): void public function testValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/char.sql'); + $this->loadFixture(FixtureDump::TYPE_CHAR); $command = $db->createCommand(); diff --git a/tests/Type/DateTest.php b/tests/Type/DateTest.php index 3936f65d0..422fd2b16 100644 --- a/tests/Type/DateTest.php +++ b/tests/Type/DateTest.php @@ -9,6 +9,7 @@ use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Mssql\Column\ColumnBuilder; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -69,7 +70,7 @@ public function testDefaultValue( DateTimeImmutable $defaultValue, ): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/date.sql'); + $this->loadFixture(FixtureDump::TYPE_DATE); $tableSchema = $db->getTableSchema('date_default'); @@ -82,7 +83,7 @@ public function testDefaultValue( public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/date.sql'); + $this->loadFixture(FixtureDump::TYPE_DATE); $command = $db->createCommand(); $command->insert('date_default', [])->execute(); @@ -102,7 +103,7 @@ public function testDefaultValueWithInsert(): void public function testValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/date.sql'); + $this->loadFixture(FixtureDump::TYPE_DATE); $command = $db->createCommand()->withDbTypecasting(false); $command->insert('date', [ @@ -141,7 +142,7 @@ public function testValue(): void public function testValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/date.sql'); + $this->loadFixture(FixtureDump::TYPE_DATE); $this->expectException(Exception::class); $this->expectExceptionMessage( diff --git a/tests/Type/DecimalTest.php b/tests/Type/DecimalTest.php index 95aba4ee3..dc6b77977 100644 --- a/tests/Type/DecimalTest.php +++ b/tests/Type/DecimalTest.php @@ -7,6 +7,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Expression\Expression; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -54,7 +55,7 @@ public function testCreateTableWithInsert(): void public function testDefaultValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/decimal.sql'); + $this->loadFixture(FixtureDump::TYPE_DECIMAL); $tableSchema = $db->getTableSchema('decimal_default'); @@ -68,7 +69,7 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/decimal.sql'); + $this->loadFixture(FixtureDump::TYPE_DECIMAL); $command = $db->createCommand(); $command->insert('decimal_default', [])->execute(); @@ -91,7 +92,7 @@ public function testDefaultValueWithInsert(): void public function testMaxValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/decimal.sql'); + $this->loadFixture(FixtureDump::TYPE_DECIMAL); $command = $db->createCommand(); $command->insert( @@ -134,7 +135,7 @@ public function testMaxValue(): void public function testMaxValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/decimal.sql'); + $this->loadFixture(FixtureDump::TYPE_DECIMAL); $command = $db->createCommand(); @@ -155,7 +156,7 @@ public function testMaxValueException(): void public function testMinValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/decimal.sql'); + $this->loadFixture(FixtureDump::TYPE_DECIMAL); $command = $db->createCommand(); $command->insert( @@ -198,7 +199,7 @@ public function testMinValue(): void public function testMinValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/decimal.sql'); + $this->loadFixture(FixtureDump::TYPE_DECIMAL); $command = $db->createCommand(); diff --git a/tests/Type/FloatTest.php b/tests/Type/FloatTest.php index 9f6f4eacc..daacd7c6d 100644 --- a/tests/Type/FloatTest.php +++ b/tests/Type/FloatTest.php @@ -7,6 +7,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Expression\Expression; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -53,7 +54,7 @@ public function testCreateTableWithInsert(): void public function testDefaultValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/float.sql'); + $this->loadFixture(FixtureDump::TYPE_FLOAT); $tableSchema = $db->getTableSchema('float_default'); @@ -69,7 +70,7 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/float.sql'); + $this->loadFixture(FixtureDump::TYPE_FLOAT); $command = $db->createCommand(); $command->insert('float_default', [])->execute(); @@ -92,7 +93,7 @@ public function testDefaultValueWithInsert(): void public function testMaxValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/float.sql'); + $this->loadFixture(FixtureDump::TYPE_FLOAT); $command = $db->createCommand(); $command->insert('float', ['Myfloat1' => '1.79E+308', 'Myfloat2' => '0'])->execute(); @@ -131,7 +132,7 @@ public function testMaxValue(): void public function testMaxValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/float.sql'); + $this->loadFixture(FixtureDump::TYPE_FLOAT); $command = $db->createCommand(); @@ -149,7 +150,7 @@ public function testMaxValueException(): void public function testMinValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/float.sql'); + $this->loadFixture(FixtureDump::TYPE_FLOAT); $command = $db->createCommand(); $command->insert('float', ['Myfloat1' => '-1.79E+308', 'Myfloat2' => '0'])->execute(); @@ -188,7 +189,7 @@ public function testMinValue(): void public function testMinValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/float.sql'); + $this->loadFixture(FixtureDump::TYPE_FLOAT); $command = $db->createCommand(); diff --git a/tests/Type/GeometryTest.php b/tests/Type/GeometryTest.php index 7824dee01..f41ad5970 100644 --- a/tests/Type/GeometryTest.php +++ b/tests/Type/GeometryTest.php @@ -6,6 +6,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Expression\Expression; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -66,7 +67,7 @@ public function testDefaultValue( ?Expression $defaultValue, ): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/geometry.sql'); + $this->loadFixture(FixtureDump::TYPE_GEOMETRY); $tableSchema = $db->getTableSchema('geometry_default'); @@ -79,7 +80,7 @@ public function testDefaultValue( public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/geometry.sql'); + $this->loadFixture(FixtureDump::TYPE_GEOMETRY); $command = $db->createCommand(); $command->insert('geometry_default', [])->execute(); @@ -99,7 +100,7 @@ public function testDefaultValueWithInsert(): void public function testValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/geometry.sql'); + $this->loadFixture(FixtureDump::TYPE_GEOMETRY); $command = $db->createCommand(); $command->insert( diff --git a/tests/Type/ImageTest.php b/tests/Type/ImageTest.php index 2834c2f44..c6ae0d7c2 100644 --- a/tests/Type/ImageTest.php +++ b/tests/Type/ImageTest.php @@ -6,6 +6,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Expression\Expression; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -52,7 +53,7 @@ public function testCreateTableWithInsert(): void public function testDefaultValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/image.sql'); + $this->loadFixture(FixtureDump::TYPE_IMAGE); $tableSchema = $db->getTableSchema('image_default'); @@ -65,7 +66,7 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/image.sql'); + $this->loadFixture(FixtureDump::TYPE_IMAGE); $command = $db->createCommand(); $command->insert('image_default', [])->execute(); @@ -85,7 +86,7 @@ public function testDefaultValueWithInsert(): void public function testValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/image.sql'); + $this->loadFixture(FixtureDump::TYPE_IMAGE); $command = $db->createCommand(); $command->insert( diff --git a/tests/Type/IntTest.php b/tests/Type/IntTest.php index 5dcdebb43..2d1b41a7c 100644 --- a/tests/Type/IntTest.php +++ b/tests/Type/IntTest.php @@ -6,6 +6,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -54,7 +55,7 @@ public function testCreateTableWithInsert(): void public function testDefaultValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/int.sql'); + $this->loadFixture(FixtureDump::TYPE_INT); $tableSchema = $db->getTableSchema('int_default'); @@ -67,7 +68,7 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/int.sql'); + $this->loadFixture(FixtureDump::TYPE_INT); $command = $db->createCommand(); $command->insert('int_default', [])->execute(); @@ -90,7 +91,7 @@ public function testDefaultValueWithInsert(): void public function testMaxValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/int.sql'); + $this->loadFixture(FixtureDump::TYPE_INT); $command = $db->createCommand(); $command->insert('int', ['Myint1' => 2_147_483_647, 'Myint2' => 0])->execute(); @@ -129,7 +130,7 @@ public function testMaxValue(): void public function testMaxValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/int.sql'); + $this->loadFixture(FixtureDump::TYPE_INT); $command = $db->createCommand(); @@ -147,7 +148,7 @@ public function testMaxValueException(): void public function testMinValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/int.sql'); + $this->loadFixture(FixtureDump::TYPE_INT); $command = $db->createCommand(); $command->insert('int', ['Myint1' => -2_147_483_648, 'Myint2' => 0])->execute(); @@ -186,7 +187,7 @@ public function testMinValue(): void public function testMinValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/int.sql'); + $this->loadFixture(FixtureDump::TYPE_INT); $command = $db->createCommand(); @@ -201,7 +202,7 @@ public function testMinValueException(): void public function testIdentityTypecasting(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/int.sql'); + $this->loadFixture(FixtureDump::TYPE_INT); $db->createCommand()->insert('int', ['Myint1' => 1])->execute(); diff --git a/tests/Type/JsonTest.php b/tests/Type/JsonTest.php index 5fb4ddcd0..8fa3ce530 100644 --- a/tests/Type/JsonTest.php +++ b/tests/Type/JsonTest.php @@ -5,6 +5,7 @@ namespace Yiisoft\Db\Mssql\Tests\Type; use Yiisoft\Db\Connection\ConnectionInterface; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -51,7 +52,7 @@ public function testCreateTableWithInsert(): void public function testDefaultValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/json.sql'); + $this->loadFixture(FixtureDump::TYPE_JSON); $tableSchema = $db->getTableSchema('json_default'); @@ -64,7 +65,7 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/json.sql'); + $this->loadFixture(FixtureDump::TYPE_JSON); $command = $db->createCommand(); $command->insert('json_default', [])->execute(); @@ -84,7 +85,7 @@ public function testDefaultValueWithInsert(): void public function testInvalidValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/json.sql'); + $this->loadFixture(FixtureDump::TYPE_JSON); $command = $db->createCommand(); $command->insert('json', ['Myjson' => 'invalid'])->execute(); @@ -102,7 +103,7 @@ public function testInvalidValue(): void public function testValidValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/json.sql'); + $this->loadFixture(FixtureDump::TYPE_JSON); $command = $db->createCommand(); $command->insert('json', ['Myjson' => '{"a":1,"b":2,"c":3,"d":4,"e":5}'])->execute(); @@ -120,7 +121,7 @@ public function testValidValue(): void public function testValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/json.sql'); + $this->loadFixture(FixtureDump::TYPE_JSON); $command = $db->createCommand(); $command->insert('json', ['Myjson' => '{"a":1,"b":2,"c":3,"d":4,"e":5}'])->execute(); diff --git a/tests/Type/MoneyTest.php b/tests/Type/MoneyTest.php index 7970c148b..2b4e6e946 100644 --- a/tests/Type/MoneyTest.php +++ b/tests/Type/MoneyTest.php @@ -6,6 +6,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -52,7 +53,7 @@ public function testCreateTableWithInsert(): void public function testDefaultValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/money.sql'); + $this->loadFixture(FixtureDump::TYPE_MONEY); $tableSchema = $db->getTableSchema('money_default'); @@ -65,7 +66,7 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/money.sql'); + $this->loadFixture(FixtureDump::TYPE_MONEY); $command = $db->createCommand(); $command->insert('money_default', [])->execute(); @@ -88,7 +89,7 @@ public function testDefaultValueWithInsert(): void public function testMaxValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/money.sql'); + $this->loadFixture(FixtureDump::TYPE_MONEY); $command = $db->createCommand(); $command->insert('money', ['Mymoney1' => '922337203685477.5807', 'Mymoney2' => '0'])->execute(); @@ -127,7 +128,7 @@ public function testMaxValue(): void public function testMaxValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/money.sql'); + $this->loadFixture(FixtureDump::TYPE_MONEY); $command = $db->createCommand(); @@ -145,7 +146,7 @@ public function testMaxValueException(): void public function testMinValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/money.sql'); + $this->loadFixture(FixtureDump::TYPE_MONEY); $command = $db->createCommand(); $command->insert('money', ['Mymoney1' => '-922337203685477.5808', 'Mymoney2' => 0])->execute(); @@ -184,7 +185,7 @@ public function testMinValue(): void public function testMinValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/money.sql'); + $this->loadFixture(FixtureDump::TYPE_MONEY); $command = $db->createCommand(); diff --git a/tests/Type/NTextTest.php b/tests/Type/NTextTest.php index 1829193c0..a5c07c905 100644 --- a/tests/Type/NTextTest.php +++ b/tests/Type/NTextTest.php @@ -5,6 +5,7 @@ namespace Yiisoft\Db\Mssql\Tests\Type; use Yiisoft\Db\Connection\ConnectionInterface; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -53,7 +54,7 @@ public function testCreateTableWithInsert(): void public function testDefaultValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/ntext.sql'); + $this->loadFixture(FixtureDump::TYPE_NTEXT); $tableSchema = $db->getTableSchema('ntext_default'); @@ -66,7 +67,7 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/ntext.sql'); + $this->loadFixture(FixtureDump::TYPE_NTEXT); $command = $db->createCommand(); $command->insert('ntext_default', [])->execute(); @@ -86,7 +87,7 @@ public function testDefaultValueWithInsert(): void public function testValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/ntext.sql'); + $this->loadFixture(FixtureDump::TYPE_NTEXT); $command = $db->createCommand(); $command->insert('ntext', ['Myntext1' => '0123456789', 'Myntext2' => null])->execute(); diff --git a/tests/Type/NumericTest.php b/tests/Type/NumericTest.php index a8fe8dffb..2d1152aff 100644 --- a/tests/Type/NumericTest.php +++ b/tests/Type/NumericTest.php @@ -7,6 +7,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Expression\Expression; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -54,7 +55,7 @@ public function testCreateTableWithInsert(): void public function testDefaultValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/numeric.sql'); + $this->loadFixture(FixtureDump::TYPE_NUMERIC); $tableSchema = $db->getTableSchema('numeric_default'); @@ -68,7 +69,7 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/numeric.sql'); + $this->loadFixture(FixtureDump::TYPE_NUMERIC); $command = $db->createCommand(); $command->insert('numeric_default', [])->execute(); @@ -91,7 +92,7 @@ public function testDefaultValueWithInsert(): void public function testMaxValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/numeric.sql'); + $this->loadFixture(FixtureDump::TYPE_NUMERIC); $command = $db->createCommand(); $command->insert( @@ -139,7 +140,7 @@ public function testMaxValue(): void public function testMinValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/numeric.sql'); + $this->loadFixture(FixtureDump::TYPE_NUMERIC); $command = $db->createCommand(); $command->insert( @@ -184,7 +185,7 @@ public function testMinValue(): void public function testMinValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/numeric.sql'); + $this->loadFixture(FixtureDump::TYPE_NUMERIC); $command = $db->createCommand(); diff --git a/tests/Type/RealTest.php b/tests/Type/RealTest.php index f13fbce5e..69b0a07a0 100644 --- a/tests/Type/RealTest.php +++ b/tests/Type/RealTest.php @@ -7,6 +7,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Expression\Expression; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -53,7 +54,7 @@ public function testCreateTableWithInsert(): void public function testDefaultValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/real.sql'); + $this->loadFixture(FixtureDump::TYPE_REAL); $tableSchema = $db->getTableSchema('real_default'); @@ -66,7 +67,7 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/real.sql'); + $this->loadFixture(FixtureDump::TYPE_REAL); $command = $db->createCommand(); $command->insert('real_default', [])->execute(); @@ -89,7 +90,7 @@ public function testDefaultValueWithInsert(): void public function testMaxValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/real.sql'); + $this->loadFixture(FixtureDump::TYPE_REAL); $command = $db->createCommand(); $command->insert('real', ['Myreal1' => '3.4E+38', 'Myreal2' => '0'])->execute(); @@ -128,7 +129,7 @@ public function testMaxValue(): void public function testMaxValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/real.sql'); + $this->loadFixture(FixtureDump::TYPE_REAL); $command = $db->createCommand(); @@ -146,7 +147,7 @@ public function testMaxValueException(): void public function testMinValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/real.sql'); + $this->loadFixture(FixtureDump::TYPE_REAL); $command = $db->createCommand(); $command->insert('real', ['Myreal1' => '-3.4E+38', 'Myreal2' => '0'])->execute(); @@ -185,7 +186,7 @@ public function testMinValue(): void public function testMinValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/real.sql'); + $this->loadFixture(FixtureDump::TYPE_REAL); $command = $db->createCommand(); diff --git a/tests/Type/RowversionTest.php b/tests/Type/RowversionTest.php index e4cbff45c..c8b22c03f 100644 --- a/tests/Type/RowversionTest.php +++ b/tests/Type/RowversionTest.php @@ -4,6 +4,7 @@ namespace Yiisoft\Db\Mssql\Tests\Type; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -19,7 +20,7 @@ final class RowversionTest extends IntegrationTestCase public function testValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/rowversion.sql'); + $this->loadFixture(FixtureDump::TYPE_ROWVERSION); $tableSchema = $db->getTableSchema('rowversion'); diff --git a/tests/Type/SmallIntTest.php b/tests/Type/SmallIntTest.php index 179106b47..63ebf5af7 100644 --- a/tests/Type/SmallIntTest.php +++ b/tests/Type/SmallIntTest.php @@ -6,6 +6,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -52,7 +53,7 @@ public function testCreateTableWithInsert(): void public function testDefaultValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallint.sql'); + $this->loadFixture(FixtureDump::TYPE_SMALLINT); $tableSchema = $db->getTableSchema('smallint_default'); @@ -65,7 +66,7 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallint.sql'); + $this->loadFixture(FixtureDump::TYPE_SMALLINT); $command = $db->createCommand(); $command->insert('smallint_default', [])->execute(); @@ -88,7 +89,7 @@ public function testDefaultValueWithInsert(): void public function testMaxValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallint.sql'); + $this->loadFixture(FixtureDump::TYPE_SMALLINT); $command = $db->createCommand(); $command->insert('smallint', ['Mysmallint1' => 32767, 'Mysmallint2' => 0])->execute(); @@ -127,7 +128,7 @@ public function testMaxValue(): void public function testMaxValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallint.sql'); + $this->loadFixture(FixtureDump::TYPE_SMALLINT); $command = $db->createCommand(); @@ -145,7 +146,7 @@ public function testMaxValueException(): void public function testMinValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallint.sql'); + $this->loadFixture(FixtureDump::TYPE_SMALLINT); $command = $db->createCommand(); $command->insert('smallint', ['Mysmallint1' => -32768, 'Mysmallint2' => 0])->execute(); @@ -184,7 +185,7 @@ public function testMinValue(): void public function testMinValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallint.sql'); + $this->loadFixture(FixtureDump::TYPE_SMALLINT); $command = $db->createCommand(); diff --git a/tests/Type/SmallMoneyTest.php b/tests/Type/SmallMoneyTest.php index b0cad09e2..35c30dd65 100644 --- a/tests/Type/SmallMoneyTest.php +++ b/tests/Type/SmallMoneyTest.php @@ -6,6 +6,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -52,7 +53,7 @@ public function testCreateTableWithInsert(): void public function testDefaultValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallmoney.sql'); + $this->loadFixture(FixtureDump::TYPE_SMALLMONEY); $tableSchema = $db->getTableSchema('smallmoney_default'); @@ -65,7 +66,7 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallmoney.sql'); + $this->loadFixture(FixtureDump::TYPE_SMALLMONEY); $command = $db->createCommand(); $command->insert('smallmoney_default', [])->execute(); @@ -88,7 +89,7 @@ public function testDefaultValueWithInsert(): void public function testMaxValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallmoney.sql'); + $this->loadFixture(FixtureDump::TYPE_SMALLMONEY); $command = $db->createCommand(); $command->insert('smallmoney', ['Mysmallmoney1' => '214748.3647', 'Mysmallmoney2' => '0'])->execute(); @@ -127,7 +128,7 @@ public function testMaxValue(): void public function testMaxValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallmoney.sql'); + $this->loadFixture(FixtureDump::TYPE_SMALLMONEY); $command = $db->createCommand(); @@ -145,7 +146,7 @@ public function testMaxValueException(): void public function testMinValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallmoney.sql'); + $this->loadFixture(FixtureDump::TYPE_SMALLMONEY); $command = $db->createCommand(); $command->insert('smallmoney', ['Mysmallmoney1' => '-214748.3648', 'Mysmallmoney2' => 0])->execute(); @@ -184,7 +185,7 @@ public function testMinValue(): void public function testMinValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/smallmoney.sql'); + $this->loadFixture(FixtureDump::TYPE_SMALLMONEY); $command = $db->createCommand(); diff --git a/tests/Type/TextTest.php b/tests/Type/TextTest.php index e7773b12f..d31e6f96f 100644 --- a/tests/Type/TextTest.php +++ b/tests/Type/TextTest.php @@ -5,6 +5,7 @@ namespace Yiisoft\Db\Mssql\Tests\Type; use Yiisoft\Db\Connection\ConnectionInterface; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -53,7 +54,7 @@ public function testCreateTableWithInsert(): void public function testDefaultValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/text.sql'); + $this->loadFixture(FixtureDump::TYPE_TEXT); $tableSchema = $db->getTableSchema('text_default'); @@ -66,7 +67,7 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/text.sql'); + $this->loadFixture(FixtureDump::TYPE_TEXT); $command = $db->createCommand(); $command->insert('text_default', [])->execute(); @@ -86,7 +87,7 @@ public function testDefaultValueWithInsert(): void public function testValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/text.sql'); + $this->loadFixture(FixtureDump::TYPE_TEXT); $command = $db->createCommand(); $command->insert('text', ['Mytext1' => '0123456789', 'Mytext2' => null])->execute(); diff --git a/tests/Type/TinyIntTest.php b/tests/Type/TinyIntTest.php index 336bc85e8..d5fdd3c67 100644 --- a/tests/Type/TinyIntTest.php +++ b/tests/Type/TinyIntTest.php @@ -6,6 +6,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -54,7 +55,7 @@ public function testCreateTableWithInsert(): void public function testDefaultValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/tinyint.sql'); + $this->loadFixture(FixtureDump::TYPE_TINYINT); $tableSchema = $db->getTableSchema('tinyint_default'); @@ -67,7 +68,7 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/tinyint.sql'); + $this->loadFixture(FixtureDump::TYPE_TINYINT); $command = $db->createCommand(); $command->insert('tinyint_default', [])->execute(); @@ -90,7 +91,7 @@ public function testDefaultValueWithInsert(): void public function testMaxValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/tinyint.sql'); + $this->loadFixture(FixtureDump::TYPE_TINYINT); $command = $db->createCommand(); $command->insert('tinyint', ['Mytinyint1' => 255, 'Mytinyint2' => 0])->execute(); @@ -144,7 +145,7 @@ public function testMaxValue(): void public function testMaxValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/tinyint.sql'); + $this->loadFixture(FixtureDump::TYPE_TINYINT); $command = $db->createCommand(); @@ -162,7 +163,7 @@ public function testMaxValueException(): void public function testMinValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/tinyint.sql'); + $this->loadFixture(FixtureDump::TYPE_TINYINT); $command = $db->createCommand(); $command->insert('tinyint', ['Mytinyint1' => 0, 'Mytinyint2' => null])->execute(); @@ -201,7 +202,7 @@ public function testMinValue(): void public function testMinValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/tinyint.sql'); + $this->loadFixture(FixtureDump::TYPE_TINYINT); $command = $db->createCommand(); diff --git a/tests/Type/UniqueidentifierTest.php b/tests/Type/UniqueidentifierTest.php index e8a4c03f9..636f0df24 100644 --- a/tests/Type/UniqueidentifierTest.php +++ b/tests/Type/UniqueidentifierTest.php @@ -6,6 +6,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Exception\Exception; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -55,7 +56,7 @@ public function testCreateTableWithInsert(): void public function testDefaultValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/uniqueidentifier.sql'); + $this->loadFixture(FixtureDump::TYPE_UNIQUEIDENTIFIER); $tableSchema = $db->getTableSchema('uniqueidentifier_default'); @@ -71,7 +72,7 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/uniqueidentifier.sql'); + $this->loadFixture(FixtureDump::TYPE_UNIQUEIDENTIFIER); $command = $db->createCommand(); $command->insert('uniqueidentifier_default', [])->execute(); @@ -94,7 +95,7 @@ public function testDefaultValueWithInsert(): void public function testValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/uniqueidentifier.sql'); + $this->loadFixture(FixtureDump::TYPE_UNIQUEIDENTIFIER); $command = $db->createCommand(); $command->insert( @@ -121,7 +122,7 @@ public function testValue(): void public function testValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/uniqueidentifier.sql'); + $this->loadFixture(FixtureDump::TYPE_UNIQUEIDENTIFIER); $this->expectException(Exception::class); $this->expectExceptionMessage( @@ -138,7 +139,7 @@ public function testValueException(): void public function testValueLength(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/uniqueidentifier.sql'); + $this->loadFixture(FixtureDump::TYPE_UNIQUEIDENTIFIER); $command = $db->createCommand(); $command->insert( diff --git a/tests/Type/VarBinaryTest.php b/tests/Type/VarBinaryTest.php index 321228f9d..d3a3bb474 100644 --- a/tests/Type/VarBinaryTest.php +++ b/tests/Type/VarBinaryTest.php @@ -6,6 +6,7 @@ use Yiisoft\Db\Connection\ConnectionInterface; use Yiisoft\Db\Expression\Expression; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -71,7 +72,7 @@ public function testDefaultValue( Expression $defaultValue, ): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/varbinary.sql'); + $this->loadFixture(FixtureDump::TYPE_VARBINARY); $tableSchema = $db->getTableSchema('varbinary_default'); @@ -85,7 +86,7 @@ public function testDefaultValue( public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/varbinary.sql'); + $this->loadFixture(FixtureDump::TYPE_VARBINARY); $command = $db->createCommand(); $command->insert('varbinary_default', [])->execute(); @@ -108,7 +109,7 @@ public function testDefaultValueWithInsert(): void public function testMaxValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/varbinary.sql'); + $this->loadFixture(FixtureDump::TYPE_VARBINARY); $command = $db->createCommand(); $command->insert('varbinary', [ diff --git a/tests/Type/VarCharTest.php b/tests/Type/VarCharTest.php index 362be8ae8..ec8234f6b 100644 --- a/tests/Type/VarCharTest.php +++ b/tests/Type/VarCharTest.php @@ -9,6 +9,7 @@ use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Mssql\Tests\Provider\Type\VarCharProvider; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; @@ -72,7 +73,7 @@ public function testDefaultValue( string|Expression $defaultValue, ): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/varchar.sql'); + $this->loadFixture(FixtureDump::TYPE_VARCHAR); $tableSchema = $db->getTableSchema('varchar_default'); @@ -86,7 +87,7 @@ public function testDefaultValue( public function testDefaultValueWithInsert(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/varchar.sql'); + $this->loadFixture(FixtureDump::TYPE_VARCHAR); $command = $db->createCommand(); $command->insert('varchar_default', [])->execute(); @@ -106,7 +107,7 @@ public function testDefaultValueWithInsert(): void public function testValue(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/varchar.sql'); + $this->loadFixture(FixtureDump::TYPE_VARCHAR); $command = $db->createCommand(); $command->insert( @@ -140,7 +141,7 @@ public function testValue(): void public function testValueException(): void { $db = $this->getSharedConnection(); - $this->loadFixture(dirname(__DIR__) . '/Support/Fixture/Type/varchar.sql'); + $this->loadFixture(FixtureDump::TYPE_VARCHAR); $command = $db->createCommand(); From 9a8a611431e1b76693d425c812bb21a81878e180 Mon Sep 17 00:00:00 2001 From: vjik <525501+vjik@users.noreply.github.com> Date: Thu, 20 Nov 2025 12:42:44 +0000 Subject: [PATCH 7/7] Apply PHP CS Fixer and Rector changes (CI) --- tests/Type/BigIntTest.php | 2 -- tests/Type/IntTest.php | 2 -- tests/Type/TextTest.php | 2 -- tests/Type/TinyIntTest.php | 2 -- tests/Type/VarCharTest.php | 2 -- 5 files changed, 10 deletions(-) diff --git a/tests/Type/BigIntTest.php b/tests/Type/BigIntTest.php index 28c0024af..b74779a5d 100644 --- a/tests/Type/BigIntTest.php +++ b/tests/Type/BigIntTest.php @@ -9,8 +9,6 @@ use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; -use function dirname; - /** * @group mssql * diff --git a/tests/Type/IntTest.php b/tests/Type/IntTest.php index 2d1b41a7c..3f0a1b17e 100644 --- a/tests/Type/IntTest.php +++ b/tests/Type/IntTest.php @@ -10,8 +10,6 @@ use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; -use function dirname; - /** * @group mssql * diff --git a/tests/Type/TextTest.php b/tests/Type/TextTest.php index d31e6f96f..3e9205d12 100644 --- a/tests/Type/TextTest.php +++ b/tests/Type/TextTest.php @@ -9,8 +9,6 @@ use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; -use function dirname; - /** * @group mssql * diff --git a/tests/Type/TinyIntTest.php b/tests/Type/TinyIntTest.php index d5fdd3c67..2b5aa2bb7 100644 --- a/tests/Type/TinyIntTest.php +++ b/tests/Type/TinyIntTest.php @@ -10,8 +10,6 @@ use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; -use function dirname; - /** * @group mssql * diff --git a/tests/Type/VarCharTest.php b/tests/Type/VarCharTest.php index ec8234f6b..5e2698007 100644 --- a/tests/Type/VarCharTest.php +++ b/tests/Type/VarCharTest.php @@ -13,8 +13,6 @@ use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Support\IntegrationTestCase; -use function dirname; - /** * @group mssql *