1111
1212namespace Symfony \Bundle \MakerBundle \Tests \Doctrine ;
1313
14- use Doctrine \Bundle \DoctrineBundle \DependencyInjection \DoctrineExtension ;
1514use Doctrine \Bundle \DoctrineBundle \DoctrineBundle ;
1615use Doctrine \Persistence \ManagerRegistry ;
1716use PHPUnit \Framework \TestCase ;
@@ -41,7 +40,7 @@ class EntityRegeneratorTest extends TestCase
4140 /**
4241 * @dataProvider getRegenerateEntitiesTests
4342 */
44- public function testRegenerateEntities (string $ expectedDirName , bool $ overwrite )
43+ public function testRegenerateEntities (string $ expectedDirName , bool $ overwrite ): void
4544 {
4645 /*
4746 * Prior to symfony/doctrine-bridge 5.0 (which require
@@ -65,7 +64,7 @@ public function testRegenerateEntities(string $expectedDirName, bool $overwrite)
6564 );
6665 }
6766
68- public function getRegenerateEntitiesTests ()
67+ public function getRegenerateEntitiesTests (): \ Generator
6968 {
7069 yield 'regenerate_no_overwrite ' => [
7170 'expected_no_overwrite ' ,
@@ -78,7 +77,7 @@ public function getRegenerateEntitiesTests()
7877 ];
7978 }
8079
81- public function testXmlRegeneration ()
80+ public function testXmlRegeneration (): void
8281 {
8382 $ kernel = new TestXmlEntityRegeneratorKernel ('dev ' , true );
8483 $ this ->doTestRegeneration (
@@ -91,7 +90,7 @@ public function testXmlRegeneration()
9190 );
9291 }
9392
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
9594 {
9695 $ fs = new Filesystem ();
9796 $ tmpDir = __DIR__ .'/../tmp/ ' .$ targetDirName ;
@@ -157,21 +156,20 @@ private function createAllButTraitsIterator(string $sourceDir): \Iterator
157156class TestEntityRegeneratorKernel extends Kernel
158157{
159158 use MicroKernelTrait;
160- use OverrideUrlTraitFixture;
161159
162- public function registerBundles ()
160+ public function registerBundles (): array
163161 {
164162 return [
165163 new FrameworkBundle (),
166164 new DoctrineBundle (),
167165 ];
168166 }
169167
170- protected function configureRoutes (RouteCollectionBuilder $ routes )
168+ protected function configureRoutes (RouteCollectionBuilder $ routes ): void
171169 {
172170 }
173171
174- protected function configureContainer (ContainerBuilder $ c , LoaderInterface $ loader )
172+ protected function configureContainer (ContainerBuilder $ c , LoaderInterface $ loader ): void
175173 {
176174 $ c ->loadFromExtension ('framework ' , [
177175 'secret ' => 123 ,
@@ -185,10 +183,6 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
185183 'url ' => 'sqlite:///fake ' ,
186184 ];
187185
188- if ($ this ->canOverrideUrl ($ c )) {
189- $ dbal ['override_url ' ] = true ;
190- }
191-
192186 $ c ->prependExtensionConfig ('doctrine ' , [
193187 'dbal ' => $ dbal ,
194188 'orm ' => [
@@ -205,12 +199,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
205199 ]);
206200 }
207201
208- public function getProjectDir ()
209- {
210- return $ this ->getRootDir ();
211- }
212-
213- public function getRootDir ()
202+ public function getProjectDir (): string
214203 {
215204 return __DIR__ .'/../tmp/current_project ' ;
216205 }
@@ -219,21 +208,20 @@ public function getRootDir()
219208class TestXmlEntityRegeneratorKernel extends Kernel
220209{
221210 use MicroKernelTrait;
222- use OverrideUrlTraitFixture;
223211
224- public function registerBundles ()
212+ public function registerBundles (): array
225213 {
226214 return [
227215 new FrameworkBundle (),
228216 new DoctrineBundle (),
229217 ];
230218 }
231219
232- protected function configureRoutes (RouteCollectionBuilder $ routes )
220+ protected function configureRoutes (RouteCollectionBuilder $ routes ): void
233221 {
234222 }
235223
236- protected function configureContainer (ContainerBuilder $ c , LoaderInterface $ loader )
224+ protected function configureContainer (ContainerBuilder $ c , LoaderInterface $ loader ): void
237225 {
238226 $ c ->loadFromExtension ('framework ' , [
239227 'secret ' => 123 ,
@@ -247,10 +235,6 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
247235 'url ' => 'sqlite:///fake ' ,
248236 ];
249237
250- if ($ this ->canOverrideUrl ($ c )) {
251- $ dbal ['override_url ' ] = true ;
252- }
253-
254238 $ c ->prependExtensionConfig ('doctrine ' , [
255239 'dbal ' => $ dbal ,
256240 'orm ' => [
@@ -268,39 +252,16 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
268252 ]);
269253 }
270254
271- public function getProjectDir ()
272- {
273- return $ this ->getRootDir ();
274- }
275-
276- public function getRootDir ()
255+ public function getProjectDir (): string
277256 {
278257 return __DIR__ .'/../tmp/current_project_xml ' ;
279258 }
280259}
281260
282261class AllButTraitsIterator extends \RecursiveFilterIterator
283262{
284- public function accept ()
263+ public function accept (): bool
285264 {
286265 return !\in_array ($ this ->current ()->getFilename (), []);
287266 }
288267}
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