Skip to content

Commit 872d2e8

Browse files
Merge branch '6.0' into 6.1
* 6.0: - - Fix merge Fix merge [HttpKernel] Guard against bad profile data Fix merge [FrameworkBundle] Fix resetting container between tests Fix deprecations on PHP 8.2
2 parents 2072c3e + 6cbb542 commit 872d2e8

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

DependencyInjection/Compiler/AddAnnotationsCachedReaderPass.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler;
1313

14+
use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
1415
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617

@@ -28,14 +29,18 @@ public function process(ContainerBuilder $container)
2829
// "annotation_reader" at build time don't get any cache
2930
foreach ($container->findTaggedServiceIds('annotations.cached_reader') as $id => $tags) {
3031
$reader = $container->getDefinition($id);
32+
$reader->setPublic(false);
3133
$properties = $reader->getProperties();
3234

3335
if (isset($properties['cacheProviderBackup'])) {
3436
$provider = $properties['cacheProviderBackup']->getValues()[0];
3537
unset($properties['cacheProviderBackup']);
3638
$reader->setProperties($properties);
37-
$container->set($id, null);
38-
$container->setDefinition($id, $reader->replaceArgument(1, $provider));
39+
$reader->replaceArgument(1, $provider);
40+
} elseif (4 <= \count($arguments = $reader->getArguments()) && $arguments[3] instanceof ServiceClosureArgument) {
41+
$arguments[1] = $arguments[3]->getValues()[0];
42+
unset($arguments[3]);
43+
$reader->setArguments($arguments);
3944
}
4045
}
4146
}

DependencyInjection/FrameworkExtension.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,9 +1610,10 @@ private function registerAnnotationsConfiguration(array $config, ContainerBuilde
16101610

16111611
$container
16121612
->getDefinition('annotations.cached_reader')
1613+
->setPublic(true) // set to false in AddAnnotationsCachedReaderPass
16131614
->replaceArgument(2, $config['debug'])
1614-
// temporary property to lazy-reference the cache provider without using it until AddAnnotationsCachedReaderPass runs
1615-
->setProperty('cacheProviderBackup', new ServiceClosureArgument(new Reference($cacheService)))
1615+
// reference the cache provider without using it until AddAnnotationsCachedReaderPass runs
1616+
->addArgument(new ServiceClosureArgument(new Reference($cacheService)))
16161617
->addTag('annotations.cached_reader')
16171618
;
16181619

KernelBrowser.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Symfony\Component\HttpKernel\KernelInterface;
2323
use Symfony\Component\HttpKernel\Profiler\Profile as HttpProfile;
2424
use Symfony\Component\Security\Core\User\UserInterface;
25-
use Symfony\Contracts\Service\ResetInterface;
2625

2726
/**
2827
* Simulates a browser and makes requests to a Kernel object.
@@ -157,12 +156,8 @@ protected function doRequest(object $request): Response
157156
// avoid shutting down the Kernel if no request has been performed yet
158157
// WebTestCase::createClient() boots the Kernel but do not handle a request
159158
if ($this->hasPerformedRequest && $this->reboot) {
160-
$container = $this->kernel->getContainer();
159+
$this->kernel->boot();
161160
$this->kernel->shutdown();
162-
163-
if ($container instanceof ResetInterface) {
164-
$container->reset();
165-
}
166161
} else {
167162
$this->hasPerformedRequest = true;
168163
}

Test/KernelTestCase.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Symfony\Component\DependencyInjection\ContainerInterface;
1616
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1717
use Symfony\Component\HttpKernel\KernelInterface;
18-
use Symfony\Contracts\Service\ResetInterface;
1918

2019
/**
2120
* KernelTestCase is the base class for tests needing a Kernel.
@@ -35,8 +34,6 @@ abstract class KernelTestCase extends TestCase
3534

3635
protected static $booted = false;
3736

38-
private static ?ContainerInterface $kernelContainer = null;
39-
4037
protected function tearDown(): void
4138
{
4239
static::ensureKernelShutdown();
@@ -69,12 +66,11 @@ protected static function bootKernel(array $options = []): KernelInterface
6966
{
7067
static::ensureKernelShutdown();
7168

72-
static::$kernel = static::createKernel($options);
73-
static::$kernel->boot();
69+
$kernel = static::createKernel($options);
70+
$kernel->boot();
71+
self::$kernel = $kernel;
7472
static::$booted = true;
7573

76-
self::$kernelContainer = static::$kernel->getContainer();
77-
7874
return static::$kernel;
7975
}
8076

@@ -95,7 +91,7 @@ protected static function getContainer(): ContainerInterface
9591
}
9692

9793
try {
98-
return self::$kernelContainer->get('test.service_container');
94+
return self::$kernel->getContainer()->get('test.service_container');
9995
} catch (ServiceNotFoundException $e) {
10096
throw new \LogicException('Could not find service "test.service_container". Try updating the "framework.test" config to "true".', 0, $e);
10197
}
@@ -144,14 +140,9 @@ protected static function createKernel(array $options = []): KernelInterface
144140
protected static function ensureKernelShutdown()
145141
{
146142
if (null !== static::$kernel) {
143+
static::$kernel->boot();
147144
static::$kernel->shutdown();
148145
static::$booted = false;
149146
}
150-
151-
if (self::$kernelContainer instanceof ResetInterface) {
152-
self::$kernelContainer->reset();
153-
}
154-
155-
self::$kernelContainer = null;
156147
}
157148
}

Tests/KernelBrowserTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ public function testEnableRebootKernel()
5151
$client->request('GET', '/');
5252
}
5353

54+
public function testRequestAfterKernelShutdownAndPerformedRequest()
55+
{
56+
$this->expectNotToPerformAssertions();
57+
58+
$client = static::createClient(['test_case' => 'TestServiceContainer']);
59+
$client->request('GET', '/');
60+
static::ensureKernelShutdown();
61+
$client->request('GET', '/');
62+
}
63+
5464
private function getKernelMock()
5565
{
5666
$mock = $this->getMockBuilder($this->getKernelClass())

0 commit comments

Comments
 (0)