From 47d2f6fa948e66a4569840a6af9be6bb394ea8c4 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 18 Oct 2024 09:49:10 +0700 Subject: [PATCH 1/3] Refactor `Dsn` class --- src/Dsn.php | 6 +++--- tests/DsnTest.php | 2 +- tests/Support/TestTrait.php | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Dsn.php b/src/Dsn.php index 77b92b021..a22e52f3d 100644 --- a/src/Dsn.php +++ b/src/Dsn.php @@ -14,11 +14,11 @@ final class Dsn extends AbstractDsn { /** - * @psalm-param string[] $options + * @psalm-param array $options */ public function __construct( - string $driver, - string $host, + string $driver = 'mysql', + string $host = 'localhost', string|null $databaseName = null, string $port = '3306', array $options = [] diff --git a/tests/DsnTest.php b/tests/DsnTest.php index 052094d87..fe1e7153a 100644 --- a/tests/DsnTest.php +++ b/tests/DsnTest.php @@ -18,7 +18,7 @@ public function testAsString(): void { $this->assertSame( 'mysql:host=localhost;dbname=yiitest;port=3306', - (new Dsn('mysql', 'localhost', 'yiitest'))->asString(), + (new Dsn(databaseName: 'yiitest'))->asString(), ); } diff --git a/tests/Support/TestTrait.php b/tests/Support/TestTrait.php index 483b57f0d..6bb30459a 100644 --- a/tests/Support/TestTrait.php +++ b/tests/Support/TestTrait.php @@ -27,7 +27,7 @@ protected function getConnection(bool $fixture = false): PdoConnectionInterface protected static function getDb(): PdoConnectionInterface { - $dsn = (new Dsn('mysql', '127.0.0.1', 'yiitest', '3306', ['charset' => 'utf8mb4']))->asString(); + $dsn = (new Dsn(databaseName: 'yiitest', options: ['charset' => 'utf8mb4']))->asString(); return new Connection(new Driver($dsn, 'root', ''), DbHelper::getSchemaCache()); } @@ -35,7 +35,7 @@ protected static function getDb(): PdoConnectionInterface protected function getDsn(): string { if ($this->dsn === '') { - $this->dsn = (new Dsn('mysql', '127.0.0.1', 'yiitest', '3306', ['charset' => 'utf8mb4']))->asString(); + $this->dsn = (new Dsn(databaseName: 'yiitest', options: ['charset' => 'utf8mb4']))->asString(); } return $this->dsn; From 5565dc09dbc016b2654d162a28ced3b37568ba9f Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 18 Oct 2024 10:16:22 +0700 Subject: [PATCH 2/3] Change `localhost` to `127.0.0.1` --- src/Dsn.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Dsn.php b/src/Dsn.php index a22e52f3d..263f3fff7 100644 --- a/src/Dsn.php +++ b/src/Dsn.php @@ -18,7 +18,7 @@ final class Dsn extends AbstractDsn */ public function __construct( string $driver = 'mysql', - string $host = 'localhost', + string $host = '127.0.0.1', string|null $databaseName = null, string $port = '3306', array $options = [] From 113a80511106eb7e7fe492f719e0ebfabb2b7721 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 18 Oct 2024 10:21:38 +0700 Subject: [PATCH 3/3] Fix test, add changelog --- CHANGELOG.md | 3 ++- tests/DsnTest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 13e2edc9a..d1e20be6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,8 @@ - Enh #354: Separate column type constants (@Tigrov) - New #355: Realize `ColumnBuilder` class (@Tigrov) - Enh #357: Update according changes in `ColumnSchemaInterface` (@Tigrov) -- New #358: Add `ColumnDefinitionBuilder` class (@Tigrov) +- New #358: Add `ColumnDefinitionBuilder` class (@Tigrov) +- Enh #359: Refactor `Dsn` class (@Tigrov) ## 1.2.0 March 21, 2024 diff --git a/tests/DsnTest.php b/tests/DsnTest.php index fe1e7153a..052094d87 100644 --- a/tests/DsnTest.php +++ b/tests/DsnTest.php @@ -18,7 +18,7 @@ public function testAsString(): void { $this->assertSame( 'mysql:host=localhost;dbname=yiitest;port=3306', - (new Dsn(databaseName: 'yiitest'))->asString(), + (new Dsn('mysql', 'localhost', 'yiitest'))->asString(), ); }