2020
2121namespace JMS \TranslationBundle \Tests \Functional ;
2222
23- use JMS \TranslationBundle \Exception \RuntimeException ;
2423use JMS \TranslationBundle \JMSTranslationBundle ;
2524use JMS \TranslationBundle \Tests \Functional \Fixture \TestBundle \TestBundle ;
26- use Sensio \Bundle \FrameworkExtraBundle \SensioFrameworkExtraBundle ;
2725use Symfony \Bundle \FrameworkBundle \FrameworkBundle ;
26+ use Symfony \Bundle \FrameworkBundle \Kernel \MicroKernelTrait ;
2827use Symfony \Bundle \TwigBundle \TwigBundle ;
2928use Symfony \Component \Config \Loader \LoaderInterface ;
30- use Symfony \Component \Filesystem \Filesystem ;
29+ use Symfony \Component \DependencyInjection \ContainerBuilder ;
30+ use Symfony \Component \DependencyInjection \Loader \Configurator \ContainerConfigurator ;
3131use Symfony \Component \HttpKernel \Kernel ;
32+ use Symfony \Component \Routing \Loader \Configurator \RoutingConfigurator ;
3233
3334class AppKernel extends Kernel
3435{
35- private string | null $ config ;
36+ use MicroKernelTrait ;
3637
37- private string $ fwConfig ;
38-
39- public function __construct ( string $ fwConfig , ? string $ config)
40- {
38+ public function __construct (
39+ private string $ frameworkConfig ,
40+ private string | null $ config = null
41+ ) {
4142 parent ::__construct ('test ' , true );
42-
43- $ fs = new Filesystem ();
44- if ($ config ) {
45- if (!$ fs ->isAbsolutePath ($ config )) {
46- $ config = __DIR__ . '/config/ ' . $ config ;
47- }
48-
49- if (!file_exists ($ config )) {
50- throw new RuntimeException (sprintf ('The config file "%s" does not exist. ' , $ config ));
51- }
52- }
53- $ this ->config = $ config ;
54-
55- if (!$ fs ->isAbsolutePath ($ fwConfig )) {
56- $ fwConfig = __DIR__ . '/config/ ' . $ fwConfig ;
57- }
58- $ this ->fwConfig = $ fwConfig ;
5943 }
6044
6145 public function registerBundles (): iterable
6246 {
63- $ bundles = [
47+ return [
6448 new TestBundle (),
6549 new FrameworkBundle (),
6650 new TwigBundle (),
6751 new JMSTranslationBundle (),
6852 ];
53+ }
54+
55+ private function configureContainer (ContainerConfigurator $ container , LoaderInterface $ loader , ContainerBuilder $ builder ): void
56+ {
57+ $ configDir = $ this ->getConfigDir ();
6958
70- if (class_exists (SensioFrameworkExtraBundle::class)) {
71- $ bundles [] = new SensioFrameworkExtraBundle ();
59+ $ container ->import ($ configDir . '/ ' . $ this ->frameworkConfig );
60+
61+ if (null !== $ this ->config ) {
62+ $ loader ->load ($ configDir . '/ ' . $ this ->config );
7263 }
7364
74- return $ bundles ;
65+ $ container -> import ( $ configDir . ' /services.yaml ' ) ;
7566 }
7667
77- public function registerContainerConfiguration ( LoaderInterface $ loader ): void
68+ private function configureRoutes ( RoutingConfigurator $ routes ): void
7869 {
79- $ loader ->load ($ this ->fwConfig );
80- if ($ this ->config ) {
81- $ loader ->load ($ this ->config );
82- }
70+ $ configDir = $ this ->getConfigDir ();
8371
84- $ loader -> load ( $ this -> getProjectDir () . '/config/services .yaml ' );
72+ $ routes -> import ( $ configDir . '/routes .yaml ' );
8573 }
8674
8775 public function getCacheDir (): string
@@ -104,13 +92,16 @@ private function getBaseDir(): string
10492 return sys_get_temp_dir () . '/JMSTranslationBundle ' ;
10593 }
10694
107- public function serialize ()
95+ public function __serialize (): array
10896 {
109- return $ this ->config ;
97+ return [
98+ 'framework_config ' => $ this ->frameworkConfig ,
99+ 'config ' => $ this ->config ,
100+ ];
110101 }
111102
112- public function unserialize ( $ config )
103+ public function __unserialize ( array $ data ): void
113104 {
114- $ this ->__construct ($ config );
105+ $ this ->__construct ($ data [ ' framework_config ' ], $ data [ ' config ' ] );
115106 }
116107}
0 commit comments