|
9 | 9 |
|
10 | 10 | /** |
11 | 11 | * @group pgsql |
12 | | - * |
13 | | - * @psalm-suppress PropertyNotSetInConstructor |
14 | 12 | */ |
15 | 13 | final class DsnTest extends TestCase |
16 | 14 | { |
17 | | - public function testAsString(): void |
| 15 | + public function testConstruct(): void |
18 | 16 | { |
19 | | - $this->assertSame( |
20 | | - 'pgsql:host=localhost;dbname=yiitest;port=5432', |
21 | | - (new Dsn('pgsql', 'localhost', 'yiitest'))->asString(), |
22 | | - ); |
| 17 | + $dsn = new Dsn('pgsql', 'localhost', 'yiitest', '5433', ['sslmode' => 'disable']); |
| 18 | + |
| 19 | + $this->assertSame('pgsql', $dsn->driver); |
| 20 | + $this->assertSame('localhost', $dsn->host); |
| 21 | + $this->assertSame('yiitest', $dsn->databaseName); |
| 22 | + $this->assertSame('5433', $dsn->port); |
| 23 | + $this->assertSame(['sslmode' => 'disable'], $dsn->options); |
| 24 | + $this->assertSame('pgsql:host=localhost;dbname=yiitest;port=5433;sslmode=disable', (string) $dsn); |
23 | 25 | } |
24 | 26 |
|
25 | | - public function testAsStringWithDatabaseName(): void |
| 27 | + public function testConstructDefaults(): void |
26 | 28 | { |
27 | | - $this->assertSame( |
28 | | - 'pgsql:host=localhost;dbname=postgres;port=5432', |
29 | | - (new Dsn('pgsql', 'localhost'))->asString(), |
30 | | - ); |
| 29 | + $dsn = new Dsn(); |
| 30 | + |
| 31 | + $this->assertSame('pgsql', $dsn->driver); |
| 32 | + $this->assertSame('127.0.0.1', $dsn->host); |
| 33 | + $this->assertSame('postgres', $dsn->databaseName); |
| 34 | + $this->assertSame('5432', $dsn->port); |
| 35 | + $this->assertSame([], $dsn->options); |
| 36 | + $this->assertSame('pgsql:host=127.0.0.1;dbname=postgres;port=5432', (string) $dsn); |
31 | 37 | } |
32 | 38 |
|
33 | | - public function testAsStringWithDatabaseNameWithEmptyString(): void |
| 39 | + public function testConstructWithEmptyDatabase(): void |
34 | 40 | { |
35 | | - $this->assertSame( |
36 | | - 'pgsql:host=localhost;dbname=postgres;port=5432', |
37 | | - (new Dsn('pgsql', 'localhost', ''))->asString(), |
38 | | - ); |
| 41 | + $dsn = new Dsn(databaseName: ''); |
| 42 | + |
| 43 | + $this->assertSame('pgsql', $dsn->driver); |
| 44 | + $this->assertSame('127.0.0.1', $dsn->host); |
| 45 | + $this->assertSame('', $dsn->databaseName); |
| 46 | + $this->assertSame('5432', $dsn->port); |
| 47 | + $this->assertSame([], $dsn->options); |
| 48 | + $this->assertSame('pgsql:host=127.0.0.1;port=5432', (string) $dsn); |
39 | 49 | } |
40 | 50 |
|
41 | | - public function testAsStringWithDatabaseNameWithNull(): void |
| 51 | + public function testConstructWithEmptyPort(): void |
42 | 52 | { |
43 | | - $this->assertSame( |
44 | | - 'pgsql:host=localhost;dbname=postgres;port=5432', |
45 | | - (new Dsn('pgsql', 'localhost', null))->asString(), |
46 | | - ); |
47 | | - } |
48 | | - |
49 | | - public function testAsStringWithOptions(): void |
50 | | - { |
51 | | - $this->assertSame( |
52 | | - 'pgsql:host=localhost;dbname=yiitest;port=5433;charset=utf8', |
53 | | - (new Dsn('pgsql', 'localhost', 'yiitest', '5433', ['charset' => 'utf8']))->asString(), |
54 | | - ); |
55 | | - } |
56 | | - |
57 | | - public function testAsStringWithPort(): void |
58 | | - { |
59 | | - $this->assertSame( |
60 | | - 'pgsql:host=localhost;dbname=yiitest;port=5433', |
61 | | - (new Dsn('pgsql', 'localhost', 'yiitest', '5433'))->asString(), |
62 | | - ); |
| 53 | + $dsn = new Dsn(port: ''); |
| 54 | + |
| 55 | + $this->assertSame('pgsql', $dsn->driver); |
| 56 | + $this->assertSame('127.0.0.1', $dsn->host); |
| 57 | + $this->assertSame('postgres', $dsn->databaseName); |
| 58 | + $this->assertSame('', $dsn->port); |
| 59 | + $this->assertSame([], $dsn->options); |
| 60 | + $this->assertSame('pgsql:host=127.0.0.1;dbname=postgres', (string) $dsn); |
63 | 61 | } |
64 | 62 | } |
0 commit comments