55namespace Tmi \TranslationBundle \Test \DependencyInjection ;
66
77use Doctrine \DBAL \Exception ;
8+ use Doctrine \DBAL \Platforms \AbstractPlatform ;
89use Doctrine \DBAL \Types \Exception \TypesException ;
910use Doctrine \DBAL \Types \Type ;
11+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
1012use Tmi \TranslationBundle \DependencyInjection \TmiTranslationExtension ;
1113use Tmi \TranslationBundle \Doctrine \Type \TuuidType ;
1214use Tmi \TranslationBundle \EventSubscriber \LocaleFilterConfigurator ;
1315use Tmi \TranslationBundle \Test \IntegrationTestCase ;
14- use Symfony \Component \DependencyInjection \ContainerBuilder ;
15- use Doctrine \DBAL \Platforms \AbstractPlatform ;
1616
1717final class TmiTranslationExtensionTest extends IntegrationTestCase
1818{
19- private function createContainerBuilderFromKernel (): ContainerBuilder
20- {
21- $ containerBuilder = new ContainerBuilder ();
22-
23- // Pull parameters from the booted kernel container if available
24- if (self ::$ container === null ) {
25- self ::bootKernel ();
26- self ::$ container = method_exists (self ::class, 'getContainer ' )
27- ? self ::getContainer ()
28- : self ::$ kernel ->getContainer ();
29- }
30-
31- if (self ::$ container !== null ) {
32- foreach (self ::$ container ->getParameterBag ()->all () as $ key => $ value ) {
33- $ containerBuilder ->setParameter ($ key , $ value );
34- }
35- }
36-
37- return $ containerBuilder ;
38- }
39-
40-
4119 /**
4220 * @throws Exception
4321 * @throws TypesException
@@ -47,10 +25,10 @@ public function testLoadRegistersServices(): void
4725 $ containerBuilder = $ this ->createContainerBuilderFromKernel ();
4826
4927 $ extension = new TmiTranslationExtension ();
50- $ config = [
28+ $ config = [
5129 [
52- 'locales ' => ['en_US ' , 'de_DE ' , 'it_IT ' ],
53- 'default_locale ' => 'en_US ' ,
30+ 'locales ' => ['en_US ' , 'de_DE ' , 'it_IT ' ],
31+ 'default_locale ' => 'en_US ' ,
5432 'disabled_firewalls ' => ['main ' ],
5533 ],
5634 ];
@@ -65,7 +43,7 @@ public function testLoadRegistersServices(): void
6543 public function testPrependDoesNothing (): void
6644 {
6745 $ containerBuilder = $ this ->createContainerBuilderFromKernel ();
68- $ extension = new TmiTranslationExtension ();
46+ $ extension = new TmiTranslationExtension ();
6947 $ extension ->prepend ($ containerBuilder );
7048
7149 $ this ->assertInstanceOf (ContainerBuilder::class, $ containerBuilder );
@@ -84,7 +62,7 @@ public function testTuuidTypeIsRegistered(): void
8462 }
8563
8664 $ containerBuilder = $ this ->createContainerBuilderFromKernel ();
87- $ extension = new TmiTranslationExtension ();
65+ $ extension = new TmiTranslationExtension ();
8866 $ extension ->load ([['locales ' => ['en_US ' , 'de_DE ' ], 'default_locale ' => 'en_US ' ]], $ containerBuilder );
8967
9068 $ this ->assertTrue (Type::hasType (TuuidType::NAME ));
@@ -102,12 +80,18 @@ public function testTuuidTypeMapping(): void
10280 // Create a fake DBAL platform stub
10381 $ platformStub = $ this ->createMock (AbstractPlatform::class);
10482 $ platformStub ->method ('registerDoctrineTypeMapping ' )
105- ->with ('tuuid ' , 'guid ' );
83+ ->with ('tuuid ' , 'tuuid ' );
10684
10785 // Create a fake connection stub
10886 $ connectionStub = new readonly class ($ platformStub ) {
109- public function __construct (private AbstractPlatform $ platform ) {}
110- public function getDatabasePlatform (): AbstractPlatform { return $ this ->platform ; }
87+ public function __construct (private AbstractPlatform $ platform )
88+ {
89+ }
90+
91+ public function getDatabasePlatform (): AbstractPlatform
92+ {
93+ return $ this ->platform ;
94+ }
11195 };
11296
11397 // Register the fake connection in the container
@@ -120,4 +104,25 @@ public function getDatabasePlatform(): AbstractPlatform { return $this->platform
120104 $ this ->assertTrue (Type::hasType (TuuidType::NAME ), 'TuuidType should be registered ' );
121105 $ this ->assertInstanceOf (TuuidType::class, Type::getType (TuuidType::NAME ));
122106 }
107+
108+ private function createContainerBuilderFromKernel (): ContainerBuilder
109+ {
110+ $ containerBuilder = new ContainerBuilder ();
111+
112+ // Pull parameters from the booted kernel container if available
113+ if (null === self ::$ container ) {
114+ self ::bootKernel ();
115+ self ::$ container = method_exists (self ::class, 'getContainer ' )
116+ ? self ::getContainer ()
117+ : self ::$ kernel ->getContainer ();
118+ }
119+
120+ if (null !== self ::$ container ) {
121+ foreach (self ::$ container ->getParameterBag ()->all () as $ key => $ value ) {
122+ $ containerBuilder ->setParameter ($ key , $ value );
123+ }
124+ }
125+
126+ return $ containerBuilder ;
127+ }
123128}
0 commit comments