|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Tests\Connection; |
|
6
|
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
|
8
|
|
|
use Yiisoft\Db\Connection\Dsn; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* @group db |
|
12
|
|
|
*/ |
|
13
|
|
|
final class DsnTest extends TestCase |
|
14
|
|
|
{ |
|
15
|
|
|
public function testGetDatabaseName(): void |
|
16
|
|
|
{ |
|
17
|
|
|
$dsn = new Dsn('mysql', 'localhost', 'yiitest', '3306', ['charset' => 'utf8']); |
|
18
|
|
|
$this->assertSame('yiitest', $dsn->getDatabaseName()); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function testGetDriver(): void |
|
22
|
|
|
{ |
|
23
|
|
|
$dsn = new Dsn('mysql', 'localhost', 'yiitest', '3306', ['charset' => 'utf8']); |
|
24
|
|
|
$this->assertSame('mysql', $dsn->getDriver()); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
public function testGetDsn(): void |
|
28
|
|
|
{ |
|
29
|
|
|
$dsn = new Dsn('mysql', 'localhost', 'yiitest', '3306', ['charset' => 'utf8']); |
|
30
|
|
|
$this->assertSame('mysql:host=localhost;dbname=yiitest;port=3306;charset=utf8', $dsn->asString()); |
|
31
|
|
|
$this->assertSame('mysql:host=localhost;dbname=yiitest;port=3306;charset=utf8', $dsn->__toString()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testGetHost(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$dsn = new Dsn('mysql', 'localhost', 'yiitest', '3306', ['charset' => 'utf8']); |
|
37
|
|
|
$this->assertSame('localhost', $dsn->getHost()); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testGetPort(): void |
|
41
|
|
|
{ |
|
42
|
|
|
$dsn = new Dsn('mysql', 'localhost', 'yiitest', '3306', ['charset' => 'utf8']); |
|
43
|
|
|
$this->assertSame('3306', $dsn->getPort()); |
|
44
|
|
|
} |
|
45
|
|
|
} |
|
46
|
|
|
|