1
|
|
|
<?php declare( strict_types = 1 ); |
2
|
|
|
|
3
|
|
|
namespace Coco\SourceWatcher\Tests\Core\Database\Connections; |
4
|
|
|
|
5
|
|
|
use Coco\SourceWatcher\Core\Database\Connections\PostgreSqlConnector; |
6
|
|
|
use Coco\SourceWatcher\Core\SourceWatcherException; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class PostgreSqlConnectorTest |
11
|
|
|
* @package Coco\SourceWatcher\Tests\Core\Database\Connections |
12
|
|
|
*/ |
13
|
|
|
class PostgreSqlConnectorTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* |
17
|
|
|
*/ |
18
|
|
|
public function testSetGetCharset () : void |
19
|
|
|
{ |
20
|
|
|
$connector = new PostgreSqlConnector(); |
21
|
|
|
|
22
|
|
|
$givenCharset = "utf8"; |
23
|
|
|
$expectedCharset = "utf8"; |
24
|
|
|
|
25
|
|
|
$connector->setCharset( $givenCharset ); |
26
|
|
|
|
27
|
|
|
$this->assertEquals( $expectedCharset, $connector->getCharset() ); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* |
32
|
|
|
*/ |
33
|
|
|
public function testSetGetDefaultDatabaseName () : void |
34
|
|
|
{ |
35
|
|
|
$connector = new PostgreSqlConnector(); |
36
|
|
|
|
37
|
|
|
$givenDefaultDatabaseName = "people"; |
38
|
|
|
$expectedDefaultDatabaseName = "people"; |
39
|
|
|
|
40
|
|
|
$connector->setDefaultDatabaseName( $givenDefaultDatabaseName ); |
41
|
|
|
|
42
|
|
|
$this->assertEquals( $expectedDefaultDatabaseName, $connector->getDefaultDatabaseName() ); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* |
47
|
|
|
*/ |
48
|
|
|
public function testSetGetSslMode () : void |
49
|
|
|
{ |
50
|
|
|
$connector = new PostgreSqlConnector(); |
51
|
|
|
|
52
|
|
|
$givenSslMode = "allow"; |
53
|
|
|
$expectedSslMode = "allow"; |
54
|
|
|
|
55
|
|
|
$connector->setSslMode( $givenSslMode ); |
56
|
|
|
|
57
|
|
|
$this->assertEquals( $expectedSslMode, $connector->getSslMode() ); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* |
62
|
|
|
*/ |
63
|
|
|
public function testSetGetSslRootCert () : void |
64
|
|
|
{ |
65
|
|
|
$connector = new PostgreSqlConnector(); |
66
|
|
|
|
67
|
|
|
$givenSslRootCert = "~/.postgresql/root.crt"; |
68
|
|
|
$expectedSslRootCert = "~/.postgresql/root.crt"; |
69
|
|
|
|
70
|
|
|
$connector->setSslRootCert( $givenSslRootCert ); |
71
|
|
|
|
72
|
|
|
$this->assertEquals( $expectedSslRootCert, $connector->getSslRootCert() ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* |
77
|
|
|
*/ |
78
|
|
|
public function testSetGetSslCert () : void |
79
|
|
|
{ |
80
|
|
|
$connector = new PostgreSqlConnector(); |
81
|
|
|
|
82
|
|
|
$givenSslCert = "~/.postgresql/postgresql.crt"; |
83
|
|
|
$expectedSslCert = "~/.postgresql/postgresql.crt"; |
84
|
|
|
|
85
|
|
|
$connector->setSslCert( $givenSslCert ); |
86
|
|
|
|
87
|
|
|
$this->assertEquals( $expectedSslCert, $connector->getSslCert() ); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* |
92
|
|
|
*/ |
93
|
|
|
public function testSetGetSslKey () : void |
94
|
|
|
{ |
95
|
|
|
$connector = new PostgreSqlConnector(); |
96
|
|
|
|
97
|
|
|
$givenSslKey = "~/.postgresql/postgresql.key"; |
98
|
|
|
$expectedSslKey = "~/.postgresql/postgresql.key"; |
99
|
|
|
|
100
|
|
|
$connector->setSslKey( $givenSslKey ); |
101
|
|
|
|
102
|
|
|
$this->assertEquals( $expectedSslKey, $connector->getSslKey() ); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* |
107
|
|
|
*/ |
108
|
|
|
public function testSetGetSslCrl () : void |
109
|
|
|
{ |
110
|
|
|
$connector = new PostgreSqlConnector(); |
111
|
|
|
|
112
|
|
|
$givenSslCrl = "~/.postgresql/root.crl"; |
113
|
|
|
$expectedSslCrl = "~/.postgresql/root.crl"; |
114
|
|
|
|
115
|
|
|
$connector->setSslCrl( $givenSslCrl ); |
116
|
|
|
|
117
|
|
|
$this->assertEquals( $expectedSslCrl, $connector->getSslCrl() ); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* |
122
|
|
|
*/ |
123
|
|
|
public function testSetGetApplicationName () : void |
124
|
|
|
{ |
125
|
|
|
$connector = new PostgreSqlConnector(); |
126
|
|
|
|
127
|
|
|
$givenAppName = "App Name for PG Stat Activity"; |
128
|
|
|
$expectedAppName = "App Name for PG Stat Activity"; |
129
|
|
|
|
130
|
|
|
$connector->setApplicationName( $givenAppName ); |
131
|
|
|
|
132
|
|
|
$this->assertEquals( $expectedAppName, $connector->getApplicationName() ); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @throws SourceWatcherException |
137
|
|
|
*/ |
138
|
|
|
public function testGetConnection () : void |
139
|
|
|
{ |
140
|
|
|
$connector = new PostgreSqlConnector(); |
141
|
|
|
$connector->setUser( "admin" ); |
142
|
|
|
$connector->setPassword( "secret" ); |
143
|
|
|
$connector->setHost( "localhost" ); |
144
|
|
|
$connector->setPort( 5432 );; |
145
|
|
|
$connector->setDbName( "people" ); |
146
|
|
|
$connector->setCharset( "utf8" ); |
147
|
|
|
$connector->setDefaultDatabaseName( "people" ); |
148
|
|
|
$connector->setSslMode( "allow" ); |
149
|
|
|
$connector->setSslRootCert( "~/.postgresql/root.crt" ); |
150
|
|
|
$connector->setSslCert( "~/.postgresql/postgresql.crt" ); |
151
|
|
|
$connector->setSslKey( "~/.postgresql/postgresql.key" ); |
152
|
|
|
$connector->setSslCrl( "~/.postgresql/root.crl" ); |
153
|
|
|
$connector->setApplicationName( "App Name for PG Stat Activity" ); |
154
|
|
|
|
155
|
|
|
$this->assertNotNull( $connector->connect() ); |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|