1
|
|
|
<?php |
2
|
|
|
namespace Mezon\PdoCrud\Tests; |
3
|
|
|
|
4
|
|
|
use Mezon\Conf\Conf; |
5
|
|
|
use Mezon\PdoCrud\PdoCrud; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
class ConnectionTraitTests extends TestCase |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Method returns mock |
13
|
|
|
* |
14
|
|
|
* @return object mock |
15
|
|
|
*/ |
16
|
|
|
protected function getPdoMock(): object |
17
|
|
|
{ |
18
|
|
|
return $this->getMockBuilder(PdoCrud::class) |
|
|
|
|
19
|
|
|
->setMethods([ |
20
|
|
|
'connect' |
21
|
|
|
]) |
22
|
|
|
->getMock(); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Method returns mock |
27
|
|
|
* |
28
|
|
|
* @return object mock |
29
|
|
|
*/ |
30
|
|
|
protected function getMock(): object |
31
|
|
|
{ |
32
|
|
|
return $this->getMockBuilder(TraitClient::class) |
|
|
|
|
33
|
|
|
->setMethods([ |
34
|
|
|
'constructConnection' |
35
|
|
|
]) |
36
|
|
|
->getMock(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Method returns mock |
41
|
|
|
* |
42
|
|
|
* @return object mock |
43
|
|
|
*/ |
44
|
|
|
protected function getMockBase(): object |
45
|
|
|
{ |
46
|
|
|
return $this->getMockBuilder(TraitClientBase::class) |
|
|
|
|
47
|
|
|
->setMethods([ |
48
|
|
|
'constructConnection' |
49
|
|
|
]) |
50
|
|
|
->getMock(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Method sets dsn |
55
|
|
|
* |
56
|
|
|
* @param string $dsn |
57
|
|
|
* dsn |
58
|
|
|
* @param string $connectionName |
59
|
|
|
* connection name |
60
|
|
|
*/ |
61
|
|
|
protected function setDsn(string $dsn, string $connectionName = 'default-db-connection'): void |
62
|
|
|
{ |
63
|
|
|
Conf::setConfigValue($connectionName . '/dsn', $dsn); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Method sets user |
68
|
|
|
* |
69
|
|
|
* @param string $user |
70
|
|
|
* user |
71
|
|
|
* @param string $connectionName |
72
|
|
|
* connection name |
73
|
|
|
*/ |
74
|
|
|
protected function setUser(string $user, string $connectionName = 'default-db-connection'): void |
75
|
|
|
{ |
76
|
|
|
Conf::setConfigValue($connectionName . '/user', $user); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* Method sets password |
81
|
|
|
* |
82
|
|
|
* @param string $password |
83
|
|
|
* password |
84
|
|
|
* @param string $connectionName |
85
|
|
|
* connection name |
86
|
|
|
*/ |
87
|
|
|
protected function setPassword(string $password, string $connectionName = 'default-db-connection'): void |
88
|
|
|
{ |
89
|
|
|
Conf::setConfigValue($connectionName . '/password', $password); |
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Setting connection |
94
|
|
|
* |
95
|
|
|
* @param string $connectionName |
96
|
|
|
* connection name |
97
|
|
|
*/ |
98
|
|
|
protected function setConnection(string $connectionName = 'default-db-connection'): void |
99
|
|
|
{ |
100
|
|
|
$this->setDsn('dsn', $connectionName); |
101
|
|
|
$this->setUser('user', $connectionName); |
102
|
|
|
$this->setPassword('password', $connectionName); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.