Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improvements Dsn::class, fix phpdoc, add more tests. (#199)
* Improvements Dsn::class, fix phpdoc, add more tests.
- Loading branch information
1 parent
0eb9be0
commit 40428ee
Showing
3 changed files
with
83 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Pgsql; | ||
|
||
use Yiisoft\Db\Connection\AbstractDsn; | ||
|
||
/** | ||
* The Dsn class is typically used to parse a DSN string, which is a string that contains all the necessary information | ||
* to connect to a database SQL Server, such as the database driver, host, database name, port, options. | ||
* | ||
* It also allows you to access individual components of the DSN, such as the driver, host, database name or port. | ||
* | ||
* @link https://www.php.net/manual/en/ref.pdo-pgsql.connection.php | ||
*/ | ||
final class Dsn extends AbstractDsn | ||
{ | ||
/** | ||
* @psalm-param string[] $options | ||
*/ | ||
public function __construct( | ||
private string $driver, | ||
private string $host, | ||
private string $databaseName, | ||
private string $port = '5432', | ||
private array $options = [] | ||
) { | ||
parent::__construct($driver, $host, $databaseName, $port, $options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Pgsql\Tests; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Yiisoft\Db\Pgsql\Dsn; | ||
|
||
/** | ||
* @group pgsql | ||
* | ||
* @psalm-suppress PropertyNotSetInConstructor | ||
*/ | ||
final class DsnTest extends TestCase | ||
{ | ||
public function testAsString(): void | ||
{ | ||
$this->assertSame( | ||
'pgsql:host=localhost;dbname=yiitest;port=5432', | ||
(new Dsn('pgsql', 'localhost', 'yiitest'))->asString(), | ||
); | ||
} | ||
|
||
public function testAsStringWithOptions(): void | ||
{ | ||
$this->assertSame( | ||
'pgsql:host=localhost;dbname=yiitest;port=5433;charset=utf8', | ||
(new Dsn('pgsql', 'localhost', 'yiitest', '5433', ['charset' => 'utf8']))->asString(), | ||
); | ||
} | ||
|
||
public function testAsStringWithPort(): void | ||
{ | ||
$this->assertSame( | ||
'pgsql:host=localhost;dbname=yiitest;port=5433', | ||
(new Dsn('pgsql', 'localhost', 'yiitest', '5433'))->asString(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters