Skip to content

Commit

Permalink
Refactor Dsn class (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov authored Oct 18, 2024
1 parent 7c4319e commit ccb8b73
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions src/Dsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
final class Dsn extends AbstractDsn
{
/**
* @psalm-param string[] $options
* @psalm-param array<string,string> $options
*/
public function __construct(
string $driver,
string $host,
string $driver = 'mysql',
string $host = '127.0.0.1',
string|null $databaseName = null,
string $port = '3306',
array $options = []
Expand Down
4 changes: 2 additions & 2 deletions tests/Support/TestTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ 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());
}

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;
Expand Down

0 comments on commit ccb8b73

Please sign in to comment.