1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Janisbiz\LightOrm\Tests\Unit\Dms\MySQL\Connection; |
4
|
|
|
|
5
|
|
|
use Janisbiz\LightOrm\Dms\MySQL\Connection\Connection; |
6
|
|
|
use Janisbiz\LightOrm\Dms\MySQL\Connection\ConnectionConfig; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
class ConnectionConfigTest extends TestCase |
10
|
|
|
{ |
11
|
|
|
const CONFIG_HOST = 'host'; |
12
|
|
|
const CONFIG_USERNAME = 'username'; |
13
|
|
|
const CONFIG_PASSWORD = 'password'; |
14
|
|
|
const CONFIG_DBNAME = 'dbname'; |
15
|
|
|
const CONFIG_ADAPTER = ConnectionConfig::ADAPTER; |
16
|
|
|
const CONFIG_ADAPTER_INVALID = 'adapter_invalid'; |
17
|
|
|
const CONFIG_PORT = 1234; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @var ConnectionConfig |
21
|
|
|
*/ |
22
|
|
|
private $connectionConfig; |
23
|
|
|
|
24
|
|
|
public function setUp() |
25
|
|
|
{ |
26
|
|
|
$this->connectionConfig = new ConnectionConfig( |
27
|
|
|
static::CONFIG_HOST, |
28
|
|
|
static::CONFIG_USERNAME, |
29
|
|
|
static::CONFIG_PASSWORD, |
30
|
|
|
static::CONFIG_DBNAME, |
31
|
|
|
static::CONFIG_PORT |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGenerateDsn() |
36
|
|
|
{ |
37
|
|
|
$this->assertEquals( |
38
|
|
|
\sprintf( |
39
|
|
|
'%s:host=%s;dbname=%s;charset=utf8mb4;port=%d', |
40
|
|
|
static::CONFIG_ADAPTER, |
41
|
|
|
static::CONFIG_HOST, |
42
|
|
|
static::CONFIG_DBNAME, |
43
|
|
|
static::CONFIG_PORT |
44
|
|
|
), |
45
|
|
|
$this->connectionConfig->generateDsn() |
46
|
|
|
); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testGetUsername() |
50
|
|
|
{ |
51
|
|
|
$this->assertEquals(static::CONFIG_USERNAME, $this->connectionConfig->getUsername()); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testGetPassword() |
55
|
|
|
{ |
56
|
|
|
$this->assertEquals(static::CONFIG_PASSWORD, $this->connectionConfig->getPassword()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function testGetDbname() |
60
|
|
|
{ |
61
|
|
|
$this->assertEquals(static::CONFIG_DBNAME, $this->connectionConfig->getDbname()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testGetAdapterConnectionClass() |
65
|
|
|
{ |
66
|
|
|
$this->assertEquals(Connection::class, $this->connectionConfig->getAdapterConnectionClass()); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|