1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace SlayerBirden\DFCodeGeneration\Generator\Config; |
5
|
|
|
|
6
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Prophecy\Argument; |
9
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
10
|
|
|
use SlayerBirden\DFCodeGeneration\CodeLoader; |
11
|
|
|
use SlayerBirden\DFCodeGeneration\PrintFileTrait; |
12
|
|
|
|
13
|
|
|
class GetTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
use PrintFileTrait; |
16
|
|
|
/** |
17
|
|
|
* @var ObjectProphecy |
18
|
|
|
*/ |
19
|
|
|
private $provider; |
20
|
|
|
|
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->provider = $this->prophesize(DataProviderInterface::class); |
24
|
|
|
$this->provider->getRouteFactoryName()->willReturn('Routes'); |
25
|
|
|
$this->provider->getInputFilterSpec()->willReturn([ |
26
|
|
|
'bar' => [ |
27
|
|
|
'required' => true, |
28
|
|
|
], |
29
|
|
|
'baz' => [ |
30
|
|
|
'required' => true, |
31
|
|
|
], |
32
|
|
|
]); |
33
|
|
|
$this->provider->getInputFilterName()->willReturn('DummyInputFilter'); |
34
|
|
|
$this->provider->getEntitiesSrc()->willReturn('src/Dummy/Entities'); |
35
|
|
|
$this->provider->getCurrentConfig()->willReturn([]); |
36
|
|
|
$this->provider->getControllerName(Argument::type('string'))->will(function ($args) { |
37
|
|
|
return ucwords($args[0]) . 'DummyAction'; |
38
|
|
|
}); |
39
|
|
|
$this->provider->getConfigNameSpace()->willReturn('A\B'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function testNewConfig() |
43
|
|
|
{ |
44
|
|
|
$configGenerator = new Config($this->provider->reveal()); |
45
|
|
|
$value = $configGenerator->generate(); |
46
|
|
|
|
47
|
|
|
try { |
48
|
|
|
CodeLoader::loadCode($value, 'dummyProvider.php'); |
49
|
|
|
$class = $configGenerator->getClassName(); |
50
|
|
|
$config = new $class(); |
51
|
|
|
$actual = call_user_func($config); |
|
|
|
|
52
|
|
|
} catch (\ParseError $exception) { |
53
|
|
|
echo 'File', PHP_EOL, $this->getPrintableFile($value), PHP_EOL; |
54
|
|
|
throw $exception; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$expected = [ |
58
|
|
|
'\\Zend\\ServiceManager\\AbstractFactory\\ConfigAbstractFactory' => [ |
59
|
|
|
'AddDummyAction' => [ |
60
|
|
|
EntityManagerInterface::class, |
61
|
|
|
'\\Zend\\Hydrator\\ClassMethods', |
62
|
|
|
'DummyInputFilter', |
63
|
|
|
'\\Psr\\Log\\LoggerInterface', |
64
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
65
|
|
|
], |
66
|
|
|
'UpdateDummyAction' => [ |
67
|
|
|
EntityManagerInterface::class, |
68
|
|
|
'\\Zend\\Hydrator\\ClassMethods', |
69
|
|
|
'DummyInputFilter', |
70
|
|
|
'\\Psr\\Log\\LoggerInterface', |
71
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
72
|
|
|
], |
73
|
|
|
'GetDummyAction' => [ |
74
|
|
|
EntityManagerInterface::class, |
75
|
|
|
'\\Psr\\Log\\LoggerInterface', |
76
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
77
|
|
|
], |
78
|
|
|
'GetsDummyAction' => [ |
79
|
|
|
EntityManagerInterface::class, |
80
|
|
|
'\\Psr\\Log\\LoggerInterface', |
81
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
82
|
|
|
], |
83
|
|
|
'DeleteDummyAction' => [ |
84
|
|
|
EntityManagerInterface::class, |
85
|
|
|
'\\Psr\\Log\\LoggerInterface', |
86
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
87
|
|
|
], |
88
|
|
|
], |
89
|
|
|
'dependencies' => [ |
90
|
|
|
'delegators' => [ |
91
|
|
|
'\\Zend\\Expressive\\Application' => [ |
92
|
|
|
'Routes', |
93
|
|
|
], |
94
|
|
|
], |
95
|
|
|
], |
96
|
|
|
'doctrine' => [ |
97
|
|
|
'paths' => [ |
98
|
|
|
'src/Dummy/Entities' |
99
|
|
|
], |
100
|
|
|
], |
101
|
|
|
'input_filter_specs' => [ |
102
|
|
|
'DummyInputFilter' => [ |
103
|
|
|
'bar' => [ |
104
|
|
|
'required' => true, |
105
|
|
|
], |
106
|
|
|
'baz' => [ |
107
|
|
|
'required' => true, |
108
|
|
|
], |
109
|
|
|
], |
110
|
|
|
], |
111
|
|
|
]; |
112
|
|
|
|
113
|
|
|
$this->assertEquals($expected, $actual); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function testExistingConfig() |
117
|
|
|
{ |
118
|
|
|
$this->provider->getCurrentConfig()->willReturn([ |
119
|
|
|
'\\Zend\\ServiceManager\\AbstractFactory\\ConfigAbstractFactory' => [ |
120
|
|
|
'AddSuperAction' => [ |
121
|
|
|
EntityManagerInterface::class, |
122
|
|
|
'\\Zend\\Hydrator\\ClassMethods', |
123
|
|
|
'SuperInputFilter', |
124
|
|
|
'\\Psr\\Log\\LoggerInterface', |
125
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
126
|
|
|
], |
127
|
|
|
'UpdateSuperAction' => [ |
128
|
|
|
EntityManagerInterface::class, |
129
|
|
|
'\\Zend\\Hydrator\\ClassMethods', |
130
|
|
|
'SuperInputFilter', |
131
|
|
|
'\\Psr\\Log\\LoggerInterface', |
132
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
133
|
|
|
], |
134
|
|
|
'GetSuperAction' => [ |
135
|
|
|
EntityManagerInterface::class, |
136
|
|
|
'\\Psr\\Log\\LoggerInterface', |
137
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
138
|
|
|
], |
139
|
|
|
'GetsSuperAction' => [ |
140
|
|
|
EntityManagerInterface::class, |
141
|
|
|
'\\Psr\\Log\\LoggerInterface', |
142
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
143
|
|
|
], |
144
|
|
|
'DeleteSuperAction' => [ |
145
|
|
|
EntityManagerInterface::class, |
146
|
|
|
'\\Psr\\Log\\LoggerInterface', |
147
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
148
|
|
|
], |
149
|
|
|
], |
150
|
|
|
'dependencies' => [ |
151
|
|
|
'delegators' => [ |
152
|
|
|
'\\Zend\\Expressive\\Application' => [ |
153
|
|
|
'Routes', |
154
|
|
|
], |
155
|
|
|
], |
156
|
|
|
], |
157
|
|
|
'doctrine' => [ |
158
|
|
|
'paths' => [ |
159
|
|
|
'src/Dummy/Entities' |
160
|
|
|
], |
161
|
|
|
], |
162
|
|
|
'input_filter_specs' => [ |
163
|
|
|
'SuperInputFilter' => [ |
164
|
|
|
'bar' => [ |
165
|
|
|
'required' => true, |
166
|
|
|
], |
167
|
|
|
'baz' => [ |
168
|
|
|
'required' => true, |
169
|
|
|
], |
170
|
|
|
], |
171
|
|
|
], |
172
|
|
|
]); |
173
|
|
|
$this->provider->getConfigNameSpace()->willReturn('A\C'); |
174
|
|
|
|
175
|
|
|
$configGenerator = new Config($this->provider->reveal()); |
176
|
|
|
$value = $configGenerator->generate(); |
177
|
|
|
|
178
|
|
|
try { |
179
|
|
|
CodeLoader::loadCode($value, 'dummyProvider.php'); |
180
|
|
|
$class = $configGenerator->getClassName(); |
181
|
|
|
$config = new $class(); |
182
|
|
|
$actual = call_user_func($config); |
|
|
|
|
183
|
|
|
} catch (\ParseError $exception) { |
184
|
|
|
echo 'File', PHP_EOL, $this->getPrintableFile($value), PHP_EOL; |
185
|
|
|
throw $exception; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
$expected = [ |
189
|
|
|
'\\Zend\\ServiceManager\\AbstractFactory\\ConfigAbstractFactory' => [ |
190
|
|
|
'AddSuperAction' => [ |
191
|
|
|
EntityManagerInterface::class, |
192
|
|
|
'\\Zend\\Hydrator\\ClassMethods', |
193
|
|
|
'SuperInputFilter', |
194
|
|
|
'\\Psr\\Log\\LoggerInterface', |
195
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
196
|
|
|
], |
197
|
|
|
'UpdateSuperAction' => [ |
198
|
|
|
EntityManagerInterface::class, |
199
|
|
|
'\\Zend\\Hydrator\\ClassMethods', |
200
|
|
|
'SuperInputFilter', |
201
|
|
|
'\\Psr\\Log\\LoggerInterface', |
202
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
203
|
|
|
], |
204
|
|
|
'GetSuperAction' => [ |
205
|
|
|
EntityManagerInterface::class, |
206
|
|
|
'\\Psr\\Log\\LoggerInterface', |
207
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
208
|
|
|
], |
209
|
|
|
'GetsSuperAction' => [ |
210
|
|
|
EntityManagerInterface::class, |
211
|
|
|
'\\Psr\\Log\\LoggerInterface', |
212
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
213
|
|
|
], |
214
|
|
|
'DeleteSuperAction' => [ |
215
|
|
|
EntityManagerInterface::class, |
216
|
|
|
'\\Psr\\Log\\LoggerInterface', |
217
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
218
|
|
|
], |
219
|
|
|
'AddDummyAction' => [ |
220
|
|
|
EntityManagerInterface::class, |
221
|
|
|
'\\Zend\\Hydrator\\ClassMethods', |
222
|
|
|
'DummyInputFilter', |
223
|
|
|
'\\Psr\\Log\\LoggerInterface', |
224
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
225
|
|
|
], |
226
|
|
|
'UpdateDummyAction' => [ |
227
|
|
|
EntityManagerInterface::class, |
228
|
|
|
'\\Zend\\Hydrator\\ClassMethods', |
229
|
|
|
'DummyInputFilter', |
230
|
|
|
'\\Psr\\Log\\LoggerInterface', |
231
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
232
|
|
|
], |
233
|
|
|
'GetDummyAction' => [ |
234
|
|
|
EntityManagerInterface::class, |
235
|
|
|
'\\Psr\\Log\\LoggerInterface', |
236
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
237
|
|
|
], |
238
|
|
|
'GetsDummyAction' => [ |
239
|
|
|
EntityManagerInterface::class, |
240
|
|
|
'\\Psr\\Log\\LoggerInterface', |
241
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
242
|
|
|
], |
243
|
|
|
'DeleteDummyAction' => [ |
244
|
|
|
EntityManagerInterface::class, |
245
|
|
|
'\\Psr\\Log\\LoggerInterface', |
246
|
|
|
'\\SlayerBirden\\DataFlowServer\\Extractor\\RecursiveEntitiesExtractor', |
247
|
|
|
], |
248
|
|
|
], |
249
|
|
|
'dependencies' => [ |
250
|
|
|
'delegators' => [ |
251
|
|
|
'\\Zend\\Expressive\\Application' => [ |
252
|
|
|
'Routes', |
253
|
|
|
], |
254
|
|
|
], |
255
|
|
|
], |
256
|
|
|
'doctrine' => [ |
257
|
|
|
'paths' => [ |
258
|
|
|
'src/Dummy/Entities' |
259
|
|
|
], |
260
|
|
|
], |
261
|
|
|
'input_filter_specs' => [ |
262
|
|
|
'SuperInputFilter' => [ |
263
|
|
|
'bar' => [ |
264
|
|
|
'required' => true, |
265
|
|
|
], |
266
|
|
|
'baz' => [ |
267
|
|
|
'required' => true, |
268
|
|
|
], |
269
|
|
|
], |
270
|
|
|
'DummyInputFilter' => [ |
271
|
|
|
'bar' => [ |
272
|
|
|
'required' => true, |
273
|
|
|
], |
274
|
|
|
'baz' => [ |
275
|
|
|
'required' => true, |
276
|
|
|
], |
277
|
|
|
], |
278
|
|
|
], |
279
|
|
|
]; |
280
|
|
|
|
281
|
|
|
$this->assertEquals($expected, $actual); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
public function testGetClassName() |
285
|
|
|
{ |
286
|
|
|
$this->assertSame('A\\B\\ConfigProvider', (new Config($this->provider->reveal()))->getClassName()); |
287
|
|
|
} |
288
|
|
|
} |
289
|
|
|
|