1616use Hautelook \AliceBundle \Functional \ConfigurableKernel ;
1717use Hautelook \AliceBundle \Functional \WithoutDoctrineKernel ;
1818use Nelmio \Alice \Bridge \Symfony \NelmioAliceBundle ;
19- use PHPUnit \ Framework \ TestCase ;
20- use Symfony \Component \HttpKernel \KernelInterface ;
19+ use Symfony \ Bundle \ FrameworkBundle \ Test \ KernelTestCase ;
20+ use Symfony \Component \HttpKernel \Kernel ;
2121
2222/**
2323 * @covers \Hautelook\AliceBundle\HautelookAliceBundle
2424 * @covers \Hautelook\AliceBundle\DependencyInjection\Configuration
2525 * @covers \Hautelook\AliceBundle\DependencyInjection\HautelookAliceExtension
2626 */
27- class HautelookAliceBundleTest extends TestCase
27+ class HautelookAliceBundleTest extends KernelTestCase
2828{
29- /**
30- * @var KernelInterface|null
31- */
32- protected $ kernel ;
33-
3429 /**
3530 * {@inheritdoc}
3631 */
37- public function tearDown (): void
32+ protected function tearDown (): void
3833 {
39- if (null !== $ this ->kernel ) {
40- $ this ->kernel ->shutdown ();
34+ if (Kernel::VERSION_ID < 41000 ) {
35+ if (null !== self ::$ kernel ) {
36+ self ::$ kernel ->shutdown ();
37+ }
38+ } else {
39+ parent ::tearDown ();
40+ static ::$ class = null ;
4141 }
4242 }
4343
@@ -46,88 +46,102 @@ public function testCannotBootIfFidryAliceDataFixturesBundleIsNotRegistered()
4646 $ this ->expectException (\LogicException::class);
4747 $ this ->expectExceptionMessage ('To register "Hautelook\AliceBundle\HautelookAliceBundle", you also need: "Doctrine\Bundle\DoctrineBundle\DoctrineBundle", "Fidry\AliceDataFixtures\Bridge\Symfony\FidryAliceDataFixturesBundle". ' );
4848
49- $ this -> kernel = new ConfigurableKernel ('ConfigurableKernel0 ' , true );
50- $ this -> kernel ->boot ();
49+ self :: $ kernel = new ConfigurableKernel ('ConfigurableKernel0 ' , true );
50+ self :: $ kernel ->boot ();
5151 }
5252
5353 public function testWillReplaceFixtureLoadCommandWithErrorInformationCommandIfDoctrineBundleIsNotRegistered ()
5454 {
5555 $ this ->expectException (\LogicException::class);
5656 $ this ->expectExceptionMessage ('To register "Hautelook\AliceBundle\HautelookAliceBundle", you also need: "Doctrine\Bundle\DoctrineBundle\DoctrineBundle". ' );
5757
58- $ this -> kernel = new WithoutDoctrineKernel ('ConfigurableKernel1 ' , true );
59- $ this -> kernel ->addBundle (new FidryAliceDataFixturesBundle ());
60- $ this -> kernel ->addBundle (new NelmioAliceBundle ());
61- $ this -> kernel ->boot ();
58+ self :: $ kernel = new WithoutDoctrineKernel ('ConfigurableKernel1 ' , true );
59+ self :: $ kernel ->addBundle (new FidryAliceDataFixturesBundle ());
60+ self :: $ kernel ->addBundle (new NelmioAliceBundle ());
61+ self :: $ kernel ->boot ();
6262 }
6363
6464 public function testServiceRegistration ()
6565 {
66- $ this ->kernel = new AppKernel ('public ' , true );
67- $ this ->kernel ->boot ();
66+ if (Kernel::VERSION_ID < 41000 ) {
67+ self ::$ kernel = new AppKernel ('public ' , true );
68+ self ::$ kernel ->boot ();
69+ $ container = self ::$ kernel ->getContainer ();
70+ } else {
71+ parent ::bootKernel (['environment ' => 'public ' , 'debug ' => true ]);
72+ $ container = self ::$ container ;
73+ }
6874
6975 // Resolvers
7076 $ this ->assertInstanceOf (
7177 \Hautelook \AliceBundle \Resolver \Bundle \SimpleBundleResolver::class,
72- $ this -> kernel -> getContainer () ->get ('hautelook_alice.resolver.bundle.simple_resolver ' )
78+ $ container ->get ('hautelook_alice.resolver.bundle.simple_resolver ' )
7379 );
7480
7581 $ this ->assertInstanceOf (
7682 \Hautelook \AliceBundle \Resolver \Bundle \NoBundleResolver::class,
77- $ this -> kernel -> getContainer () ->get ('hautelook_alice.resolver.bundle.no_bundle_resolver ' )
83+ $ container ->get ('hautelook_alice.resolver.bundle.no_bundle_resolver ' )
7884 );
7985
8086 $ this ->assertInstanceOf (
8187 \Hautelook \AliceBundle \BundleResolverInterface::class,
82- $ this -> kernel -> getContainer () ->get ('hautelook_alice.resolver.bundle ' )
88+ $ container ->get ('hautelook_alice.resolver.bundle ' )
8389 );
8490
8591 // Locators
8692 $ this ->assertInstanceOf (
8793 \Hautelook \AliceBundle \Locator \EnvironmentlessFilesLocator::class,
88- $ this -> kernel -> getContainer () ->get ('hautelook_alice.locator.environmentless ' )
94+ $ container ->get ('hautelook_alice.locator.environmentless ' )
8995 );
9096
9197 $ this ->assertInstanceOf (
9298 \Hautelook \AliceBundle \Locator \EnvDirectoryLocator::class,
93- $ this -> kernel -> getContainer () ->get ('hautelook_alice.locator.env_directory ' )
99+ $ container ->get ('hautelook_alice.locator.env_directory ' )
94100 );
95101
96102 $ this ->assertInstanceOf (
97103 \Hautelook \AliceBundle \FixtureLocatorInterface::class,
98- $ this -> kernel -> getContainer () ->get ('hautelook_alice.locator ' )
104+ $ container ->get ('hautelook_alice.locator ' )
99105 );
100106
101107 // Loader
102108 $ this ->assertInstanceOf (
103109 \Fidry \AliceDataFixtures \Loader \FileResolverLoader::class,
104- $ this -> kernel -> getContainer () ->get ('hautelook_alice.data_fixtures.loader.file_resolver_loader ' )
110+ $ container ->get ('hautelook_alice.data_fixtures.loader.file_resolver_loader ' )
105111 );
106112
107113 $ this ->assertInstanceOf (
108114 \Fidry \AliceDataFixtures \LoaderInterface::class,
109- $ this -> kernel -> getContainer () ->get ('hautelook_alice.data_fixtures.purge_loader ' )
115+ $ container ->get ('hautelook_alice.data_fixtures.purge_loader ' )
110116 );
111117
112118 $ this ->assertInstanceOf (
113119 \Fidry \AliceDataFixtures \LoaderInterface::class,
114- $ this -> kernel -> getContainer () ->get ('hautelook_alice.data_fixtures.append_loader ' )
120+ $ container ->get ('hautelook_alice.data_fixtures.append_loader ' )
115121 );
116122
117123 $ this ->assertInstanceOf (
118124 \Hautelook \AliceBundle \Loader \DoctrineOrmLoader::class,
119- $ this -> kernel -> getContainer () ->get ('hautelook_alice.loader.doctrine_orm_loader ' )
125+ $ container ->get ('hautelook_alice.loader.doctrine_orm_loader ' )
120126 );
121127
122128 $ this ->assertInstanceOf (
123129 \Hautelook \AliceBundle \LoaderInterface::class,
124- $ this -> kernel -> getContainer () ->get ('hautelook_alice.loader ' )
130+ $ container ->get ('hautelook_alice.loader ' )
125131 );
126132
127133 // Commands
128134 $ this ->assertInstanceOf (
129135 \Hautelook \AliceBundle \Console \Command \Doctrine \DoctrineOrmLoadDataFixturesCommand::class,
130- $ this -> kernel -> getContainer () ->get ('hautelook_alice.console.command.doctrine.doctrine_orm_load_data_fixtures_command ' )
136+ $ container ->get ('hautelook_alice.console.command.doctrine.doctrine_orm_load_data_fixtures_command ' )
131137 );
132138 }
139+
140+ /**
141+ * {@inheritdoc}
142+ */
143+ protected static function getKernelClass ()
144+ {
145+ return AppKernel::class;
146+ }
133147}
0 commit comments