3
3
namespace Nemo64 \DbalRdsData \Tests ;
4
4
5
5
6
- use Aws \RDSDataService \RDSDataServiceClient ;
7
- use Aws \Result ;
8
6
use Doctrine \DBAL \FetchMode ;
9
- use Nemo64 \DbalRdsData \RdsDataConnection ;
10
7
use PHPUnit \Framework \TestCase ;
11
8
12
9
class RdsDataConnectionTest extends TestCase
13
10
{
14
- private const DEFAULT_OPTIONS = [
15
- 'resourceArn ' => 'resource_arm ' ,
16
- 'secretArn ' => 'secret_arm ' ,
17
- ];
18
-
19
- /**
20
- * @var \PHPUnit\Framework\MockObject\MockObject|RDSDataServiceClient
21
- */
22
- private $ client ;
23
-
24
- private $ expectedCalls = [
25
- // ['executeStatement', ['options' => 'value'], 'returnValue']
26
- ];
27
-
28
- /**
29
- * @var RdsDataConnection
30
- */
31
- private $ connection ;
11
+ use RdsDataServiceClientTrait;
32
12
33
13
protected function setUp ()
34
14
{
35
- $ this ->client = $ this ->createMock (RDSDataServiceClient::class);
36
- $ this ->client ->method ('__call ' )->willReturnCallback (function ($ methodName , $ arguments ) {
37
- $ nextCall = array_shift ($ this ->expectedCalls );
38
- $ this ->assertIsArray ($ nextCall , "there must be another call planned " );
39
- $ this ->assertEquals ($ nextCall [0 ], $ methodName , "method call " );
40
- $ this ->assertEquals ($ nextCall [1 ], $ arguments [0 ], "options of $ methodName " );
41
- return $ nextCall [2 ];
42
- });
43
-
44
- $ this ->connection = new RdsDataConnection (
45
- $ this ->client ,
46
- self ::DEFAULT_OPTIONS ['resourceArn ' ],
47
- self ::DEFAULT_OPTIONS ['secretArn ' ],
48
- 'db '
49
- );
50
- }
51
-
52
- private function addClientCall (string $ method , array $ options , array $ result )
53
- {
54
- $ this ->expectedCalls [] = [$ method , $ options , new Result ($ result )];
15
+ $ this ->createRdsDataServiceClient ();
55
16
}
56
17
57
18
public function testSimpleQuery ()
58
19
{
59
20
$ this ->addClientCall (
60
21
'executeStatement ' ,
61
- self ::DEFAULT_OPTIONS + [
22
+ [
23
+ 'resourceArn ' => 'arn:resource ' ,
24
+ 'secretArn ' => 'arn:secret ' ,
62
25
'database ' => 'db ' ,
63
26
'continueAfterTimeout ' => false ,
64
27
'includeResultMetadata ' => true ,
@@ -88,15 +51,21 @@ public function testTransaction()
88
51
{
89
52
$ this ->addClientCall (
90
53
'beginTransaction ' ,
91
- self ::DEFAULT_OPTIONS + ['database ' => 'db ' ],
54
+ [
55
+ 'resourceArn ' => 'arn:resource ' ,
56
+ 'secretArn ' => 'arn:secret ' ,
57
+ 'database ' => 'db ' ,
58
+ ],
92
59
['transactionId ' => '~~transaction id~~ ' ]
93
60
);
94
61
$ this ->assertTrue ($ this ->connection ->beginTransaction ());
95
62
$ this ->assertEquals ('~~transaction id~~ ' , $ this ->connection ->getTransactionId ());
96
63
97
64
$ this ->addClientCall (
98
65
'executeStatement ' ,
99
- self ::DEFAULT_OPTIONS + [
66
+ [
67
+ 'resourceArn ' => 'arn:resource ' ,
68
+ 'secretArn ' => 'arn:secret ' ,
100
69
'database ' => 'db ' ,
101
70
'continueAfterTimeout ' => false ,
102
71
'includeResultMetadata ' => true ,
@@ -125,7 +94,11 @@ public function testTransaction()
125
94
126
95
$ this ->addClientCall (
127
96
'commitTransaction ' ,
128
- self ::DEFAULT_OPTIONS + ['transactionId ' => '~~transaction id~~ ' ],
97
+ [
98
+ 'resourceArn ' => 'arn:resource ' ,
99
+ 'secretArn ' => 'arn:secret ' ,
100
+ 'transactionId ' => '~~transaction id~~ ' ,
101
+ ],
129
102
['transactionStatus ' => 'cleaning up ' ]
130
103
);
131
104
$ this ->assertTrue ($ this ->connection ->commit ());
@@ -137,7 +110,11 @@ public function testRollBack()
137
110
{
138
111
$ this ->addClientCall (
139
112
'beginTransaction ' ,
140
- self ::DEFAULT_OPTIONS + ['database ' => 'db ' ],
113
+ [
114
+ 'resourceArn ' => 'arn:resource ' ,
115
+ 'secretArn ' => 'arn:secret ' ,
116
+ 'database ' => 'db ' ,
117
+ ],
141
118
['transactionId ' => '~~transaction id~~ ' ]
142
119
);
143
120
$ this ->assertTrue ($ this ->connection ->beginTransaction ());
@@ -146,7 +123,11 @@ public function testRollBack()
146
123
147
124
$ this ->addClientCall (
148
125
'rollbackTransaction ' ,
149
- self ::DEFAULT_OPTIONS + ['transactionId ' => '~~transaction id~~ ' ],
126
+ [
127
+ 'resourceArn ' => 'arn:resource ' ,
128
+ 'secretArn ' => 'arn:secret ' ,
129
+ 'transactionId ' => '~~transaction id~~ ' ,
130
+ ],
150
131
['transactionStatus ' => 'cleaning up ' ]
151
132
);
152
133
$ this ->assertTrue ($ this ->connection ->rollBack ());
@@ -158,7 +139,9 @@ public function testUpdate()
158
139
{
159
140
$ this ->addClientCall (
160
141
'executeStatement ' ,
161
- self ::DEFAULT_OPTIONS + [
142
+ [
143
+ 'resourceArn ' => 'arn:resource ' ,
144
+ 'secretArn ' => 'arn:secret ' ,
162
145
'database ' => 'db ' ,
163
146
'continueAfterTimeout ' => false ,
164
147
'includeResultMetadata ' => true ,
@@ -179,7 +162,9 @@ public function testParameters()
179
162
{
180
163
$ this ->addClientCall (
181
164
'executeStatement ' ,
182
- self ::DEFAULT_OPTIONS + [
165
+ [
166
+ 'resourceArn ' => 'arn:resource ' ,
167
+ 'secretArn ' => 'arn:secret ' ,
183
168
'database ' => 'db ' ,
184
169
'continueAfterTimeout ' => false ,
185
170
'includeResultMetadata ' => true ,
@@ -222,7 +207,9 @@ public function testInsert()
222
207
223
208
$ this ->addClientCall (
224
209
'executeStatement ' ,
225
- self ::DEFAULT_OPTIONS + [
210
+ [
211
+ 'resourceArn ' => 'arn:resource ' ,
212
+ 'secretArn ' => 'arn:secret ' ,
226
213
'database ' => 'db ' ,
227
214
'continueAfterTimeout ' => false ,
228
215
'includeResultMetadata ' => true ,
0 commit comments