diff --git a/composer.json b/composer.json index a731c755..2f5544ec 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 38ed4001..b1c76578 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 85ba62dd..02fcf419 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 552ec33f..2930f3cf 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 da7e8f8b..bcc6f08d 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'); @@ -163,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()'); + } } diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 51302715..750a588d 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 17cc196d..2b1684a1 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 166619ef..004182db 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 6802e9ae..60f230d0 100644 --- a/tests/PdoConnectionTest.php +++ b/tests/PdoConnectionTest.php @@ -4,32 +4,20 @@ 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\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 e0519285..4ae61bca 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 ddb634cb..7955b375 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,13 +890,9 @@ public static function multiOperandFunctionClasses(): array public static function multiOperandFunctionBuilder(): array { - $data = parent::multiOperandFunctionBuilder(); - - $db = self::getDb(); - $serverVersion = $db->getServerInfo()->getVersion(); - $db->close(); + $data = iterator_to_array(parent::multiOperandFunctionBuilder()); - 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)'; @@ -936,7 +929,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(); - - 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/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 7d1cae2b..435a82ee 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,18 @@ public function testCaseXBuilder( } #[DataProviderExternal(QueryBuilderProvider::class, 'delete')] - public function testDelete(string $table, array|string $condition, string $expectedSQL, array $expectedParams): void - { - parent::testDelete($table, $condition, $expectedSQL, $expectedParams); + public function testDelete( + string $table, + array|string $condition, + Closure|string $expectedSql, + array $expectedParams, + ): void { + 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 +883,7 @@ public function testLengthBuilder( public function testLengthBuilderWithColumnName(): void { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $qb = $db->getQueryBuilder(); $length = new Length('column_name'); @@ -882,7 +896,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 +924,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 +932,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 d78e988a..b2690415 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 773a8499..b155ba34 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -5,22 +5,17 @@ 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\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 +24,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 +39,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 +56,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 7e6c5851..d7578930 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 a8f37a75..8bbfe468 100644 --- a/tests/SchemaTest.php +++ b/tests/SchemaTest.php @@ -11,27 +11,27 @@ 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 + public function testColumns(array $columns, string $tableName, ?string $dump = null): void { - parent::testColumns($columns, $tableName); + parent::testColumns($columns, $tableName, $dump); } 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 593506f7..8b0189e2 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/Fixture/FixtureDump.php b/tests/Support/Fixture/FixtureDump.php new file mode 100644 index 00000000..8cad19fb --- /dev/null +++ b/tests/Support/Fixture/FixtureDump.php @@ -0,0 +1,33 @@ +getSchema()->refresh(); + return $db; + } + + public static function getServerVersion(): string + { + return self::getShared()->getServerInfo()->getVersion(); + } + + 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 6997b799..00000000 --- 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 d8a44330..282b7b3c 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 276c19e1..b74779a5 100644 --- a/tests/Type/BigIntTest.php +++ b/tests/Type/BigIntTest.php @@ -4,33 +4,20 @@ 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\Fixture\FixtureDump; +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 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 +30,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 +49,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(FixtureDump::TYPE_BIGINT); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('bigint_default'); $this->assertSame('bigint', $tableSchema?->getColumn('Mybigint')->getDbType()); @@ -89,18 +62,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(FixtureDump::TYPE_BIGINT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('bigint_default', [])->execute(); @@ -119,18 +85,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(FixtureDump::TYPE_BIGINT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('bigint', ['Mybigint1' => '9223372036854775807', 'Mybigint2' => '0'])->execute(); @@ -168,18 +128,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(FixtureDump::TYPE_BIGINT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('bigint', ['Mybigint1' => '-9223372036854775808', 'Mybigint2' => '0'])->execute(); @@ -216,7 +170,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 f26e85ce..46aaee16 100644 --- a/tests/Type/BinaryTest.php +++ b/tests/Type/BinaryTest.php @@ -4,35 +4,23 @@ 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\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; +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 +40,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 +61,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 +69,9 @@ public function testDefaultValue( int $size, Expression $defaultValue, ): void { - $this->setFixture('Type/binary.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(FixtureDump::TYPE_BINARY); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('binary_default'); $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); @@ -106,18 +81,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(FixtureDump::TYPE_BINARY); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('binary_default', [])->execute(); @@ -135,18 +103,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(FixtureDump::TYPE_BINARY); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('binary', [ 'Mybinary1' => new Expression('CONVERT(binary(10), \'binary_default_value\')'), @@ -171,18 +133,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(FixtureDump::TYPE_BINARY); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('binary', [ 'Mybinary1' => new Expression('CONVERT(binary(10), \'binary\')'), @@ -211,7 +166,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 078af730..f1cb8425 100644 --- a/tests/Type/BitTest.php +++ b/tests/Type/BitTest.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\Fixture\FixtureDump; +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 +37,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 +58,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 +65,9 @@ public function testDefaultValue( string $phpType, bool $defaultValue, ): void { - $this->setFixture('Type/bit.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(FixtureDump::TYPE_BIT); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('bit_default'); $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); @@ -101,18 +76,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(FixtureDump::TYPE_BIT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('bit_default', [])->execute(); @@ -128,18 +96,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(FixtureDump::TYPE_BIT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('bit', ['Mybit1' => true, 'Mybit2' => false, 'Mybit3' => true])->execute(); @@ -162,18 +123,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(FixtureDump::TYPE_BIT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('bit', ['Mybit1' => 1, 'Mybit2' => 1, 'Mybit3' => 1])->execute(); @@ -213,19 +168,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(FixtureDump::TYPE_BIT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('bit', ['Mybit1' => 0, 'Mybit2' => 0, 'Mybit3' => 0])->execute(); @@ -264,7 +213,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 c71d9518..9b6cad7d 100644 --- a/tests/Type/CharTest.php +++ b/tests/Type/CharTest.php @@ -4,34 +4,23 @@ 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\Fixture\FixtureDump; +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 +40,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 +61,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 +69,9 @@ public function testDefaultValue( int $size, string $defaultValue, ): void { - $this->setFixture('Type/char.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(FixtureDump::TYPE_CHAR); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('char_default'); $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); @@ -105,18 +81,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(FixtureDump::TYPE_CHAR); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('char_default', [])->execute(); @@ -132,18 +101,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(FixtureDump::TYPE_CHAR); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'char', @@ -173,18 +135,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(FixtureDump::TYPE_CHAR); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -197,7 +152,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 011149ed..422fd2b1 100644 --- a/tests/Type/DateTest.php +++ b/tests/Type/DateTest.php @@ -5,36 +5,25 @@ 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\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; +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 +41,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 +62,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 +69,9 @@ public function testDefaultValue( string $phpType, DateTimeImmutable $defaultValue, ): void { - $this->setFixture('Type/date.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(FixtureDump::TYPE_DATE); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('date_default'); $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); @@ -104,18 +80,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(FixtureDump::TYPE_DATE); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('date_default', [])->execute(); @@ -131,18 +100,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(FixtureDump::TYPE_DATE); - $db = $this->getConnection(true); $command = $db->createCommand()->withDbTypecasting(false); $command->insert('date', [ 'Mydate1' => '2007-05-08', @@ -177,18 +139,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(FixtureDump::TYPE_DATE); $this->expectException(Exception::class); $this->expectExceptionMessage( @@ -200,7 +154,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 7cf8b446..dc6b7797 100644 --- a/tests/Type/DecimalTest.php +++ b/tests/Type/DecimalTest.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\Expression\Expression; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; +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 +33,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 +52,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(FixtureDump::TYPE_DECIMAL); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('decimal_default'); $this->assertSame('decimal', $tableSchema?->getColumn('Mydecimal')->getDbType()); @@ -92,18 +66,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(FixtureDump::TYPE_DECIMAL); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('decimal_default', [])->execute(); @@ -121,18 +88,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(FixtureDump::TYPE_DECIMAL); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'decimal', @@ -171,18 +132,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(FixtureDump::TYPE_DECIMAL); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -198,18 +152,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(FixtureDump::TYPE_DECIMAL); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'decimal', @@ -248,18 +196,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(FixtureDump::TYPE_DECIMAL); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -275,7 +216,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 045c42e3..daacd7c6 100644 --- a/tests/Type/FloatTest.php +++ b/tests/Type/FloatTest.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\Expression\Expression; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; +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 +32,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 +51,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(FixtureDump::TYPE_FLOAT); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('float_default'); $this->assertSame('float', $tableSchema?->getColumn('Myfloat')->getDbType()); @@ -93,18 +67,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(FixtureDump::TYPE_FLOAT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('float_default', [])->execute(); @@ -122,18 +89,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(FixtureDump::TYPE_FLOAT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('float', ['Myfloat1' => '1.79E+308', 'Myfloat2' => '0'])->execute(); @@ -168,18 +129,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(FixtureDump::TYPE_FLOAT); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -192,18 +146,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(FixtureDump::TYPE_FLOAT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('float', ['Myfloat1' => '-1.79E+308', 'Myfloat2' => '0'])->execute(); @@ -238,18 +186,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(FixtureDump::TYPE_FLOAT); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -262,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/GeometryTest.php b/tests/Type/GeometryTest.php index 9ff6f401..f41ad597 100644 --- a/tests/Type/GeometryTest.php +++ b/tests/Type/GeometryTest.php @@ -4,35 +4,23 @@ 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\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; +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 +38,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 +59,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 +66,9 @@ public function testDefaultValue( string $phpType, ?Expression $defaultValue, ): void { - $this->setFixture('Type/geometry.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(FixtureDump::TYPE_GEOMETRY); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('geometry_default'); $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); @@ -102,18 +77,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(FixtureDump::TYPE_GEOMETRY); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('geometry_default', [])->execute(); @@ -129,18 +97,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(FixtureDump::TYPE_GEOMETRY); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'geometry', @@ -167,7 +128,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 0c8c1484..c6ae0d7c 100644 --- a/tests/Type/ImageTest.php +++ b/tests/Type/ImageTest.php @@ -4,34 +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\Expression\Expression; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; +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 +31,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 +50,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(FixtureDump::TYPE_IMAGE); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('image_default'); $this->assertSame('image', $tableSchema?->getColumn('Myimage')->getDbType()); @@ -90,18 +63,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(FixtureDump::TYPE_IMAGE); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('image_default', [])->execute(); @@ -117,18 +83,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(FixtureDump::TYPE_IMAGE); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'image', @@ -153,7 +112,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 80485320..3f0a1b17 100644 --- a/tests/Type/IntTest.php +++ b/tests/Type/IntTest.php @@ -4,19 +4,20 @@ 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\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @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 +52,9 @@ public function testCreateTableWithInsert(): void public function testDefaultValue(): void { - $this->setFixture('Type/int.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(FixtureDump::TYPE_INT); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('int_default'); $this->assertSame('int', $tableSchema?->getColumn('Myint')->getDbType()); @@ -64,9 +65,9 @@ public function testDefaultValue(): void public function testDefaultValueWithInsert(): void { - $this->setFixture('Type/int.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(FixtureDump::TYPE_INT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('int_default', [])->execute(); @@ -87,9 +88,9 @@ public function testDefaultValueWithInsert(): void */ public function testMaxValue(): void { - $this->setFixture('Type/int.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(FixtureDump::TYPE_INT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('int', ['Myint1' => 2_147_483_647, 'Myint2' => 0])->execute(); @@ -126,9 +127,9 @@ public function testMaxValue(): void public function testMaxValueException(): void { - $this->setFixture('Type/int.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(FixtureDump::TYPE_INT); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -144,9 +145,9 @@ public function testMaxValueException(): void */ public function testMinValue(): void { - $this->setFixture('Type/int.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(FixtureDump::TYPE_INT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('int', ['Myint1' => -2_147_483_648, 'Myint2' => 0])->execute(); @@ -183,9 +184,9 @@ public function testMinValue(): void public function testMinValueException(): void { - $this->setFixture('Type/int.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(FixtureDump::TYPE_INT); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -198,8 +199,9 @@ public function testMinValueException(): void public function testIdentityTypecasting(): void { - $this->setFixture('Type/int.sql'); - $db = $this->getConnection(true); + $db = $this->getSharedConnection(); + $this->loadFixture(FixtureDump::TYPE_INT); + $db->createCommand()->insert('int', ['Myint1' => 1])->execute(); $result = $db @@ -214,7 +216,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 0093fa21..8fa3ce53 100644 --- a/tests/Type/JsonTest.php +++ b/tests/Type/JsonTest.php @@ -4,33 +4,20 @@ 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\Fixture\FixtureDump; +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 +30,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 +49,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(FixtureDump::TYPE_JSON); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('json_default'); $this->assertSame('nvarchar', $tableSchema?->getColumn('Myjson')->getDbType()); @@ -89,18 +62,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(FixtureDump::TYPE_JSON); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('json_default', [])->execute(); @@ -116,18 +82,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(FixtureDump::TYPE_JSON); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('json', ['Myjson' => 'invalid'])->execute(); @@ -141,18 +100,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(FixtureDump::TYPE_JSON); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('json', ['Myjson' => '{"a":1,"b":2,"c":3,"d":4,"e":5}'])->execute(); @@ -166,18 +118,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(FixtureDump::TYPE_JSON); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('json', ['Myjson' => '{"a":1,"b":2,"c":3,"d":4,"e":5}'])->execute(); @@ -242,7 +187,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 a7ab787d..2b4e6e94 100644 --- a/tests/Type/MoneyTest.php +++ b/tests/Type/MoneyTest.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\Fixture\FixtureDump; +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 +31,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 +50,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(FixtureDump::TYPE_MONEY); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('money_default'); $this->assertSame('money', $tableSchema->getColumn('Mymoney')->getDbType()); @@ -89,18 +63,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(FixtureDump::TYPE_MONEY); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('money_default', [])->execute(); @@ -118,18 +85,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(FixtureDump::TYPE_MONEY); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('money', ['Mymoney1' => '922337203685477.5807', 'Mymoney2' => '0'])->execute(); @@ -164,18 +125,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(FixtureDump::TYPE_MONEY); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -188,18 +142,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(FixtureDump::TYPE_MONEY); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('money', ['Mymoney1' => '-922337203685477.5808', 'Mymoney2' => 0])->execute(); @@ -234,18 +182,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(FixtureDump::TYPE_MONEY); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -258,7 +199,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 9898ff8a..a5c07c90 100644 --- a/tests/Type/NTextTest.php +++ b/tests/Type/NTextTest.php @@ -4,14 +4,10 @@ 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\Fixture\FixtureDump; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; +use Yiisoft\Db\Tests\Support\IntegrationTestCase; /** * @group mssql @@ -20,17 +16,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 +32,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 +51,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(FixtureDump::TYPE_NTEXT); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('ntext_default'); $this->assertSame('ntext', $tableSchema?->getColumn('Myntext')->getDbType()); @@ -89,18 +64,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(FixtureDump::TYPE_NTEXT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('ntext_default', [])->execute(); @@ -116,18 +84,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(FixtureDump::TYPE_NTEXT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('ntext', ['Myntext1' => '0123456789', 'Myntext2' => null])->execute(); @@ -149,7 +110,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 b25e427b..2d1152af 100644 --- a/tests/Type/NumericTest.php +++ b/tests/Type/NumericTest.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\Expression\Expression; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; +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 +33,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 +52,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(FixtureDump::TYPE_NUMERIC); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('numeric_default'); $this->assertSame('numeric', $tableSchema?->getColumn('Mynumeric')->getDbType()); @@ -92,18 +66,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(FixtureDump::TYPE_NUMERIC); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('numeric_default', [])->execute(); @@ -121,18 +88,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(FixtureDump::TYPE_NUMERIC); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'numeric', @@ -175,18 +136,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(FixtureDump::TYPE_NUMERIC); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'numeric', @@ -227,18 +182,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(FixtureDump::TYPE_NUMERIC); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -254,7 +202,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 5bb6de0b..69b0a07a 100644 --- a/tests/Type/RealTest.php +++ b/tests/Type/RealTest.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\Expression\Expression; -use Yiisoft\Db\Mssql\Tests\Support\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; +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 +32,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 +51,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(FixtureDump::TYPE_REAL); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('real_default'); $this->assertSame('real', $tableSchema?->getColumn('Myreal')->getDbType()); @@ -90,18 +64,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(FixtureDump::TYPE_REAL); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('real_default', [])->execute(); @@ -119,18 +86,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(FixtureDump::TYPE_REAL); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('real', ['Myreal1' => '3.4E+38', 'Myreal2' => '0'])->execute(); @@ -165,18 +126,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(FixtureDump::TYPE_REAL); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -189,18 +143,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(FixtureDump::TYPE_REAL); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('real', ['Myreal1' => '-3.4E+38', 'Myreal2' => '0'])->execute(); @@ -235,18 +183,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(FixtureDump::TYPE_REAL); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -259,7 +200,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 276f5eee..c8b22c03 100644 --- a/tests/Type/RowversionTest.php +++ b/tests/Type/RowversionTest.php @@ -4,37 +4,24 @@ 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\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; +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(FixtureDump::TYPE_ROWVERSION); - $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 96ae8dd4..63ebf5af 100644 --- a/tests/Type/SmallIntTest.php +++ b/tests/Type/SmallIntTest.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\Fixture\FixtureDump; +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 +31,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 +50,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(FixtureDump::TYPE_SMALLINT); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('smallint_default'); $this->assertSame('smallint', $tableSchema?->getColumn('Mysmallint')->getDbType()); @@ -89,18 +63,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(FixtureDump::TYPE_SMALLINT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('smallint_default', [])->execute(); @@ -118,18 +85,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(FixtureDump::TYPE_SMALLINT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('smallint', ['Mysmallint1' => 32767, 'Mysmallint2' => 0])->execute(); @@ -164,18 +125,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(FixtureDump::TYPE_SMALLINT); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -188,18 +142,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(FixtureDump::TYPE_SMALLINT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('smallint', ['Mysmallint1' => -32768, 'Mysmallint2' => 0])->execute(); @@ -234,18 +182,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(FixtureDump::TYPE_SMALLINT); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -258,7 +199,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 5d822200..35c30dd6 100644 --- a/tests/Type/SmallMoneyTest.php +++ b/tests/Type/SmallMoneyTest.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\Fixture\FixtureDump; +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 +31,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 +50,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(FixtureDump::TYPE_SMALLMONEY); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('smallmoney_default'); $this->assertSame('smallmoney', $tableSchema?->getColumn('Mysmallmoney')->getDbType()); @@ -89,18 +63,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(FixtureDump::TYPE_SMALLMONEY); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('smallmoney_default', [])->execute(); @@ -118,18 +85,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(FixtureDump::TYPE_SMALLMONEY); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('smallmoney', ['Mysmallmoney1' => '214748.3647', 'Mysmallmoney2' => '0'])->execute(); @@ -164,18 +125,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(FixtureDump::TYPE_SMALLMONEY); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -188,18 +142,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(FixtureDump::TYPE_SMALLMONEY); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('smallmoney', ['Mysmallmoney1' => '-214748.3648', 'Mysmallmoney2' => 0])->execute(); @@ -234,18 +182,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(FixtureDump::TYPE_SMALLMONEY); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -258,7 +199,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 ae9d305f..3e9205d1 100644 --- a/tests/Type/TextTest.php +++ b/tests/Type/TextTest.php @@ -4,33 +4,20 @@ 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\Fixture\FixtureDump; +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 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 +30,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 +49,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(FixtureDump::TYPE_TEXT); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('text_default'); $this->assertSame('text', $tableSchema?->getColumn('Mytext')->getDbType()); @@ -89,18 +62,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(FixtureDump::TYPE_TEXT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('text_default', [])->execute(); @@ -116,18 +82,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(FixtureDump::TYPE_TEXT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('text', ['Mytext1' => '0123456789', 'Mytext2' => null])->execute(); @@ -149,7 +108,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 9c8c4cea..2b5aa2bb 100644 --- a/tests/Type/TinyIntTest.php +++ b/tests/Type/TinyIntTest.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\Fixture\FixtureDump; +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 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 +31,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 +50,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(FixtureDump::TYPE_TINYINT); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('tinyint_default'); $this->assertSame('tinyint', $tableSchema?->getColumn('Mytinyint')->getDbType()); @@ -89,18 +63,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(FixtureDump::TYPE_TINYINT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('tinyint_default', [])->execute(); @@ -118,18 +85,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(FixtureDump::TYPE_TINYINT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('tinyint', ['Mytinyint1' => 255, 'Mytinyint2' => 0])->execute(); @@ -179,18 +140,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(FixtureDump::TYPE_TINYINT); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -203,18 +157,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(FixtureDump::TYPE_TINYINT); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('tinyint', ['Mytinyint1' => 0, 'Mytinyint2' => null])->execute(); @@ -249,18 +197,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(FixtureDump::TYPE_TINYINT); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -273,7 +214,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 79a823e6..636f0df2 100644 --- a/tests/Type/UniqueidentifierTest.php +++ b/tests/Type/UniqueidentifierTest.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\Fixture\FixtureDump; +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 +34,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 +53,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(FixtureDump::TYPE_UNIQUEIDENTIFIER); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('uniqueidentifier_default'); $this->assertSame('uniqueidentifier', $tableSchema?->getColumn('Myuniqueidentifier')->getDbType()); @@ -95,18 +69,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(FixtureDump::TYPE_UNIQUEIDENTIFIER); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('uniqueidentifier_default', [])->execute(); @@ -124,18 +91,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(FixtureDump::TYPE_UNIQUEIDENTIFIER); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'uniqueidentifier', @@ -158,18 +119,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(FixtureDump::TYPE_UNIQUEIDENTIFIER); $this->expectException(Exception::class); $this->expectExceptionMessage( @@ -182,18 +135,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(FixtureDump::TYPE_UNIQUEIDENTIFIER); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'uniqueidentifier', @@ -218,7 +165,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 4c4f5fba..d3a3bb47 100644 --- a/tests/Type/VarBinaryTest.php +++ b/tests/Type/VarBinaryTest.php @@ -4,37 +4,25 @@ 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\TestTrait; +use Yiisoft\Db\Mssql\Tests\Support\Fixture\FixtureDump; +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 +42,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 +63,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 +71,9 @@ public function testDefaultValue( int $size, Expression $defaultValue, ): void { - $this->setFixture('Type/varbinary.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(FixtureDump::TYPE_VARBINARY); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('varbinary_default'); $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); @@ -108,18 +83,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(FixtureDump::TYPE_VARBINARY); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('varbinary_default', [])->execute(); @@ -137,18 +105,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(FixtureDump::TYPE_VARBINARY); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('varbinary', [ 'Myvarbinary1' => new Expression('CONVERT(varbinary(10), \'binary_default_value\')'), @@ -173,47 +135,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 e8f32717..5e269800 100644 --- a/tests/Type/VarCharTest.php +++ b/tests/Type/VarCharTest.php @@ -4,36 +4,25 @@ namespace Yiisoft\Db\Mssql\Tests\Type; -use PHPUnit\Framework\TestCase; -use Throwable; +use PHPUnit\Framework\Attributes\DataProviderExternal; 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\TestTrait; +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; /** * @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 +41,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 +62,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 +70,9 @@ public function testDefaultValue( int $size, string|Expression $defaultValue, ): void { - $this->setFixture('Type/varchar.sql'); + $db = $this->getSharedConnection(); + $this->loadFixture(FixtureDump::TYPE_VARCHAR); - $db = $this->getConnection(true); $tableSchema = $db->getTableSchema('varchar_default'); $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); @@ -106,18 +82,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(FixtureDump::TYPE_VARCHAR); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert('varchar_default', [])->execute(); @@ -133,18 +102,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(FixtureDump::TYPE_VARCHAR); - $db = $this->getConnection(true); $command = $db->createCommand(); $command->insert( 'varchar', @@ -174,18 +136,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(FixtureDump::TYPE_VARCHAR); - $db = $this->getConnection(true); $command = $db->createCommand(); $this->expectException(Exception::class); @@ -198,7 +153,7 @@ public function testValueException(): void private function buildTable(): ConnectionInterface { - $db = $this->getConnection(); + $db = $this->getSharedConnection(); $command = $db->createCommand();