Skip to content

Commit daad23a

Browse files
committed
bug #57455 [FrameworkBundle] Fix Kernel configuration loading (yceruto)
This PR was merged into the 7.2 branch. Discussion ---------- [FrameworkBundle] Fix Kernel configuration loading | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT - [x] Adding tests for it to avoid any regression in the future Commits ------- afa40bdca8 Fix kernel configuration loading
2 parents 4875a84 + cabdf4b commit daad23a

File tree

6 files changed

+82
-2
lines changed

6 files changed

+82
-2
lines changed

Kernel/MicroKernelTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private function configureContainer(ContainerConfigurator $container, LoaderInte
5454
$container->import($configDir.'/{packages}/*.{php,yaml}');
5555
$container->import($configDir.'/{packages}/'.$this->environment.'/*.{php,yaml}');
5656

57-
if (is_file($configDir.'/services.yaml')) {
57+
if (is_file($this->getConfigDir().'/services.yaml')) {
5858
$container->import($configDir.'/services.yaml');
5959
$container->import($configDir.'/{services}_'.$this->environment.'.yaml');
6060
} else {
@@ -79,7 +79,7 @@ private function configureRoutes(RoutingConfigurator $routes): void
7979
$routes->import($configDir.'/{routes}/'.$this->environment.'/*.{php,yaml}');
8080
$routes->import($configDir.'/{routes}/*.{php,yaml}');
8181

82-
if (is_file($configDir.'/routes.yaml')) {
82+
if (is_file($this->getConfigDir().'/routes.yaml')) {
8383
$routes->import($configDir.'/routes.yaml');
8484
} else {
8585
$routes->import($configDir.'/{routes}.php');

Tests/Kernel/MicroKernelTraitTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Symfony\Component\HttpKernel\Kernel;
2626
use Symfony\Component\Routing\Loader\Configurator\RoutingConfigurator;
2727

28+
require_once __DIR__.'/default/src/DefaultKernel.php';
2829
require_once __DIR__.'/flex-style/src/FlexStyleMicroKernel.php';
2930

3031
class MicroKernelTraitTest extends TestCase
@@ -150,6 +151,19 @@ public function testSimpleKernel()
150151

151152
$this->assertSame('Hello World!', $response->getContent());
152153
}
154+
155+
public function testDefaultKernel()
156+
{
157+
$kernel = $this->kernel = new DefaultKernel('test', false);
158+
$kernel->boot();
159+
160+
$this->assertTrue($kernel->getContainer()->has('foo_service'));
161+
162+
$request = Request::create('/');
163+
$response = $kernel->handle($request, HttpKernelInterface::MAIN_REQUEST, false);
164+
165+
$this->assertSame('OK', $response->getContent());
166+
}
153167
}
154168

155169
abstract class MinimalKernel extends Kernel
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
13+
14+
return [
15+
FrameworkBundle::class => ['all' => true],
16+
];
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
welcome:
2+
path: /
3+
controller: 'kernel'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
services:
2+
foo_service:
3+
class: stdClass
4+
public: true
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Bundle\FrameworkBundle\Tests\Kernel;
13+
14+
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
15+
use Symfony\Component\HttpFoundation\Response;
16+
use Symfony\Component\HttpKernel\Kernel;
17+
18+
class DefaultKernel extends Kernel
19+
{
20+
use MicroKernelTrait;
21+
22+
public function __invoke(): Response
23+
{
24+
return new Response('OK');
25+
}
26+
27+
private string $cacheDir;
28+
29+
public function getCacheDir(): string
30+
{
31+
return $this->cacheDir ??= sys_get_temp_dir().'/sf_default_kernel';
32+
}
33+
34+
public function getLogDir(): string
35+
{
36+
return $this->cacheDir;
37+
}
38+
39+
public function getProjectDir(): string
40+
{
41+
return \dirname(__DIR__);
42+
}
43+
}

0 commit comments

Comments
 (0)