Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8ec22e5

Browse files
Merge branch '4.1'
* 4.1: [FrameworkBundle] Fix test-container on kernel reboot, revert to returning the real container from Client::getContainer() Remove mentions of "beta" in composer.json files [DI] Ignore missing tree root nodes on validate [WebProfilerBundle] fixed getSession when no session has been set deprecation warnings bug #27299 [Cache] memcache connect should not add duplicate entries on sequential calls [Router] regression when matching a route [FrameworkBundle][SecurityBundle] Remove no-longer necessary Bundle::registerCommands override [Routing] Don't reorder past variable-length placeholders [DebugBundle] DebugBundle::registerCommands should be noop [BrowserKit] Fix a BC break in Client affecting Panthère [DX] Improve exception message when AbstractController::getParameter fails simple-phpunit: remove outdated appveryor workaround
2 parents d8739d1 + c9118b9 commit 8ec22e5

File tree

28 files changed

+221
-129
lines changed

28 files changed

+221
-129
lines changed

src/Symfony/Bridge/PhpUnit/bin/simple-phpunit

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,6 @@ if ($components) {
217217
}
218218
}
219219

220-
// Fixes for colors support on appveyor
221-
// See https://github.com/appveyor/ci/issues/373
222-
$colorFixes = array(
223-
array("S\033[0m\033[0m\033[36m\033[1mS", "E\033[0m\033[0m\033[31m\033[1mE", "I\033[0m\033[0m\033[33m\033[1mI", "F\033[0m\033[0m\033[41m\033[37mF"),
224-
array("SS", "EE", "II", "FF"),
225-
);
226-
$colorFixes[0] = array_merge($colorFixes[0], $colorFixes[0]);
227-
$colorFixes[1] = array_merge($colorFixes[1], $colorFixes[1]);
228-
229220
while ($runningProcs) {
230221
usleep(300000);
231222
$terminatedProcs = array();
@@ -241,20 +232,7 @@ if ($components) {
241232
foreach ($terminatedProcs as $component => $procStatus) {
242233
foreach (array('out', 'err') as $file) {
243234
$file = "$component/phpunit.std$file";
244-
245-
if ('\\' === DIRECTORY_SEPARATOR) {
246-
$h = fopen($file, 'rb');
247-
while (false !== $line = fgets($h)) {
248-
echo str_replace($colorFixes[0], $colorFixes[1], preg_replace(
249-
'/(\033\[[0-9]++);([0-9]++m)(?:(.)(\033\[0m))?/',
250-
"$1m\033[$2$3$4$4",
251-
$line
252-
));
253-
}
254-
fclose($h);
255-
} else {
256-
readfile($file);
257-
}
235+
readfile($file);
258236
unlink($file);
259237
}
260238

src/Symfony/Bundle/DebugBundle/DebugBundle.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\DebugBundle;
1313

1414
use Symfony\Bundle\DebugBundle\DependencyInjection\Compiler\DumpDataCollectorPass;
15+
use Symfony\Component\Console\Application;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\HttpKernel\Bundle\Bundle;
1718
use Symfony\Component\VarDumper\VarDumper;
@@ -52,4 +53,9 @@ public function build(ContainerBuilder $container)
5253

5354
$container->addCompilerPass(new DumpDataCollectorPass());
5455
}
56+
57+
public function registerCommands(Application $application)
58+
{
59+
// noop
60+
}
5561
}

src/Symfony/Bundle/FrameworkBundle/Client.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,13 @@ class Client extends BaseClient
3030
private $hasPerformedRequest = false;
3131
private $profiler = false;
3232
private $reboot = true;
33-
private $testContainerId;
3433

3534
/**
3635
* {@inheritdoc}
3736
*/
38-
public function __construct(KernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null, string $testContainerId = null)
37+
public function __construct(KernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null)
3938
{
4039
parent::__construct($kernel, $server, $history, $cookieJar);
41-
$this->testContainerId = $testContainerId;
4240
}
4341

4442
/**
@@ -48,9 +46,7 @@ public function __construct(KernelInterface $kernel, array $server = array(), Hi
4846
*/
4947
public function getContainer()
5048
{
51-
$container = $this->kernel->getContainer();
52-
53-
return null !== $this->testContainerId ? $container->get($this->testContainerId) : $container;
49+
return $this->kernel->getContainer();
5450
}
5551

5652
/**

src/Symfony/Bundle/FrameworkBundle/Controller/AbstractController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Psr\Container\ContainerInterface;
1515
use Doctrine\Common\Persistence\ManagerRegistry;
16+
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1617
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;
1718
use Symfony\Component\DependencyInjection\ServiceSubscriberInterface;
1819
use Symfony\Component\Form\FormFactoryInterface;
@@ -64,7 +65,7 @@ public function setContainer(ContainerInterface $container)
6465
protected function getParameter(string $name)
6566
{
6667
if (!$this->container->has('parameter_bag')) {
67-
throw new \LogicException('The "parameter_bag" service is not available. Try running "composer require dependency-injection:^4.1"');
68+
throw new ServiceNotFoundException('parameter_bag', null, null, array(), sprintf('The "%s::getParameter()" method is missing a parameter bag to work properly. Did you forget to register your controller as a service subscriber? This can be fixed either by using autoconfiguration or by manually wiring a "parameter_bag" in the service locator passed to the controller.', get_class($this)));
6869
}
6970

7071
return $this->container->get('parameter_bag')->get($name);

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TestServiceContainerRealRefPass.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@ class TestServiceContainerRealRefPass implements CompilerPassInterface
2222
{
2323
public function process(ContainerBuilder $container)
2424
{
25-
if (!$container->hasDefinition('test.service_container')) {
25+
if (!$container->hasDefinition('test.private_services_locator')) {
2626
return;
2727
}
2828

29-
$testContainer = $container->getDefinition('test.service_container');
30-
$privateContainer = $testContainer->getArgument(2);
31-
if ($privateContainer instanceof Reference) {
32-
$privateContainer = $container->getDefinition((string) $privateContainer);
33-
}
29+
$privateContainer = $container->getDefinition('test.private_services_locator');
3430
$definitions = $container->getDefinitions();
3531
$privateServices = $privateContainer->getArgument(0);
3632

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Compiler/TestServiceContainerWeakRefPass.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TestServiceContainerWeakRefPass implements CompilerPassInterface
2323
{
2424
public function process(ContainerBuilder $container)
2525
{
26-
if (!$container->hasDefinition('test.service_container')) {
26+
if (!$container->hasDefinition('test.private_services_locator')) {
2727
return;
2828
}
2929

@@ -50,7 +50,7 @@ public function process(ContainerBuilder $container)
5050
}
5151

5252
if ($privateServices) {
53-
$definitions[(string) $definitions['test.service_container']->getArgument(2)]->replaceArgument(0, $privateServices);
53+
$definitions['test.private_services_locator']->replaceArgument(0, $privateServices);
5454
}
5555
}
5656
}

src/Symfony/Bundle/FrameworkBundle/FrameworkBundle.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\TestServiceContainerRealRefPass;
2828
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\UnusedTagsPass;
2929
use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\WorkflowGuardListenerPass;
30-
use Symfony\Component\Console\Application;
3130
use Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass;
3231
use Symfony\Component\HttpKernel\DependencyInjection\ControllerArgumentValueResolverPass;
3332
use Symfony\Component\HttpKernel\DependencyInjection\LoggerPass;
@@ -137,9 +136,4 @@ private function addCompilerPassIfExists(ContainerBuilder $container, $class, $t
137136
$container->addCompilerPass(new $class(), $type, $priority);
138137
}
139138
}
140-
141-
public function registerCommands(Application $application)
142-
{
143-
// noop
144-
}
145139
}

src/Symfony/Bundle/FrameworkBundle/Resources/config/test.xml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
<argument>%test.client.parameters%</argument>
1717
<argument type="service" id="test.client.history" />
1818
<argument type="service" id="test.client.cookiejar" />
19-
<argument>test.service_container</argument>
2019
</service>
2120

2221
<service id="test.client.history" class="Symfony\Component\BrowserKit\History" shared="false" />
@@ -36,13 +35,12 @@
3635
</service>
3736

3837
<service id="test.service_container" class="Symfony\Bundle\FrameworkBundle\Test\TestContainer" public="true">
39-
<argument type="service" id="parameter_bag" on-invalid="null" />
40-
<argument type="service" id="service_container" />
41-
<argument type="service">
42-
<service class="Symfony\Component\DependencyInjection\ServiceLocator">
43-
<argument type="collection" />
44-
</service>
45-
</argument>
38+
<argument type="service" id="kernel" />
39+
<argument>test.private_services_locator</argument>
40+
</service>
41+
42+
<service id="test.private_services_locator" class="Symfony\Component\DependencyInjection\ServiceLocator" public="true">
43+
<argument type="collection" />
4644
</service>
4745
</services>
4846
</container>

src/Symfony/Bundle/FrameworkBundle/Test/TestContainer.php

Lines changed: 63 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,95 +11,140 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Test;
1313

14-
use Psr\Container\ContainerInterface as PsrContainerInterface;
1514
use Symfony\Component\DependencyInjection\Container;
16-
use Symfony\Component\DependencyInjection\ContainerInterface as SymfonyContainerInterface;
17-
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
15+
use Symfony\Component\HttpKernel\KernelInterface;
1816

1917
/**
2018
* @author Nicolas Grekas <[email protected]>
19+
*
20+
* @internal
2121
*/
2222
class TestContainer extends Container
2323
{
24-
private $publicContainer;
25-
private $privateContainer;
24+
private $kernel;
25+
private $privateServicesLocatorId;
2626

27-
public function __construct(?ParameterBagInterface $parameterBag, SymfonyContainerInterface $publicContainer, PsrContainerInterface $privateContainer)
27+
public function __construct(KernelInterface $kernel, string $privateServicesLocatorId)
2828
{
29-
$this->parameterBag = $parameterBag ?? $publicContainer->getParameterBag();
30-
$this->publicContainer = $publicContainer;
31-
$this->privateContainer = $privateContainer;
29+
$this->kernel = $kernel;
30+
$this->privateServicesLocatorId = $privateServicesLocatorId;
3231
}
3332

3433
/**
3534
* {@inheritdoc}
3635
*/
3736
public function compile()
3837
{
39-
$this->publicContainer->compile();
38+
$this->getPublicContainer()->compile();
4039
}
4140

4241
/**
4342
* {@inheritdoc}
4443
*/
4544
public function isCompiled()
4645
{
47-
return $this->publicContainer->isCompiled();
46+
return $this->getPublicContainer()->isCompiled();
47+
}
48+
49+
/**
50+
* {@inheritdoc}
51+
*/
52+
public function getParameterBag()
53+
{
54+
return $this->getPublicContainer()->getParameterBag();
55+
}
56+
57+
/**
58+
* {@inheritdoc}
59+
*/
60+
public function getParameter($name)
61+
{
62+
return $this->getPublicContainer()->getParameter($name);
63+
}
64+
65+
/**
66+
* {@inheritdoc}
67+
*/
68+
public function hasParameter($name)
69+
{
70+
return $this->getPublicContainer()->hasParameter($name);
71+
}
72+
73+
/**
74+
* {@inheritdoc}
75+
*/
76+
public function setParameter($name, $value)
77+
{
78+
$this->getPublicContainer()->setParameter($name, $value);
4879
}
4980

5081
/**
5182
* {@inheritdoc}
5283
*/
5384
public function set($id, $service)
5485
{
55-
$this->publicContainer->set($id, $service);
86+
$this->getPublicContainer()->set($id, $service);
5687
}
5788

5889
/**
5990
* {@inheritdoc}
6091
*/
6192
public function has($id)
6293
{
63-
return $this->publicContainer->has($id) || $this->privateContainer->has($id);
94+
return $this->getPublicContainer()->has($id) || $this->getPrivateContainer()->has($id);
6495
}
6596

6697
/**
6798
* {@inheritdoc}
6899
*/
69100
public function get($id, $invalidBehavior = /* self::EXCEPTION_ON_INVALID_REFERENCE */ 1)
70101
{
71-
return $this->privateContainer->has($id) ? $this->privateContainer->get($id) : $this->publicContainer->get($id, $invalidBehavior);
102+
return $this->getPrivateContainer()->has($id) ? $this->getPrivateContainer()->get($id) : $this->getPublicContainer()->get($id, $invalidBehavior);
72103
}
73104

74105
/**
75106
* {@inheritdoc}
76107
*/
77108
public function initialized($id)
78109
{
79-
return $this->publicContainer->initialized($id);
110+
return $this->getPublicContainer()->initialized($id);
80111
}
81112

82113
/**
83114
* {@inheritdoc}
84115
*/
85116
public function reset()
86117
{
87-
$this->publicContainer->reset();
118+
$this->getPublicContainer()->reset();
88119
}
89120

90121
/**
91122
* {@inheritdoc}
92123
*/
93124
public function getServiceIds()
94125
{
95-
return $this->publicContainer->getServiceIds();
126+
return $this->getPublicContainer()->getServiceIds();
96127
}
97128

98129
/**
99130
* {@inheritdoc}
100131
*/
101132
public function getRemovedIds()
102133
{
103-
return $this->publicContainer->getRemovedIds();
134+
return $this->getPublicContainer()->getRemovedIds();
135+
}
136+
137+
private function getPublicContainer()
138+
{
139+
if (null === $container = $this->kernel->getContainer()) {
140+
throw new \LogicException('Cannot access the container on a non-booted kernel. Did you forget to boot it?');
141+
}
142+
143+
return $container;
144+
}
145+
146+
private function getPrivateContainer()
147+
{
148+
return $this->getPublicContainer()->get($this->privateServicesLocatorId);
104149
}
105150
}

src/Symfony/Bundle/FrameworkBundle/Tests/Controller/AbstractControllerTest.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,32 @@ public function testSubscribedServices()
5252

5353
public function testGetParameter()
5454
{
55+
if (!class_exists(ContainerBag::class)) {
56+
$this->markTestSkipped('ContainerBag class does not exist');
57+
}
58+
5559
$container = new Container(new FrozenParameterBag(array('foo' => 'bar')));
60+
$container->set('parameter_bag', new ContainerBag($container));
5661

5762
$controller = $this->createController();
5863
$controller->setContainer($container);
5964

60-
if (!class_exists(ContainerBag::class)) {
61-
$this->expectException(\LogicException::class);
62-
$this->expectExceptionMessage('The "parameter_bag" service is not available. Try running "composer require dependency-injection:^4.1"');
63-
} else {
64-
$container->set('parameter_bag', new ContainerBag($container));
65-
}
66-
6765
$this->assertSame('bar', $controller->getParameter('foo'));
6866
}
67+
68+
/**
69+
* @expectedException \Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException
70+
* @expectedExceptionMessage TestAbstractController::getParameter()" method is missing a parameter bag
71+
*/
72+
public function testMissingParameterBag()
73+
{
74+
$container = new Container();
75+
76+
$controller = $this->createController();
77+
$controller->setContainer($container);
78+
79+
$controller->getParameter('foo');
80+
}
6981
}
7082

7183
class TestAbstractController extends AbstractController

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ContainerDumpTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ public function testContainerCompilationInDebug()
2020
{
2121
$client = $this->createClient(array('test_case' => 'ContainerDump', 'root_config' => 'config.yml'));
2222

23-
$this->assertTrue($client->getContainer()->has('serializer'));
23+
$this->assertTrue(static::$container->has('serializer'));
2424
}
2525

2626
public function testContainerCompilation()
2727
{
2828
$client = $this->createClient(array('test_case' => 'ContainerDump', 'root_config' => 'config.yml', 'debug' => false));
2929

30-
$this->assertTrue($client->getContainer()->has('serializer'));
30+
$this->assertTrue(static::$container->has('serializer'));
3131
}
3232
}

0 commit comments

Comments
 (0)