Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Dsn class #359

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading