diff --git a/tests/ColumnBuilderTest.php b/tests/ColumnBuilderTest.php index 02fcf419..1f537697 100644 --- a/tests/ColumnBuilderTest.php +++ b/tests/ColumnBuilderTest.php @@ -6,6 +6,7 @@ use PHPUnit\Framework\Attributes\DataProviderExternal; use Yiisoft\Db\Mssql\Tests\Provider\ColumnBuilderProvider; +use Yiisoft\Db\Mssql\Tests\Support\IntegrationTestTrait; use Yiisoft\Db\Tests\Common\CommonColumnBuilderTest; /** @@ -13,6 +14,8 @@ */ class ColumnBuilderTest extends CommonColumnBuilderTest { + use IntegrationTestTrait; + #[DataProviderExternal(ColumnBuilderProvider::class, 'buildingMethods')] public function testBuildingMethods( string $buildingMethod, diff --git a/tests/ColumnTest.php b/tests/ColumnTest.php index bcc6f08d..98b8a268 100644 --- a/tests/ColumnTest.php +++ b/tests/ColumnTest.php @@ -41,7 +41,7 @@ public function testSelectWithPhpTypecasting(): void $expected = [ 'null' => null, 1 => 1, - '2.5' => 2.5, + '2.5' => '2.5', 'string' => 'string', ]; @@ -67,13 +67,13 @@ public function testSelectWithPhpTypecasting(): void ->withPhpTypecasting() ->queryScalar(); - $this->assertSame(2.5, $result); + $this->assertSame('2.5', $result); $result = $db->createCommand('SELECT 2.5 UNION SELECT 3.3') ->withPhpTypecasting() ->queryColumn(); - $this->assertSame([2.5, 3.3], $result); + $this->assertSame(['2.5', '3.3'], $result); $db->close(); } diff --git a/tests/Provider/ColumnFactoryProvider.php b/tests/Provider/ColumnFactoryProvider.php index bbd9bf4b..77fafc02 100644 --- a/tests/Provider/ColumnFactoryProvider.php +++ b/tests/Provider/ColumnFactoryProvider.php @@ -39,8 +39,8 @@ public static function dbTypes(): array ['smallint', ColumnType::SMALLINT, IntegerColumn::class], ['int', ColumnType::INTEGER, IntegerColumn::class], ['bigint', ColumnType::BIGINT, IntegerColumn::class], - ['numeric', ColumnType::DECIMAL, DoubleColumn::class], - ['decimal', ColumnType::DECIMAL, DoubleColumn::class], + ['numeric', ColumnType::DECIMAL, StringColumn::class], + ['decimal', ColumnType::DECIMAL, StringColumn::class], ['float', ColumnType::FLOAT, DoubleColumn::class], ['real', ColumnType::FLOAT, DoubleColumn::class], ['double', ColumnType::DOUBLE, DoubleColumn::class], diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 7955b375..b588b073 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -424,9 +424,9 @@ public static function insertReturningPks(): array ['order_id' => 1, 'item_id' => 1, 'quantity' => 1, 'subtotal' => 1.0], [], << new Param('1', DataType::STRING)], ], ]; } @@ -642,14 +642,14 @@ public static function upsertReturning(): array ['id_1' => 1, 'id_2' => 2.5, 'type' => 'Test'], true, ['id_1', 'id_2'], - 'SET NOCOUNT ON;DECLARE @temporary_inserted TABLE ([id_1] int, [id_2] decimal(5,2));' - . 'MERGE [notauto_pk] WITH (HOLDLOCK) USING (VALUES (1, 2.5, :qp0)) AS EXCLUDED' + 'SET NOCOUNT ON;DECLARE @temporary_inserted TABLE ([id_1] int, [id_2] decimal(5,1));' + . 'MERGE [notauto_pk] WITH (HOLDLOCK) USING (VALUES (1, :qp0, :qp1)) AS EXCLUDED' . ' ([id_1], [id_2], [type]) ON (([notauto_pk].[id_1]=EXCLUDED.[id_1])' . ' AND ([notauto_pk].[id_2]=EXCLUDED.[id_2])) WHEN MATCHED THEN UPDATE SET [type]=EXCLUDED.[type]' . ' WHEN NOT MATCHED THEN INSERT ([id_1], [id_2], [type])' . ' VALUES (EXCLUDED.[id_1], EXCLUDED.[id_2], EXCLUDED.[type])' . ' OUTPUT INSERTED.[id_1],INSERTED.[id_2] INTO @temporary_inserted;SELECT * FROM @temporary_inserted;', - [':qp0' => new Param('Test', DataType::STRING)], + [':qp0' => new Param('2.5', DataType::STRING), ':qp1' => new Param('Test', DataType::STRING)], ], 'no return columns' => [ 'type', diff --git a/tests/Provider/SchemaProvider.php b/tests/Provider/SchemaProvider.php index 34821eb3..b95e88fb 100644 --- a/tests/Provider/SchemaProvider.php +++ b/tests/Provider/SchemaProvider.php @@ -70,11 +70,10 @@ public static function columns(): array collation: 'SQL_Latin1_General_CP1_CI_AS', ), 'float_col' => new DoubleColumn( - ColumnType::DECIMAL, - dbType: 'decimal', + ColumnType::FLOAT, + dbType: 'float', notNull: true, - size: 4, - scale: 3, + size: 53, ), 'float_col2' => new DoubleColumn( ColumnType::FLOAT, @@ -85,12 +84,12 @@ public static function columns(): array 'blob_col' => new BinaryColumn( dbType: 'varbinary', ), - 'numeric_col' => new DoubleColumn( + 'numeric_col' => new StringColumn( ColumnType::DECIMAL, dbType: 'decimal', - size: 5, scale: 2, - defaultValue: 33.22, + size: 5, + defaultValue: '33.22', ), 'datetime_col' => new DateTimeColumn( dbType: 'datetime', @@ -221,7 +220,7 @@ public static function resultColumns(): array 'len' => 2147483647, 'precision' => 0, ]], - [new DoubleColumn(ColumnType::DECIMAL, dbType: 'decimal', name: 'float_col', size: 4, scale: 3), [ + [new StringColumn(ColumnType::DECIMAL, dbType: 'decimal', name: 'float_col', scale: 3, size: 4), [ 'flags' => 0, 'sqlsrv:decl_type' => 'decimal', 'native_type' => 'string', @@ -291,7 +290,7 @@ public static function resultColumns(): array 'len' => 0, 'precision' => 0, ]], - [new DoubleColumn(ColumnType::DECIMAL, dbType: 'numeric', name: '2.5', size: 2, scale: 1), [ + [new StringColumn(ColumnType::DECIMAL, dbType: 'numeric', name: '2.5', scale: 1, size: 2), [ 'flags' => 0, 'sqlsrv:decl_type' => 'numeric', 'native_type' => 'string', diff --git a/tests/Support/Fixture/mssql.sql b/tests/Support/Fixture/mssql.sql index 4b9f0a87..acfd799f 100644 --- a/tests/Support/Fixture/mssql.sql +++ b/tests/Support/Fixture/mssql.sql @@ -149,7 +149,7 @@ CREATE TABLE [dbo].[type] ( [char_col] [char](100) NOT NULL, [char_col2] [varchar](100) COLLATE Latin1_General_CI_AS DEFAULT 'something', [char_col3] [text], - [float_col] [decimal](4,3) NOT NULL, + [float_col] [float] NOT NULL, [float_col2] [float] DEFAULT '1.23', [blob_col] [varbinary](MAX), [numeric_col] [decimal](5,2) DEFAULT '33.22', @@ -178,7 +178,7 @@ CREATE TABLE [dbo].[default_pk] ( CREATE TABLE [dbo].[notauto_pk] ( [id_1] [INT], - [id_2] [DECIMAL](5,2), + [id_2] [DECIMAL](5,1), [type] [VARCHAR](255) NOT NULL, CONSTRAINT [PK_notauto_pk] PRIMARY KEY CLUSTERED ( [id_1] ASC, diff --git a/tests/Type/DecimalTest.php b/tests/Type/DecimalTest.php index dc6b7797..28275da0 100644 --- a/tests/Type/DecimalTest.php +++ b/tests/Type/DecimalTest.php @@ -28,7 +28,10 @@ public function testCreateTableWithDefaultValue(): void $this->assertSame('decimal', $tableSchema?->getColumn('Mydecimal')->getDbType()); $this->assertSame(38, $tableSchema?->getColumn('Mydecimal')->getSize()); - $this->assertSame(9.9999999999999998e+037, $tableSchema?->getColumn('Mydecimal')->getDefaultValue()); + $this->assertSame( + '99999999999999997748809823456034029568', + $tableSchema?->getColumn('Mydecimal')->getDefaultValue(), + ); $db->createCommand()->insert('decimal_default', [])->execute(); } @@ -61,7 +64,7 @@ public function testDefaultValue(): void $this->assertSame('decimal', $tableSchema?->getColumn('Mydecimal')->getDbType()); $this->assertSame(38, $tableSchema?->getColumn('Mydecimal')->getSize()); - $this->assertSame(9.9999999999999998e+037, $tableSchema?->getColumn('Mydecimal')->getDefaultValue()); + $this->assertSame('9.9999999999999998e+037', $tableSchema?->getColumn('Mydecimal')->getDefaultValue()); $db->createCommand()->dropTable('decimal_default')->execute(); } diff --git a/tests/Type/NumericTest.php b/tests/Type/NumericTest.php index 2d1152af..52598a7d 100644 --- a/tests/Type/NumericTest.php +++ b/tests/Type/NumericTest.php @@ -28,7 +28,10 @@ public function testCreateTableWithDefaultValue(): void $this->assertSame('numeric', $tableSchema?->getColumn('Mynumeric')->getDbType()); $this->assertSame(38, $tableSchema?->getColumn('Mynumeric')->getSize()); - $this->assertSame(9.9999999999999998e+037, $tableSchema?->getColumn('Mynumeric')->getDefaultValue()); + $this->assertSame( + '99999999999999997748809823456034029568', + $tableSchema?->getColumn('Mynumeric')->getDefaultValue(), + ); $db->createCommand()->dropTable('numeric_default')->execute(); } @@ -61,7 +64,7 @@ public function testDefaultValue(): void $this->assertSame('numeric', $tableSchema?->getColumn('Mynumeric')->getDbType()); $this->assertSame(38, $tableSchema?->getColumn('Mynumeric')->getSize()); - $this->assertSame(9.9999999999999998e+037, $tableSchema?->getColumn('Mynumeric')->getDefaultValue()); + $this->assertSame('9.9999999999999998e+037', $tableSchema?->getColumn('Mynumeric')->getDefaultValue()); $db->createCommand()->dropTable('numeric_default')->execute(); }