File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414use Composer \Semver \Semver ;
1515use PHPUnit \Framework \TestCase ;
1616use Symfony \Bundle \MakerBundle \MakerInterface ;
17- use Symfony \Bundle \MakerBundle \Str ;
1817use Symfony \Component \HttpKernel \KernelInterface ;
1918use Symfony \Component \Process \Process ;
2019
@@ -100,10 +99,7 @@ private function getMakerInstance(string $makerClass): MakerInterface
10099 $ this ->kernel ->boot ();
101100 }
102101
103- // a cheap way to guess the service id
104- $ serviceId ??= \sprintf ('maker.maker.%s ' , Str::asSnakeCase ((new \ReflectionClass ($ makerClass ))->getShortName ()));
105-
106- return $ this ->kernel ->getContainer ()->get ($ serviceId );
102+ return $ this ->kernel ->getContainer ()->get ('maker_locator_for_tests ' )->get ($ makerClass );
107103 }
108104
109105 protected function createKernel (): KernelInterface
Original file line number Diff line number Diff line change 1818use Symfony \Component \Config \Loader \LoaderInterface ;
1919use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
2020use Symfony \Component \DependencyInjection \ContainerBuilder ;
21+ use Symfony \Component \DependencyInjection \Reference ;
22+ use Symfony \Component \DependencyInjection \ServiceLocator ;
2123use Symfony \Component \HttpKernel \Kernel ;
2224use Symfony \Component \Routing \Loader \Configurator \RoutingConfigurator ;
2325
@@ -77,10 +79,15 @@ public function getRootDir(): string
7779
7880 public function process (ContainerBuilder $ container ): void
7981 {
80- // makes all makers public to help the tests
82+ // Add a service locator to find makers by class name
83+ $ makers = [];
8184 foreach ($ container ->findTaggedServiceIds (MakeCommandRegistrationPass::MAKER_TAG ) as $ id => $ tags ) {
82- $ defn = $ container ->getDefinition ($ id );
83- $ defn ->setPublic (true );
85+ $ makers [$ container ->getDefinition ($ id )->getClass ()] = new Reference ($ id );
8486 }
87+
88+ $ container ->register ('maker_locator_for_tests ' , ServiceLocator::class)
89+ ->setArguments ([$ makers ])
90+ ->addTag ('container.service_locator ' )
91+ ->setPublic (true );
8592 }
8693}
You can’t perform that action at this time.
0 commit comments