11
11
12
12
namespace Symfony \Bundle \MakerBundle \Tests \Doctrine ;
13
13
14
- use Doctrine \Bundle \DoctrineBundle \DependencyInjection \DoctrineExtension ;
15
14
use Doctrine \Bundle \DoctrineBundle \DoctrineBundle ;
16
15
use Doctrine \Persistence \ManagerRegistry ;
17
16
use PHPUnit \Framework \TestCase ;
@@ -41,7 +40,7 @@ class EntityRegeneratorTest extends TestCase
41
40
/**
42
41
* @dataProvider getRegenerateEntitiesTests
43
42
*/
44
- public function testRegenerateEntities (string $ expectedDirName , bool $ overwrite )
43
+ public function testRegenerateEntities (string $ expectedDirName , bool $ overwrite ): void
45
44
{
46
45
/*
47
46
* Prior to symfony/doctrine-bridge 5.0 (which require
@@ -65,7 +64,7 @@ public function testRegenerateEntities(string $expectedDirName, bool $overwrite)
65
64
);
66
65
}
67
66
68
- public function getRegenerateEntitiesTests ()
67
+ public function getRegenerateEntitiesTests (): \ Generator
69
68
{
70
69
yield 'regenerate_no_overwrite ' => [
71
70
'expected_no_overwrite ' ,
@@ -78,7 +77,7 @@ public function getRegenerateEntitiesTests()
78
77
];
79
78
}
80
79
81
- public function testXmlRegeneration ()
80
+ public function testXmlRegeneration (): void
82
81
{
83
82
$ kernel = new TestXmlEntityRegeneratorKernel ('dev ' , true );
84
83
$ this ->doTestRegeneration (
@@ -91,7 +90,7 @@ public function testXmlRegeneration()
91
90
);
92
91
}
93
92
94
- private function doTestRegeneration (string $ sourceDir , Kernel $ kernel , string $ namespace , string $ expectedDirName , bool $ overwrite , string $ targetDirName )
93
+ private function doTestRegeneration (string $ sourceDir , Kernel $ kernel , string $ namespace , string $ expectedDirName , bool $ overwrite , string $ targetDirName ): void
95
94
{
96
95
$ fs = new Filesystem ();
97
96
$ tmpDir = __DIR__ .'/../tmp/ ' .$ targetDirName ;
@@ -157,21 +156,20 @@ private function createAllButTraitsIterator(string $sourceDir): \Iterator
157
156
class TestEntityRegeneratorKernel extends Kernel
158
157
{
159
158
use MicroKernelTrait;
160
- use OverrideUrlTraitFixture;
161
159
162
- public function registerBundles ()
160
+ public function registerBundles (): array
163
161
{
164
162
return [
165
163
new FrameworkBundle (),
166
164
new DoctrineBundle (),
167
165
];
168
166
}
169
167
170
- protected function configureRoutes (RouteCollectionBuilder $ routes )
168
+ protected function configureRoutes (RouteCollectionBuilder $ routes ): void
171
169
{
172
170
}
173
171
174
- protected function configureContainer (ContainerBuilder $ c , LoaderInterface $ loader )
172
+ protected function configureContainer (ContainerBuilder $ c , LoaderInterface $ loader ): void
175
173
{
176
174
$ c ->loadFromExtension ('framework ' , [
177
175
'secret ' => 123 ,
@@ -185,10 +183,6 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
185
183
'url ' => 'sqlite:///fake ' ,
186
184
];
187
185
188
- if ($ this ->canOverrideUrl ($ c )) {
189
- $ dbal ['override_url ' ] = true ;
190
- }
191
-
192
186
$ c ->prependExtensionConfig ('doctrine ' , [
193
187
'dbal ' => $ dbal ,
194
188
'orm ' => [
@@ -205,12 +199,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
205
199
]);
206
200
}
207
201
208
- public function getProjectDir ()
209
- {
210
- return $ this ->getRootDir ();
211
- }
212
-
213
- public function getRootDir ()
202
+ public function getProjectDir (): string
214
203
{
215
204
return __DIR__ .'/../tmp/current_project ' ;
216
205
}
@@ -219,21 +208,20 @@ public function getRootDir()
219
208
class TestXmlEntityRegeneratorKernel extends Kernel
220
209
{
221
210
use MicroKernelTrait;
222
- use OverrideUrlTraitFixture;
223
211
224
- public function registerBundles ()
212
+ public function registerBundles (): array
225
213
{
226
214
return [
227
215
new FrameworkBundle (),
228
216
new DoctrineBundle (),
229
217
];
230
218
}
231
219
232
- protected function configureRoutes (RouteCollectionBuilder $ routes )
220
+ protected function configureRoutes (RouteCollectionBuilder $ routes ): void
233
221
{
234
222
}
235
223
236
- protected function configureContainer (ContainerBuilder $ c , LoaderInterface $ loader )
224
+ protected function configureContainer (ContainerBuilder $ c , LoaderInterface $ loader ): void
237
225
{
238
226
$ c ->loadFromExtension ('framework ' , [
239
227
'secret ' => 123 ,
@@ -247,10 +235,6 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
247
235
'url ' => 'sqlite:///fake ' ,
248
236
];
249
237
250
- if ($ this ->canOverrideUrl ($ c )) {
251
- $ dbal ['override_url ' ] = true ;
252
- }
253
-
254
238
$ c ->prependExtensionConfig ('doctrine ' , [
255
239
'dbal ' => $ dbal ,
256
240
'orm ' => [
@@ -268,39 +252,16 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
268
252
]);
269
253
}
270
254
271
- public function getProjectDir ()
272
- {
273
- return $ this ->getRootDir ();
274
- }
275
-
276
- public function getRootDir ()
255
+ public function getProjectDir (): string
277
256
{
278
257
return __DIR__ .'/../tmp/current_project_xml ' ;
279
258
}
280
259
}
281
260
282
261
class AllButTraitsIterator extends \RecursiveFilterIterator
283
262
{
284
- public function accept ()
263
+ public function accept (): bool
285
264
{
286
265
return !\in_array ($ this ->current ()->getFilename (), []);
287
266
}
288
267
}
289
-
290
- trait OverrideUrlTraitFixture
291
- {
292
- /**
293
- * Quick and dirty way to check if override_url is required since doctrine-bundle 2.3.
294
- */
295
- public function canOverrideUrl (ContainerBuilder $ builder ): bool
296
- {
297
- /** @var DoctrineExtension $ext */
298
- $ ext = $ builder ->getExtension ('doctrine ' );
299
- $ method = new \ReflectionMethod (DoctrineExtension::class, 'getConnectionOptions ' );
300
- $ method ->setAccessible (true );
301
-
302
- $ configOptions = $ method ->invoke ($ ext , ['override_url ' => 'string ' , 'shards ' => [], 'replicas ' => [], 'slaves ' => []]);
303
-
304
- return \array_key_exists ('connection_override_options ' , $ configOptions );
305
- }
306
- }
0 commit comments