From 624ef6a9c0fc0af43dd31ca3ac905811ce1a4a37 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 11 Oct 2024 14:11:17 +0700 Subject: [PATCH 1/8] Fix tests --- .github/workflows/build.yml | 5 +++++ tests/Support/TestTrait.php | 2 ++ 2 files changed, 7 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 66adb433e..61153a39a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -63,6 +63,11 @@ jobs: options: --name=mssql --health-cmd="/opt/mssql-tools${{ matrix.mssql.odbc-version }}/bin/sqlcmd ${{ matrix.mssql.flag }} -S localhost -U SA -P 'YourStrong!Passw0rd' -Q 'SELECT 1'" --health-interval=10s --health-timeout=5s --health-retries=3 steps: + - name: Install ODBC driver. + run: | + sudo curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list + sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 + - name: Checkout. uses: actions/checkout@v3 diff --git a/tests/Support/TestTrait.php b/tests/Support/TestTrait.php index 3f77c031c..a5df7a1ce 100644 --- a/tests/Support/TestTrait.php +++ b/tests/Support/TestTrait.php @@ -38,6 +38,7 @@ protected function getConnection(bool $fixture = false): PdoConnectionInterface protected static function getDb(): PdoConnectionInterface { $dsn = (new Dsn('sqlsrv', 'localhost', 'yiitest'))->asString(); + $dsn .= ';TrustServerCertificate=yes'; return new Connection( new Driver($dsn, 'SA', 'YourStrong!Passw0rd'), @@ -49,6 +50,7 @@ protected function getDsn(): string { if ($this->dsn === '') { $this->dsn = (new Dsn('sqlsrv', 'localhost', 'yiitest'))->asString(); + $this->dsn .= ';TrustServerCertificate=yes'; } return $this->dsn; From db7fb487bbac7c3e1f7981b0eb6c58c7ad3fbbf5 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 11 Oct 2024 14:12:59 +0700 Subject: [PATCH 2/8] Fix tests --- .github/workflows/mutation.yml | 5 +++++ tests/Support/TestTrait.php | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 81bbe8ecf..6d76aac36 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -44,6 +44,11 @@ jobs: options: --name=mssql --health-cmd="/opt/mssql-tools18/bin/sqlcmd -S localhost -U SA -P 'YourStrong!Passw0rd' -C -Q 'SELECT 1'" --health-interval=10s --health-timeout=5s --health-retries=3 steps: + - name: Install ODBC driver. + run: | + sudo curl https://packages.microsoft.com/config/ubuntu/$(lsb_release -rs)/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list + sudo ACCEPT_EULA=Y apt-get install -y msodbcsql18 + - name: Checkout. uses: actions/checkout@v3 diff --git a/tests/Support/TestTrait.php b/tests/Support/TestTrait.php index a5df7a1ce..2d1dbe97b 100644 --- a/tests/Support/TestTrait.php +++ b/tests/Support/TestTrait.php @@ -38,7 +38,7 @@ protected function getConnection(bool $fixture = false): PdoConnectionInterface protected static function getDb(): PdoConnectionInterface { $dsn = (new Dsn('sqlsrv', 'localhost', 'yiitest'))->asString(); - $dsn .= ';TrustServerCertificate=yes'; + $dsn .= ';Encrypt=no'; return new Connection( new Driver($dsn, 'SA', 'YourStrong!Passw0rd'), @@ -50,7 +50,7 @@ protected function getDsn(): string { if ($this->dsn === '') { $this->dsn = (new Dsn('sqlsrv', 'localhost', 'yiitest'))->asString(); - $this->dsn .= ';TrustServerCertificate=yes'; + $this->dsn .= ';Encrypt=no'; } return $this->dsn; From fcca0b637fa172da911f46afe969cf9b86dd3ead Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 11 Oct 2024 20:54:55 +0700 Subject: [PATCH 3/8] Fix tests --- src/Dsn.php | 35 ++++++++++++++++++----------- tests/CommandTest.php | 4 ++-- tests/Support/TestTrait.php | 6 ++--- tests/Type/CharTest.php | 2 +- tests/Type/DateTest.php | 2 +- tests/Type/DecimalTest.php | 4 ++-- tests/Type/FloatTest.php | 4 ++-- tests/Type/IntTest.php | 4 ++-- tests/Type/MoneyTest.php | 4 ++-- tests/Type/NumericTest.php | 2 +- tests/Type/RealTest.php | 4 ++-- tests/Type/SmallIntTest.php | 4 ++-- tests/Type/SmallMoneyTest.php | 4 ++-- tests/Type/TinyIntTest.php | 4 ++-- tests/Type/UniqueidentifierTest.php | 2 +- tests/Type/VarCharTest.php | 2 +- 16 files changed, 47 insertions(+), 40 deletions(-) diff --git a/src/Dsn.php b/src/Dsn.php index 6bcb74193..1a08ac0f4 100644 --- a/src/Dsn.php +++ b/src/Dsn.php @@ -14,12 +14,13 @@ final class Dsn extends AbstractDsn { public function __construct( - private string $driver, - private string $host, - private string|null $databaseName = null, - private string $port = '1433' + string $driver = 'sqlsrv', + string $host = 'localhost', + string|null $databaseName = null, + string $port = '1433', + array $options = [] ) { - parent::__construct($driver, $host, $databaseName, $port); + parent::__construct($driver, $host, $databaseName, $port, $options); } /** @@ -39,16 +40,24 @@ public function __construct( */ public function asString(): string { - if ($this->port !== '') { - $server = "Server=$this->host,$this->port;"; - } else { - $server = "Server=$this->host;"; + $driver = $this->getDriver(); + $host = $this->getHost(); + $port = $this->getPort(); + $databaseName = $this->getDatabaseName(); + $options = $this->getOptions(); + + $dsn = "$driver:Server=$host"; + + if (!empty($port)) { + $dsn .= ",$port"; + } + + if (!empty($databaseName)) { + $dsn .= ";Database=$databaseName"; } - if (!empty($this->databaseName)) { - $dsn = "$this->driver:" . $server . "Database=$this->databaseName"; - } else { - $dsn = "$this->driver:" . $server; + if (!empty($options)) { + $dsn .= ';' . http_build_query($options, '', ';'); } return $dsn; diff --git a/tests/CommandTest.php b/tests/CommandTest.php index 607c632d5..560521e49 100644 --- a/tests/CommandTest.php +++ b/tests/CommandTest.php @@ -313,7 +313,7 @@ public function testDropDefaultValueSql(): void public function testShowDatabases(): void { - $dsn = new Dsn('sqlsrv', 'localhost'); + $dsn = new Dsn(options: ['Encrypt' => 'no']); $db = new Connection( new Driver($dsn->asString(), 'SA', 'YourStrong!Passw0rd'), DbHelper::getSchemaCache(), @@ -321,7 +321,7 @@ public function testShowDatabases(): void $command = $db->createCommand(); - $this->assertSame('sqlsrv:Server=localhost,1433;', $db->getDriver()->getDsn()); + $this->assertSame('sqlsrv:Server=localhost,1433;Encrypt=no', $db->getDriver()->getDsn()); $this->assertSame(['yiitest'], $command->showDatabases()); } diff --git a/tests/Support/TestTrait.php b/tests/Support/TestTrait.php index 2d1dbe97b..517caedc7 100644 --- a/tests/Support/TestTrait.php +++ b/tests/Support/TestTrait.php @@ -37,8 +37,7 @@ protected function getConnection(bool $fixture = false): PdoConnectionInterface protected static function getDb(): PdoConnectionInterface { - $dsn = (new Dsn('sqlsrv', 'localhost', 'yiitest'))->asString(); - $dsn .= ';Encrypt=no'; + $dsn = (new Dsn(databaseName: 'yiitest', options: ['Encrypt' => 'no']))->asString(); return new Connection( new Driver($dsn, 'SA', 'YourStrong!Passw0rd'), @@ -49,8 +48,7 @@ protected static function getDb(): PdoConnectionInterface protected function getDsn(): string { if ($this->dsn === '') { - $this->dsn = (new Dsn('sqlsrv', 'localhost', 'yiitest'))->asString(); - $this->dsn .= ';Encrypt=no'; + $this->dsn = (new Dsn(databaseName: 'yiitest', options: ['Encrypt' => 'no']))->asString(); } return $this->dsn; diff --git a/tests/Type/CharTest.php b/tests/Type/CharTest.php index e1bf61da3..6b8764dae 100644 --- a/tests/Type/CharTest.php +++ b/tests/Type/CharTest.php @@ -191,7 +191,7 @@ public function testValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - '[ODBC Driver 17 for SQL Server][SQL Server]String or binary data would be truncated' + '[ODBC Driver 18 for SQL Server][SQL Server]String or binary data would be truncated' ); $command->insert('char', ['Mychar1' => '01234567891'])->execute(); diff --git a/tests/Type/DateTest.php b/tests/Type/DateTest.php index 042745d31..909c7701b 100644 --- a/tests/Type/DateTest.php +++ b/tests/Type/DateTest.php @@ -191,7 +191,7 @@ public function testValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22007]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Conversion failed when converting date and/or time from character string.' + 'SQLSTATE[22007]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Conversion failed when converting date and/or time from character string.' ); $db->createCommand()->insert('date', ['Mydate1' => '0000-00-00'])->execute(); diff --git a/tests/Type/DecimalTest.php b/tests/Type/DecimalTest.php index f11d40110..e57d21b86 100644 --- a/tests/Type/DecimalTest.php +++ b/tests/Type/DecimalTest.php @@ -189,7 +189,7 @@ public function testMaxValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - "SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The number '199999999999999997748809823456034029570' is out of the range for numeric representation (maximum precision 38)." + "SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The number '199999999999999997748809823456034029570' is out of the range for numeric representation (maximum precision 38)." ); $command->insert( @@ -266,7 +266,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - "SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The number '199999999999999997748809823456034029570' is out of the range for numeric representation (maximum precision 38)." + "SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The number '199999999999999997748809823456034029570' is out of the range for numeric representation (maximum precision 38)." ); $command->insert( diff --git a/tests/Type/FloatTest.php b/tests/Type/FloatTest.php index 110fe1194..232141181 100644 --- a/tests/Type/FloatTest.php +++ b/tests/Type/FloatTest.php @@ -186,7 +186,7 @@ public function testMaxValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - "SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The floating point value '1.80E+308' is out of the range of computer representation (8 bytes)." + "SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The floating point value '1.80E+308' is out of the range of computer representation (8 bytes)." ); $command->insert('float', ['Myfloat1' => new Expression('1.80E+308')])->execute(); @@ -256,7 +256,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - "SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The floating point value '1.80E+308' is out of the range of computer representation (8 bytes)." + "SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The floating point value '1.80E+308' is out of the range of computer representation (8 bytes)." ); $command->insert('float', ['Myfloat1' => new Expression('-1.80E+308')])->execute(); diff --git a/tests/Type/IntTest.php b/tests/Type/IntTest.php index 4d513f97b..6c33e2b9e 100644 --- a/tests/Type/IntTest.php +++ b/tests/Type/IntTest.php @@ -182,7 +182,7 @@ public function testMaxValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Arithmetic overflow' + 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow' ); $command->insert('int', ['Myint1' => 2_147_483_648])->execute(); @@ -252,7 +252,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Arithmetic overflow' + 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow' ); $command->insert('int', ['Myint1' => -2_147_483_649])->execute(); diff --git a/tests/Type/MoneyTest.php b/tests/Type/MoneyTest.php index e69983834..275eccc4b 100644 --- a/tests/Type/MoneyTest.php +++ b/tests/Type/MoneyTest.php @@ -182,7 +182,7 @@ public function testMaxValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Arithmetic overflow error converting expression to data type money.' + 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow error converting expression to data type money.' ); $command->insert('money', ['Mymoney1' => '922337203685478.5808'])->execute(); @@ -252,7 +252,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Arithmetic overflow error converting expression to data type money.' + 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow error converting expression to data type money.' ); $command->insert('money', ['Mymoney1' => '-922337203685480.5808'])->execute(); diff --git a/tests/Type/NumericTest.php b/tests/Type/NumericTest.php index 36470b7f8..add591142 100644 --- a/tests/Type/NumericTest.php +++ b/tests/Type/NumericTest.php @@ -245,7 +245,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - "SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The number '199999999999999997748809823456034029570' is out of the range for numeric representation (maximum precision 38)." + "SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The number '199999999999999997748809823456034029570' is out of the range for numeric representation (maximum precision 38)." ); $command->insert( diff --git a/tests/Type/RealTest.php b/tests/Type/RealTest.php index 74ea36c99..1c6bcd550 100644 --- a/tests/Type/RealTest.php +++ b/tests/Type/RealTest.php @@ -183,7 +183,7 @@ public function testMaxValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Arithmetic overflow error for type real' + 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow error for type real' ); $command->insert('real', ['Myreal1' => new Expression('4.4E+38')])->execute(); @@ -253,7 +253,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Arithmetic overflow error for type real' + 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow error for type real' ); $command->insert('real', ['Myreal1' => new Expression('-4.4E+38')])->execute(); diff --git a/tests/Type/SmallIntTest.php b/tests/Type/SmallIntTest.php index 46a01d272..f001e2014 100644 --- a/tests/Type/SmallIntTest.php +++ b/tests/Type/SmallIntTest.php @@ -182,7 +182,7 @@ public function testMaxValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Arithmetic overflow' + 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow' ); $command->insert('smallint', ['Mysmallint1' => 32768])->execute(); @@ -252,7 +252,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Arithmetic overflow' + 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow' ); $command->insert('smallint', ['Mysmallint1' => -32769])->execute(); diff --git a/tests/Type/SmallMoneyTest.php b/tests/Type/SmallMoneyTest.php index 104e766dc..024224659 100644 --- a/tests/Type/SmallMoneyTest.php +++ b/tests/Type/SmallMoneyTest.php @@ -182,7 +182,7 @@ public function testMaxValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Arithmetic overflow error converting expression to data type smallmoney.' + 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow error converting expression to data type smallmoney.' ); $command->insert('smallmoney', ['Mysmallmoney1' => '214749.3647'])->execute(); @@ -252,7 +252,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Arithmetic overflow error converting expression to data type smallmoney.' + 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow error converting expression to data type smallmoney.' ); $command->insert('smallmoney', ['Mysmallmoney1' => '-214749.3648'])->execute(); diff --git a/tests/Type/TinyIntTest.php b/tests/Type/TinyIntTest.php index 9fc3bc786..a440388dc 100644 --- a/tests/Type/TinyIntTest.php +++ b/tests/Type/TinyIntTest.php @@ -197,7 +197,7 @@ public function testMaxValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Arithmetic overflow' + 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow' ); $command->insert('tinyint', ['Mytinyint1' => 256])->execute(); @@ -267,7 +267,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Arithmetic overflow' + 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow' ); $command->insert('tinyint', ['Mytinyint1' => -1])->execute(); diff --git a/tests/Type/UniqueidentifierTest.php b/tests/Type/UniqueidentifierTest.php index 70a653de6..75a025667 100644 --- a/tests/Type/UniqueidentifierTest.php +++ b/tests/Type/UniqueidentifierTest.php @@ -175,7 +175,7 @@ public function testValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[42000]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Conversion failed when converting from a character string to uniqueidentifier.' + 'SQLSTATE[42000]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Conversion failed when converting from a character string to uniqueidentifier.' ); $command = $db->createCommand(); diff --git a/tests/Type/VarCharTest.php b/tests/Type/VarCharTest.php index 405417186..1cad4910f 100644 --- a/tests/Type/VarCharTest.php +++ b/tests/Type/VarCharTest.php @@ -191,7 +191,7 @@ public function testValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - '[Microsoft][ODBC Driver 17 for SQL Server][SQL Server]String or binary data would be truncated' + '[Microsoft][ODBC Driver 18 for SQL Server][SQL Server]String or binary data would be truncated' ); $command->insert('varchar', ['Myvarchar1' => '01234567891'])->execute(); From ea06b5c7f23797a81c3c7c5692a284f3a796e7c3 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 11 Oct 2024 21:02:46 +0700 Subject: [PATCH 4/8] Fix tests --- .github/workflows/build.yml | 2 +- tests/DsnTest.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 61153a39a..1b86df233 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,7 +24,7 @@ jobs: env: COMPOSER_ROOT_VERSION: 1.0.0 - EXTENSIONS: pdo, pdo_sqlsrv-5.10.1 + EXTENSIONS: pdo, pdo_sqlsrv-5.12 runs-on: ${{ matrix.mssql.os || 'ubuntu-latest' }} diff --git a/tests/DsnTest.php b/tests/DsnTest.php index 719c66f2b..0a2c07c0c 100644 --- a/tests/DsnTest.php +++ b/tests/DsnTest.php @@ -24,17 +24,17 @@ public function testAsString(): void public function testAsStringWithDatabaseName(): void { - $this->assertSame('sqlsrv:Server=127.0.0.1,1433;', (new Dsn('sqlsrv', '127.0.0.1'))->asString()); + $this->assertSame('sqlsrv:Server=127.0.0.1,1433', (new Dsn('sqlsrv', '127.0.0.1'))->asString()); } public function testAsStringWithDatabaseNameWithEmptyString(): void { - $this->assertSame('sqlsrv:Server=127.0.0.1,1433;', (new Dsn('sqlsrv', '127.0.0.1', ''))->asString()); + $this->assertSame('sqlsrv:Server=127.0.0.1,1433', (new Dsn('sqlsrv', '127.0.0.1', ''))->asString()); } public function testAsStringWithDatabaseNameWithNull(): void { - $this->assertSame('sqlsrv:Server=127.0.0.1,1433;', (new Dsn('sqlsrv', '127.0.0.1', null))->asString()); + $this->assertSame('sqlsrv:Server=127.0.0.1,1433', (new Dsn('sqlsrv', '127.0.0.1', null))->asString()); } public function testAsStringWithEmptyPort(): void From 0f766cb55a9b58548f0a2c6f777356394b20c3f3 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 11 Oct 2024 21:07:49 +0700 Subject: [PATCH 5/8] Fix psalm --- src/Dsn.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Dsn.php b/src/Dsn.php index 1a08ac0f4..b519d101f 100644 --- a/src/Dsn.php +++ b/src/Dsn.php @@ -13,6 +13,9 @@ */ final class Dsn extends AbstractDsn { + /** + * @param string[] $options + */ public function __construct( string $driver = 'sqlsrv', string $host = 'localhost', From 178f8371841470bbfb292f4b000400ba5966a1c9 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 11 Oct 2024 21:10:31 +0700 Subject: [PATCH 6/8] Fix mutation test --- .github/workflows/mutation.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 6d76aac36..825b2828f 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -20,7 +20,7 @@ jobs: env: COMPOSER_ROOT_VERSION: 1.0.0 - EXTENSIONS: pdo, pdo_sqlsrv-5.10.1 + EXTENSIONS: pdo, pdo_sqlsrv-5.12 runs-on: ${{ matrix.os }} From 72883f7344f73ba2e9a3aeb5ae2f6db58a686dd7 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 11 Oct 2024 21:25:49 +0700 Subject: [PATCH 7/8] Fix tests for 2017 --- tests/Type/CharTest.php | 2 +- tests/Type/DateTest.php | 2 +- tests/Type/DecimalTest.php | 4 ++-- tests/Type/FloatTest.php | 4 ++-- tests/Type/IntTest.php | 4 ++-- tests/Type/MoneyTest.php | 4 ++-- tests/Type/NumericTest.php | 2 +- tests/Type/RealTest.php | 4 ++-- tests/Type/SmallIntTest.php | 4 ++-- tests/Type/SmallMoneyTest.php | 4 ++-- tests/Type/TinyIntTest.php | 4 ++-- tests/Type/UniqueidentifierTest.php | 2 +- tests/Type/VarCharTest.php | 2 +- 13 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/Type/CharTest.php b/tests/Type/CharTest.php index 6b8764dae..071b93792 100644 --- a/tests/Type/CharTest.php +++ b/tests/Type/CharTest.php @@ -191,7 +191,7 @@ public function testValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - '[ODBC Driver 18 for SQL Server][SQL Server]String or binary data would be truncated' + '[SQL Server]String or binary data would be truncated' ); $command->insert('char', ['Mychar1' => '01234567891'])->execute(); diff --git a/tests/Type/DateTest.php b/tests/Type/DateTest.php index 909c7701b..f8e9b9e85 100644 --- a/tests/Type/DateTest.php +++ b/tests/Type/DateTest.php @@ -191,7 +191,7 @@ public function testValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22007]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Conversion failed when converting date and/or time from character string.' + '[SQL Server]Conversion failed when converting date and/or time from character string.' ); $db->createCommand()->insert('date', ['Mydate1' => '0000-00-00'])->execute(); diff --git a/tests/Type/DecimalTest.php b/tests/Type/DecimalTest.php index e57d21b86..d5ade4350 100644 --- a/tests/Type/DecimalTest.php +++ b/tests/Type/DecimalTest.php @@ -189,7 +189,7 @@ public function testMaxValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - "SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The number '199999999999999997748809823456034029570' is out of the range for numeric representation (maximum precision 38)." + "[SQL Server]The number '199999999999999997748809823456034029570' is out of the range for numeric representation (maximum precision 38)." ); $command->insert( @@ -266,7 +266,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - "SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The number '199999999999999997748809823456034029570' is out of the range for numeric representation (maximum precision 38)." + "[SQL Server]The number '199999999999999997748809823456034029570' is out of the range for numeric representation (maximum precision 38)." ); $command->insert( diff --git a/tests/Type/FloatTest.php b/tests/Type/FloatTest.php index 232141181..d9653fca1 100644 --- a/tests/Type/FloatTest.php +++ b/tests/Type/FloatTest.php @@ -186,7 +186,7 @@ public function testMaxValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - "SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The floating point value '1.80E+308' is out of the range of computer representation (8 bytes)." + "[SQL Server]The floating point value '1.80E+308' is out of the range of computer representation (8 bytes)." ); $command->insert('float', ['Myfloat1' => new Expression('1.80E+308')])->execute(); @@ -256,7 +256,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - "SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The floating point value '1.80E+308' is out of the range of computer representation (8 bytes)." + "[SQL Server]The floating point value '1.80E+308' is out of the range of computer representation (8 bytes)." ); $command->insert('float', ['Myfloat1' => new Expression('-1.80E+308')])->execute(); diff --git a/tests/Type/IntTest.php b/tests/Type/IntTest.php index 6c33e2b9e..9444cebf7 100644 --- a/tests/Type/IntTest.php +++ b/tests/Type/IntTest.php @@ -182,7 +182,7 @@ public function testMaxValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow' + '[SQL Server]Arithmetic overflow' ); $command->insert('int', ['Myint1' => 2_147_483_648])->execute(); @@ -252,7 +252,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow' + '[SQL Server]Arithmetic overflow' ); $command->insert('int', ['Myint1' => -2_147_483_649])->execute(); diff --git a/tests/Type/MoneyTest.php b/tests/Type/MoneyTest.php index 275eccc4b..b7cee0ad4 100644 --- a/tests/Type/MoneyTest.php +++ b/tests/Type/MoneyTest.php @@ -182,7 +182,7 @@ public function testMaxValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow error converting expression to data type money.' + '[SQL Server]Arithmetic overflow error converting expression to data type money.' ); $command->insert('money', ['Mymoney1' => '922337203685478.5808'])->execute(); @@ -252,7 +252,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow error converting expression to data type money.' + '[SQL Server]Arithmetic overflow error converting expression to data type money.' ); $command->insert('money', ['Mymoney1' => '-922337203685480.5808'])->execute(); diff --git a/tests/Type/NumericTest.php b/tests/Type/NumericTest.php index add591142..073a1f888 100644 --- a/tests/Type/NumericTest.php +++ b/tests/Type/NumericTest.php @@ -245,7 +245,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - "SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]The number '199999999999999997748809823456034029570' is out of the range for numeric representation (maximum precision 38)." + "[SQL Server]The number '199999999999999997748809823456034029570' is out of the range for numeric representation (maximum precision 38)." ); $command->insert( diff --git a/tests/Type/RealTest.php b/tests/Type/RealTest.php index 1c6bcd550..62bfe4f67 100644 --- a/tests/Type/RealTest.php +++ b/tests/Type/RealTest.php @@ -183,7 +183,7 @@ public function testMaxValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow error for type real' + '[SQL Server]Arithmetic overflow error for type real' ); $command->insert('real', ['Myreal1' => new Expression('4.4E+38')])->execute(); @@ -253,7 +253,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow error for type real' + '[SQL Server]Arithmetic overflow error for type real' ); $command->insert('real', ['Myreal1' => new Expression('-4.4E+38')])->execute(); diff --git a/tests/Type/SmallIntTest.php b/tests/Type/SmallIntTest.php index f001e2014..f9dc0c2f8 100644 --- a/tests/Type/SmallIntTest.php +++ b/tests/Type/SmallIntTest.php @@ -182,7 +182,7 @@ public function testMaxValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow' + '[SQL Server]Arithmetic overflow' ); $command->insert('smallint', ['Mysmallint1' => 32768])->execute(); @@ -252,7 +252,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow' + '[SQL Server]Arithmetic overflow' ); $command->insert('smallint', ['Mysmallint1' => -32769])->execute(); diff --git a/tests/Type/SmallMoneyTest.php b/tests/Type/SmallMoneyTest.php index 024224659..8eb58d64a 100644 --- a/tests/Type/SmallMoneyTest.php +++ b/tests/Type/SmallMoneyTest.php @@ -182,7 +182,7 @@ public function testMaxValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow error converting expression to data type smallmoney.' + '[SQL Server]Arithmetic overflow error converting expression to data type smallmoney.' ); $command->insert('smallmoney', ['Mysmallmoney1' => '214749.3647'])->execute(); @@ -252,7 +252,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow error converting expression to data type smallmoney.' + '[SQL Server]Arithmetic overflow error converting expression to data type smallmoney.' ); $command->insert('smallmoney', ['Mysmallmoney1' => '-214749.3648'])->execute(); diff --git a/tests/Type/TinyIntTest.php b/tests/Type/TinyIntTest.php index a440388dc..94cb01e0c 100644 --- a/tests/Type/TinyIntTest.php +++ b/tests/Type/TinyIntTest.php @@ -197,7 +197,7 @@ public function testMaxValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow' + '[SQL Server]Arithmetic overflow' ); $command->insert('tinyint', ['Mytinyint1' => 256])->execute(); @@ -267,7 +267,7 @@ public function testMinValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[22003]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Arithmetic overflow' + '[SQL Server]Arithmetic overflow' ); $command->insert('tinyint', ['Mytinyint1' => -1])->execute(); diff --git a/tests/Type/UniqueidentifierTest.php b/tests/Type/UniqueidentifierTest.php index 75a025667..30b1aebb2 100644 --- a/tests/Type/UniqueidentifierTest.php +++ b/tests/Type/UniqueidentifierTest.php @@ -175,7 +175,7 @@ public function testValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - 'SQLSTATE[42000]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Conversion failed when converting from a character string to uniqueidentifier.' + '[SQL Server]Conversion failed when converting from a character string to uniqueidentifier.' ); $command = $db->createCommand(); diff --git a/tests/Type/VarCharTest.php b/tests/Type/VarCharTest.php index 1cad4910f..ff81fec8b 100644 --- a/tests/Type/VarCharTest.php +++ b/tests/Type/VarCharTest.php @@ -191,7 +191,7 @@ public function testValueException(): void $this->expectException(Exception::class); $this->expectExceptionMessage( - '[Microsoft][ODBC Driver 18 for SQL Server][SQL Server]String or binary data would be truncated' + '[SQL Server]String or binary data would be truncated' ); $command->insert('varchar', ['Myvarchar1' => '01234567891'])->execute(); From ea5cabe4ae5a4a30f70382762962e417dad77885 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sat, 12 Oct 2024 12:13:28 +0700 Subject: [PATCH 8/8] Improve --- src/Dsn.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Dsn.php b/src/Dsn.php index b519d101f..5050bc750 100644 --- a/src/Dsn.php +++ b/src/Dsn.php @@ -14,13 +14,13 @@ final class Dsn extends AbstractDsn { /** - * @param string[] $options + * @psalm-param array $options */ public function __construct( string $driver = 'sqlsrv', string $host = 'localhost', string|null $databaseName = null, - string $port = '1433', + string|null $port = '1433', array $options = [] ) { parent::__construct($driver, $host, $databaseName, $port, $options); @@ -60,7 +60,9 @@ public function asString(): string } if (!empty($options)) { - $dsn .= ';' . http_build_query($options, '', ';'); + foreach ($options as $key => $value) { + $dsn .= ";$key=$value"; + } } return $dsn;