ConnectionConfigUrlTest::testConstruct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 20
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 27
rs 9.6
1
<?php declare(strict_types=1);
2
3
namespace Janisbiz\LightOrm\Tests\Unit\Dms\MySQL\Connection;
4
5
use Janisbiz\LightOrm\Dms\MySQL\Connection\ConnectionConfigUrl;
6
use PHPUnit\Framework\TestCase;
7
8
class ConnectionConfigUrlTest extends TestCase
9
{
10
    const URL_PART_SCHEME = 'mysql';
11
    const URL_PART_USER = 'user';
12
    const URL_PART_PASS = 'password';
13
    const URL_PART_HOST = 'host';
14
    const URL_PART_PORT = 1234;
15
    const URL_PART_PATH = 'database_name';
16
17
    public function testConstruct()
18
    {
19
        $connectionConfigUrl = new ConnectionConfigUrl(
20
            \sprintf(
21
                '%s://%s:%s@%s:%d/%s',
22
                static::URL_PART_SCHEME,
23
                static::URL_PART_USER,
24
                static::URL_PART_PASS,
25
                static::URL_PART_HOST,
26
                static::URL_PART_PORT,
27
                static::URL_PART_PATH
28
            )
29
        );
30
31
        $this->assertEquals(
32
            \sprintf(
33
                '%s:host=%s;dbname=%s;charset=utf8mb4;port=%d',
34
                static::URL_PART_SCHEME,
35
                static::URL_PART_HOST,
36
                static::URL_PART_PATH,
37
                static::URL_PART_PORT
38
            ),
39
            $connectionConfigUrl->generateDsn()
40
        );
41
        $this->assertEquals(static::URL_PART_USER, $connectionConfigUrl->getUsername());
42
        $this->assertEquals(static::URL_PART_PASS, $connectionConfigUrl->getPassword());
43
        $this->assertEquals(static::URL_PART_PATH, $connectionConfigUrl->getDbname());
44
    }
45
}
46