diff --git a/tests/Function/CastTest.php b/tests/Function/CastTest.php deleted file mode 100644 index 1f2c29922..000000000 --- a/tests/Function/CastTest.php +++ /dev/null @@ -1,171 +0,0 @@ -buildTable(); - - $tableSchema = $db->getTableSchema('cast'); - - $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); - $this->assertSame($phpType, $tableSchema?->getColumn($column)->getPhpType()); - $this->assertSame($defaultValue, $tableSchema?->getColumn($column)->getDefaultValue()); - - $db->createCommand()->dropTable('cast')->execute(); - } - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testCreateTableWithInsert(): void - { - $db = $this->buildTable(); - - $command = $db->createCommand(); - $command->insert('cast', [])->execute(); - - $this->assertSame( - $this->getColumns(), - $command->setSql( - <<queryOne(), - ); - - $db->createCommand()->dropTable('cast')->execute(); - } - - /** - * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Function\ConvertionProvider::castColumns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testDefaultValue( - string $column, - string $dbType, - string $phpType, - string $defaultValue - ): void { - $this->setFixture('Function/convertion.sql'); - - $db = $this->getConnection(true); - $tableSchema = $db->getTableSchema('cast'); - - $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); - $this->assertSame($phpType, $tableSchema?->getColumn($column)->getPhpType()); - $this->assertSame($defaultValue, $tableSchema?->getColumn($column)->getDefaultValue()); - - $db->createCommand()->dropTable('cast')->execute(); - } - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testDefaultValueWithInsert(): void - { - $this->setFixture('Function/convertion.sql'); - - $db = $this->getConnection(true); - $command = $db->createCommand(); - $command->insert('cast', [])->execute(); - - $this->assertSame( - $this->getColumns(), - $command->setSql( - <<queryOne(), - ); - - $db->createCommand()->dropTable('cast')->execute(); - } - - private function buildTable(): ConnectionInterface - { - $db = $this->getConnection(); - - $command = $db->createCommand(); - - if ($db->getSchema()->getTableSchema('cast') !== null) { - $command->dropTable('cast')->execute(); - } - - $command->createTable( - 'cast', - [ - 'id' => 'INT IDENTITY NOT NULL', - 'Mycast1' => 'INT NOT NULL DEFAULT CAST(\'1\' AS INT)', - 'Mycast2' => 'INT NOT NULL DEFAULT CAST(14.85 AS INT)', - 'Mycast3' => 'FLOAT NOT NULL DEFAULT CAST(\'14.85\' AS FLOAT)', - 'Mycast4' => 'VARCHAR(4) NOT NULL DEFAULT CAST(15.6 AS VARCHAR(4))', - 'Mycast5' => 'DATETIME NOT NULL DEFAULT CAST(\'2023-02-21\' AS DATETIME)', - 'Mycast6' => 'BINARY(10) NOT NULL DEFAULT CAST(\'testme\' AS BINARY(10))', - ], - )->execute(); - - return $db; - } - - private function getColumns(): array - { - return [ - 'id' => '1', - 'Mycast1' => '1', - 'Mycast2' => '14', - 'Mycast3' => '14.85', - 'Mycast4' => '15.6', - 'Mycast5' => '2023-02-21 00:00:00.000', - 'Mycast6' => '0x74657374', - ]; - } -} diff --git a/tests/Function/ConvertTest.php b/tests/Function/ConvertTest.php deleted file mode 100644 index 1d129dc95..000000000 --- a/tests/Function/ConvertTest.php +++ /dev/null @@ -1,172 +0,0 @@ -buildTable(); - - $tableSchema = $db->getTableSchema('convert'); - - $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); - $this->assertSame($phpType, $tableSchema?->getColumn($column)->getPhpType()); - $this->assertSame($defaultValue, $tableSchema?->getColumn($column)->getDefaultValue()); - - $db->createCommand()->dropTable('convert')->execute(); - } - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testCreateTableWithInsert(): void - { - $db = $this->buildTable(); - - $command = $db->createCommand(); - $command->insert('convert', [])->execute(); - - $this->assertSame( - $this->getColumns(), - $command->setSql( - <<queryOne(), - ); - - $db->createCommand()->dropTable('convert')->execute(); - } - - /** - * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Function\ConvertionProvider::convertColumns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testDefaultValue( - string $column, - string $dbType, - string $phpType, - string $defaultValue - ): void { - $this->setFixture('Function/convertion.sql'); - - $db = $this->getConnection(true); - $tableSchema = $db->getTableSchema('convert'); - - $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); - $this->assertSame($phpType, $tableSchema?->getColumn($column)->getPhpType()); - $this->assertSame($defaultValue, $tableSchema?->getColumn($column)->getDefaultValue()); - - $db->createCommand()->dropTable('convert')->execute(); - } - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testDefaultValueWithInsert(): void - { - $this->setFixture('Function/convertion.sql'); - - $db = $this->getConnection(true); - $command = $db->createCommand(); - - $command->insert('convert', [])->execute(); - - $this->assertSame( - $this->getColumns(), - $command->setSql( - <<queryOne(), - ); - - $db->createCommand()->dropTable('convert')->execute(); - } - - private function buildTable(): ConnectionInterface - { - $db = $this->getConnection(); - - $command = $db->createCommand(); - - if ($db->getSchema()->getTableSchema('convert') !== null) { - $command->dropTable('convert')->execute(); - } - - $command->createTable( - 'convert', - [ - 'id' => 'int IDENTITY(1,1) PRIMARY KEY', - 'Myconvert1' => 'INT NOT NULL DEFAULT CONVERT([INT],\'1\')', - 'Myconvert2' => 'INT NOT NULL DEFAULT CONVERT([INT],(14.85))', - 'Myconvert3' => 'FLOAT NOT NULL DEFAULT CONVERT([FLOAT],\'14.85\')', - 'Myconvert4' => 'VARCHAR(4) NOT NULL DEFAULT CONVERT([VARCHAR](4),(15.6))', - 'Myconvert5' => 'DATETIME NOT NULL DEFAULT CONVERT([DATETIME],\'2023-02-21\')', - 'Myconvert6' => 'BINARY(10) NOT NULL DEFAULT CONVERT([BINARY](10),\'testme\')', - ], - )->execute(); - - return $db; - } - - private function getColumns(): array - { - return [ - 'id' => '1', - 'Myconvert1' => '1', - 'Myconvert2' => '14', - 'Myconvert3' => '14.85', - 'Myconvert4' => '15.6', - 'Myconvert5' => '2023-02-21 00:00:00.000', - 'Myconvert6' => '0x74657374', - ]; - } -} diff --git a/tests/Function/DateTimeTest.php b/tests/Function/DateTimeTest.php deleted file mode 100644 index 11cfab86e..000000000 --- a/tests/Function/DateTimeTest.php +++ /dev/null @@ -1,277 +0,0 @@ -buildTable(); - - $tableSchema = $db->getTableSchema('datetime'); - - $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); - $this->assertSame($phpType, $tableSchema?->getColumn($column)->getPhpType()); - $this->assertSame($defaultValue, $tableSchema?->getColumn($column)->getDefaultValue()); - - $db->createCommand()->dropTable('datetime')->execute(); - } - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testCreateTableWithInsert(): void - { - $db = $this->buildTable(); - - $command = $db->createCommand(); - $command->insert('datetime', [])->execute(); - - $this->assertSame( - $this->getColumns(), - $command->setSql( - <<queryOne(), - ); - - $this->assertInstanceOf( - DateTime::class, - DateTime::createFromFormat( - 'Y-m-d H:i:s.u', - (string) $command->setSql( - <<queryScalar(), - ), - ); - - $this->assertInstanceOf( - DateTime::class, - DateTime::createFromFormat( - 'Y-m-d H:i:s.uv P', - (string) $command->setSql( - <<queryScalar(), - ), - ); - - $this->assertInstanceOf( - DateTime::class, - DateTime::createFromFormat( - 'Y-m-d H:i:s.uv P', - (string) $command->setSql( - <<queryScalar(), - ), - ); - - $this->assertInstanceOf( - DateTime::class, - DateTime::createFromFormat( - 'H:i:s.uv', - (string) $command->setSql( - <<queryScalar(), - ), - ); - - $db->createCommand()->dropTable('datetime')->execute(); - } - - /** - * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Function\DateTimeProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testDefaultValue( - string $column, - string $dbType, - string $phpType, - string $defaultValue - ): void { - $this->setFixture('Function/datetime.sql'); - - $db = $this->getConnection(true); - $tableSchema = $db->getTableSchema('datetime'); - - $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); - $this->assertSame($phpType, $tableSchema?->getColumn($column)->getPhpType()); - $this->assertSame($defaultValue, $tableSchema?->getColumn($column)->getDefaultValue()); - - $db->createCommand()->dropTable('datetime')->execute(); - } - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testDefaultValueWithInsert(): void - { - $this->setFixture('Function/datetime.sql'); - - $db = $this->getConnection(true); - $command = $db->createCommand(); - - $command->insert('datetime', [])->execute(); - - $this->assertSame( - $this->getColumns(), - $command->setSql( - <<queryOne(), - ); - - $this->assertInstanceOf( - DateTime::class, - DateTime::createFromFormat( - 'Y-m-d H:i:s.u', - (string) $command->setSql( - <<queryScalar(), - ), - ); - - $this->assertInstanceOf( - DateTime::class, - DateTime::createFromFormat( - 'Y-m-d H:i:s.uv P', - (string) $command->setSql( - <<queryScalar(), - ), - ); - - $this->assertInstanceOf( - DateTime::class, - DateTime::createFromFormat( - 'Y-m-d H:i:s.uv P', - (string) $command->setSql( - <<queryScalar(), - ), - ); - - $this->assertInstanceOf( - DateTime::class, - DateTime::createFromFormat( - 'H:i:s.uv', - (string) $command->setSql( - <<queryScalar(), - ), - ); - - $db->createCommand()->dropTable('datetime')->execute(); - } - - private function buildTable(): ConnectionInterface - { - $db = $this->getConnection(); - - $command = $db->createCommand(); - - if ($db->getSchema()->getTableSchema('datetime') !== null) { - $command->dropTable('datetime')->execute(); - } - - $command->createTable( - 'datetime', - [ - 'id' => 'INT IDENTITY NOT NULL', - 'Mydate1' => 'DATE NOT NULL DEFAULT GETUTCDATE()', - 'Mydate2' => 'DATE NOT NULL DEFAULT GETDATE()', - 'Mydate3' => 'DATE NOT NULL DEFAULT DATEADD(month, 1, \'2006-08-31\')', - 'Mydatetime1' => 'VARCHAR(10) NOT NULL DEFAULT CAST(datediff(day, \'2005-12-31\', \'2006-01-01\') AS varchar(10)) + \' days\'', - 'Mydatetime2' => 'VARCHAR(10) NOT NULL DEFAULT DATENAME(month,\'2023-02-21\')', - 'Mydatetime3' => 'INT NOT NULL DEFAULT DATEPART(month,\'2023-02-21\')', - 'Mydatetime4' => 'INT NOT NULL DEFAULT DAY(\'2023-02-21\')', - 'Mydatetime5' => 'INT NOT NULL DEFAULT MONTH(\'2023-02-21\')', - 'Mydatetime6' => 'INT NOT NULL DEFAULT YEAR(\'2023-02-21\')', - 'Mydatetime7' => 'DATETIME NOT NULL DEFAULT SYSDATETIME()', - 'Mydatetimeoffset1' => 'DATETIMEOFFSET NOT NULL DEFAULT SYSDATETIMEOFFSET()', - 'Mydatetimeoffset2' => 'DATETIMEOFFSET NOT NULL DEFAULT SYSUTCDATETIME()', - 'Mytime' => 'TIME NOT NULL DEFAULT CURRENT_TIMESTAMP', - ], - )->execute(); - - return $db; - } - - private function getColumns(): array - { - return [ - 'id' => '1', - 'Mydate1' => date('Y-m-d'), - 'Mydate2' => date('Y-m-d'), - 'Mydate3' => '2006-09-30', - 'Mydatetime1' => '1 days', - 'Mydatetime2' => 'February', - 'Mydatetime3' => '2', - 'Mydatetime4' => '21', - 'Mydatetime5' => '2', - 'Mydatetime6' => '2023', - ]; - } -} diff --git a/tests/Function/NumericTest.php b/tests/Function/NumericTest.php deleted file mode 100644 index ab2623288..000000000 --- a/tests/Function/NumericTest.php +++ /dev/null @@ -1,198 +0,0 @@ -buildTable(); - - $tableSchema = $db->getTableSchema('numeric'); - - $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); - $this->assertSame($phpType, $tableSchema?->getColumn($column)->getPhpType()); - $this->assertSame($defaultValue, $tableSchema?->getColumn($column)->getDefaultValue()); - - $db->createCommand()->dropTable('numeric')->execute(); - } - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testCreateTableWithInsert(): void - { - $db = $this->buildTable(); - - $command = $db->createCommand(); - $command->insert('numeric', [])->execute(); - - $row = $command->setSql( - <<queryOne(); - - unset($row['Myrand']); - - $this->assertSame($this->getColumns(), $row); - - $db->createCommand()->dropTable('numeric')->execute(); - } - - /** - * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Function\NumericProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testDefaultValue( - string $column, - string $dbType, - string $phpType, - string $defaultValue - ): void { - $this->setFixture('Function/numeric.sql'); - - $db = $this->getConnection(true); - $tableSchema = $db->getTableSchema('numeric'); - - $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); - $this->assertSame($phpType, $tableSchema?->getColumn($column)->getPhpType()); - $this->assertSame($defaultValue, $tableSchema?->getColumn($column)->getDefaultValue()); - - $db->createCommand()->dropTable('numeric')->execute(); - } - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testDefaultValueWithInsert(): void - { - $this->setFixture('Function/numeric.sql'); - - $db = $this->getConnection(true); - $command = $db->createCommand(); - $command->insert('numeric', [])->execute(); - - $row = $command->setSql( - <<queryOne(); - - unset($row['Myrand']); - - $this->assertSame($this->getColumns(), $row); - - $db->createCommand()->dropTable('numeric')->execute(); - } - - private function buildTable(): ConnectionInterface - { - $db = $this->getConnection(); - - $command = $db->createCommand(); - - if ($db->getSchema()->getTableSchema('numeric') !== null) { - $command->dropTable('numeric')->execute(); - } - - $command->createTable( - 'numeric', - [ - 'id' => 'INT IDENTITY NOT NULL', - 'Myabs' => 'NUMERIC(3,1) NOT NULL DEFAULT ABS(-1)', - 'Myacos' => 'NUMERIC(8,5) NOT NULL DEFAULT ACOS(-1.0)', - 'Myasin' => 'NUMERIC(7,5) NOT NULL DEFAULT ASIN(0.1472738)', - 'Myatan' => 'NUMERIC(11,7) NOT NULL DEFAULT ATAN((197.1099392))', - 'Myceiling' => 'MONEY NOT NULL DEFAULT CEILING($-123.45)', - 'Mycos' => 'NUMERIC(9,6) NOT NULL DEFAULT COS(14.78)', - 'Mycot' => 'NUMERIC(9,6) NOT NULL DEFAULT COT(124.1332)', - 'Mydegrees' => 'NUMERIC(18,7) NOT NULL DEFAULT DEGREES((PI()/2))', - 'Myexp' => 'NUMERIC(11,5) NOT NULL DEFAULT EXP(10.0)', - 'Myfloor' => 'INT NOT NULL DEFAULT FLOOR(-123.45)', - 'Mylog' => 'NUMERIC(6,5) NOT NULL DEFAULT LOG(10.0)', - 'Mylog10' => 'NUMERIC(6,5) NOT NULL DEFAULT LOG10(145.175643)', - 'Mypi' => 'NUMERIC(6,5) NOT NULL DEFAULT PI()', - 'Mypower' => 'NUMERIC(6,3) NOT NULL DEFAULT POWER(2, 2.5)', - 'Myradians' => 'NUMERIC(7,5) NOT NULL DEFAULT RADIANS(180.0)', - 'Myrand' => 'NUMERIC(7,5) NOT NULL DEFAULT RAND()', - 'Myround' => 'NUMERIC(8,4) NOT NULL DEFAULT ROUND(123.9994, 3)', - 'Mysign' => 'FLOAT NOT NULL DEFAULT SIGN(-125)', - 'Mysin' => 'NUMERIC(8,6) NOT NULL DEFAULT SIN(45.175643)', - 'Mysqrt' => 'FLOAT NOT NULL DEFAULT SQRT(10.0)', - ], - )->execute(); - - return $db; - } - - private function getColumns(): array - { - return [ - 'id' => '1', - 'Myabs' => '1.0', - 'Myacos' => '3.14159', - 'Myasin' => '.14781', - 'Myatan' => '1.5657231', - 'Myceiling' => '-123.0000', - 'Mycos' => '-.599465', - 'Mycot' => '-.040312', - 'Mydegrees' => '90.0000000', - 'Myexp' => '22026.46579', - 'Myfloor' => '-124', - 'Mylog' => '2.30259', - 'Mylog10' => '2.16189', - 'Mypi' => '3.14159', - 'Mypower' => '5.000', - 'Myradians' => '3.14159', - 'Myround' => '123.9990', - 'Mysign' => '-1.0', - 'Mysin' => '.929607', - 'Mysqrt' => '3.1622776601683795', - ]; - } -} diff --git a/tests/Function/StringTest.php b/tests/Function/StringTest.php deleted file mode 100644 index 8cbf6b5e5..000000000 --- a/tests/Function/StringTest.php +++ /dev/null @@ -1,144 +0,0 @@ -buildTable(); - - $tableSchema = $db->getTableSchema('string'); - - $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); - $this->assertSame($phpType, $tableSchema?->getColumn($column)->getPhpType()); - $this->assertSame($defaultValue, $tableSchema?->getColumn($column)->getDefaultValue()); - - $db->createCommand()->dropTable('string')->execute(); - } - - /** - * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Function\StringProvider::columns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testDefaultValue( - string $column, - string $dbType, - string $phpType, - string $defaultValue - ): void { - $this->setFixture('Function/string.sql'); - - $db = $this->getConnection(true); - $tableSchema = $db->getTableSchema('string'); - - $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); - $this->assertSame($phpType, $tableSchema?->getColumn($column)->getPhpType()); - $this->assertSame($defaultValue, $tableSchema?->getColumn($column)->getDefaultValue()); - - $db->createCommand()->dropTable('string')->execute(); - } - - private function buildTable(): ConnectionInterface - { - $db = $this->getConnection(); - - $command = $db->createCommand(); - - if ($db->getSchema()->getTableSchema('string') !== null) { - $command->dropTable('string')->execute(); - } - - $command->createTable( - 'string', - [ - 'id' => 'INT NOT NULL IDENTITY', - 'Myascii' => 'INT NOT NULL DEFAULT ASCII(\'a\')', - 'Mychar' => 'CHAR(1) NOT NULL DEFAULT CHAR(97)', - 'Mycharindex' => 'INT NOT NULL DEFAULT charindex(\'B\', \'aBc\')', - 'Myconcat' => 'VARCHAR(3) NOT NULL DEFAULT CONCAT(\'a\',\'b\',\'c\')', - 'Myconcatws' => 'VARCHAR(3) NOT NULL DEFAULT CONCAT_WS(\'a\',\'b\',\'C\')', - 'Mycomplex' => 'VARCHAR(10) NOT NULL DEFAULT SUBSTRING(STUFF(concat(\'a\', \'b\', \'c\'), 3, 1, concat_ws(\'f\', \'g\', \'h\')), 5, 1)', - 'Mydatalength' => 'INT NOT NULL DEFAULT DATALENGTH(\'abc\')', - 'Myleft' => 'VARCHAR(1) NOT NULL DEFAULT LEFT(\'abc\',1)', - 'Mylen' => 'INT NOT NULL DEFAULT LEN(\'abc\')', - 'Mylower' => 'VARCHAR(3) NOT NULL DEFAULT LOWER(\'ABC\')', - 'Myltrim' => 'VARCHAR(3) NOT NULL DEFAULT LTRIM(\' abc\')', - 'Mynchar' => 'NCHAR(1) NOT NULL DEFAULT NCHAR(50)', - 'Mypatindex' => 'INT NOT NULL DEFAULT PATINDEX(\'a\',\'abc\')', - 'Myreplace' => 'VARCHAR(3) NOT NULL DEFAULT replace(\'abc\',\'a\',\'d\')', - 'Myright' => 'VARCHAR(1) NOT NULL DEFAULT right(\'abc\',(1))', - 'Myrtrim' => 'VARCHAR(3) NOT NULL DEFAULT rtrim(\'abc \')', - 'Mystr' => 'VARCHAR(5) NOT NULL DEFAULT str((1.234),(5),(2))', - 'Mystuff' => 'VARCHAR(3) NOT NULL DEFAULT stuff(\'abc\',(1),(1),\'d\')', - 'Mysubstring' => 'VARCHAR(3) NOT NULL DEFAULT substring(\'abc\',(1),(1))', - 'Myupper' => 'VARCHAR(3) NOT NULL DEFAULT upper(\'abc\')', - ], - )->execute(); - - return $db; - } - - private function getColumns(): array - { - return [ - 'id' => '1', - 'Myascii' => '97', - 'Mychar' => 'a', - 'Mycharindex' => '2', - 'Myconcat' => 'abc', - 'Myconcatws' => 'baC', - 'Mycomplex' => 'h', - 'Mydatalength' => '3', - 'Myleft' => 'a', - 'Mylen' => '3', - 'Mylower' => 'abc', - 'Myltrim' => 'abc', - 'Mynchar' => '2', - 'Mypatindex' => '0', - 'Myreplace' => 'dbc', - 'Myright' => 'c', - 'Myrtrim' => 'abc', - 'Mystr' => ' 1.23', - 'Mystuff' => 'dbc', - 'Mysubstring' => 'a', - 'Myupper' => 'ABC', - ]; - } -} diff --git a/tests/Function/TryCastTest.php b/tests/Function/TryCastTest.php deleted file mode 100644 index beb81fa83..000000000 --- a/tests/Function/TryCastTest.php +++ /dev/null @@ -1,171 +0,0 @@ -buildTable(); - - $tableSchema = $db->getTableSchema('trycast'); - - $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); - $this->assertSame($phpType, $tableSchema?->getColumn($column)->getPhpType()); - $this->assertSame($defaultValue, $tableSchema?->getColumn($column)->getDefaultValue()); - - $db->createCommand()->dropTable('trycast')->execute(); - } - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testCreateTableWithInsert(): void - { - $db = $this->buildTable(); - - $command = $db->createCommand(); - $command->insert('trycast', [])->execute(); - - $this->assertSame( - $this->getColumns(), - $command->setSql( - <<queryOne(), - ); - - $db->createCommand()->dropTable('trycast')->execute(); - } - - /** - * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Function\ConvertionProvider::tryCastColumns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testDefaultValue( - string $column, - string $dbType, - string $phpType, - string $defaultValue - ): void { - $this->setFixture('Function/convertion.sql'); - - $db = $this->getConnection(true); - $tableSchema = $db->getTableSchema('trycast'); - - $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); - $this->assertSame($phpType, $tableSchema?->getColumn($column)->getPhpType()); - $this->assertSame($defaultValue, $tableSchema?->getColumn($column)->getDefaultValue()); - - $db->createCommand()->dropTable('trycast')->execute(); - } - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testDefaultValueWithInsert(): void - { - $this->setFixture('Function/convertion.sql'); - - $db = $this->getConnection(true); - $command = $db->createCommand(); - $command->insert('trycast', [])->execute(); - - $this->assertSame( - $this->getColumns(), - $command->setSql( - <<queryOne(), - ); - - $db->createCommand()->dropTable('trycast')->execute(); - } - - private function buildTable(): ConnectionInterface - { - $db = $this->getConnection(); - - $command = $db->createCommand(); - - if ($db->getSchema()->getTableSchema('trycast') !== null) { - $command->dropTable('trycast')->execute(); - } - - $command->createTable( - 'trycast', - [ - 'id' => 'INT IDENTITY NOT NULL', - 'Mytrycast1' => 'INT NOT NULL DEFAULT TRY_CAST(\'1\' AS INT)', - 'Mytrycast2' => 'INT NOT NULL DEFAULT TRY_CAST((14.85) AS INT)', - 'Mytrycast3' => 'FLOAT NOT NULL DEFAULT TRY_CAST(\'14.85\' AS FLOAT)', - 'Mytrycast4' => 'VARCHAR(4) NOT NULL DEFAULT TRY_CAST((15.6) AS VARCHAR(4))', - 'Mytrycast5' => 'DATETIME NOT NULL DEFAULT TRY_CAST(\'2023-02-21\' AS DATETIME)', - 'Mytrycast6' => 'BINARY(10) NOT NULL DEFAULT TRY_CAST(\'testme\' AS BINARY(10))', - ], - )->execute(); - - return $db; - } - - private function getColumns(): array - { - return [ - 'id' => '1', - 'Mytrycast1' => '1', - 'Mytrycast2' => '14', - 'Mytrycast3' => '14.85', - 'Mytrycast4' => '15.6', - 'Mytrycast5' => '2023-02-21 00:00:00.000', - 'Mytrycast' => '0x74657374', - ]; - } -} diff --git a/tests/Function/TryConvertTest.php b/tests/Function/TryConvertTest.php deleted file mode 100644 index 63162a44e..000000000 --- a/tests/Function/TryConvertTest.php +++ /dev/null @@ -1,171 +0,0 @@ -buildTable(); - - $tableSchema = $db->getTableSchema('tryconvert'); - - $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); - $this->assertSame($phpType, $tableSchema?->getColumn($column)->getPhpType()); - $this->assertSame($defaultValue, $tableSchema?->getColumn($column)->getDefaultValue()); - - $db->createCommand()->dropTable('tryconvert')->execute(); - } - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testCreateTableWithInsert(): void - { - $db = $this->buildTable(); - - $command = $db->createCommand(); - $command->insert('tryconvert', [])->execute(); - - $this->assertSame( - $this->getColumns(), - $command->setSql( - <<queryOne(), - ); - - $db->createCommand()->dropTable('tryconvert')->execute(); - } - - /** - * @dataProvider \Yiisoft\Db\Mssql\Tests\Provider\Function\ConvertionProvider::tryConvertColumns - * - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testDefaultValue( - string $column, - string $dbType, - string $phpType, - string $defaultValue - ): void { - $this->setFixture('Function/convertion.sql'); - - $db = $this->getConnection(true); - $tableSchema = $db->getTableSchema('tryconvert'); - - $this->assertSame($dbType, $tableSchema?->getColumn($column)->getDbType()); - $this->assertSame($phpType, $tableSchema?->getColumn($column)->getPhpType()); - $this->assertSame($defaultValue, $tableSchema?->getColumn($column)->getDefaultValue()); - - $db->createCommand()->dropTable('tryconvert')->execute(); - } - - /** - * @throws Exception - * @throws InvalidConfigException - * @throws InvalidArgumentException - * @throws NotSupportedException - * @throws Throwable - */ - public function testDefaultValueWithInsert(): void - { - $this->setFixture('Function/convertion.sql'); - - $db = $this->getConnection(true); - $command = $db->createCommand(); - $command->insert('tryconvert', [])->execute(); - - $this->assertSame( - $this->getColumns(), - $command->setSql( - <<queryOne(), - ); - - $db->createCommand()->dropTable('tryconvert')->execute(); - } - - private function buildTable(): ConnectionInterface - { - $db = $this->getConnection(); - - $command = $db->createCommand(); - - if ($db->getSchema()->getTableSchema('tryconvert') !== null) { - $command->dropTable('tryconvert')->execute(); - } - - $command->createTable( - 'tryconvert', - [ - 'id' => 'INT NOT NULL IDENTITY', - 'Mytryconvert1' => 'INT NOT NULL DEFAULT TRY_CONVERT(INT, \'1\')', - 'Mytryconvert2' => 'INT NOT NULL DEFAULT TRY_CONVERT(INT, 14.85)', - 'Mytryconvert3' => 'FLOAT NOT NULL DEFAULT TRY_CONVERT(FLOAT, \'14.85\')', - 'Mytryconvert4' => 'VARCHAR(4) NOT NULL DEFAULT TRY_CONVERT(VARCHAR(4), 15.6)', - 'Mytryconvert5' => 'DATETIME NOT NULL DEFAULT TRY_CONVERT(DATETIME, \'2023-02-21\')', - 'Mytryconvert6' => 'BINARY(10) NOT NULL DEFAULT TRY_CONVERT(BINARY(10), \'testme\')', - ], - )->execute(); - - return $db; - } - - private function getColumns(): array - { - return [ - 'id' => '1', - 'Mytryconvert1' => '1', - 'Mytryconvert2' => '14', - 'Mytryconvert3' => '14.85', - 'Mytryconvert4' => '15.6', - 'Mytryconvert5' => '2023-02-21 00:00:00.000', - 'Mytryconvert6' => '0x74657374', - ]; - } -} diff --git a/tests/Provider/Function/ConvertionProvider.php b/tests/Provider/Function/ConvertionProvider.php deleted file mode 100644 index c5bf656ac..000000000 --- a/tests/Provider/Function/ConvertionProvider.php +++ /dev/null @@ -1,56 +0,0 @@ -