8000 [FrameworkBundle] Fix using test.service_container when Client is reb… · symfony/symfony@169a3b1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 169a3b1

Browse files
[FrameworkBundle] Fix using test.service_container when Client is rebooted
1 parent 930b960 commit 169a3b1

File tree

11 files changed

+25
-38
lines changed

11 files changed

+25
-38
lines changed

src/Symfony/Bundle/FrameworkBundle/Client.php

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

3535
/**
3636
* {@inheritdoc}
3737
*/
38-
public function __construct(KernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null, ContainerInterface $container = null)
38+
public function __construct(KernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null, string $testContainerId = null)
3939
{
4040
parent::__construct($kernel, $server, $history, $cookieJar);
41-
$this->container = $container;
41+
$this->testContainerId = $testContainerId;
4242
}
4343

4444
/**
@@ -48,7 +48,9 @@ public function __construct(KernelInterface $kernel, array $server = array(), Hi
4848
*/
4949
public function getContainer()
5050
{
51-
return $this->container ?? $this->kernel->getContainer();
51+
$container = $this->kernel->getContainer();
52+
53+
return null !== $this->testContainerId ? $container->get($this->testContainerId) : $container;
5254
}
5355

5456
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<argument>%test.client.parameters%</argument>
1717
<argument type="service" id="test.client.history" />
1818
<argument type="service" id="test.client.cookiejar" />
19-
<argument type="service" id="test.service_container" />
19+
<argument>test.service_container</argument>
2020
</service>
2121

2222
<service id="test.client.history" class="Symfony\Component\BrowserKit\History" shared="false" />

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,52 +24,46 @@ class AutowiringTypesTest extends WebTestCase
2424
public function testAnnotationReaderAutowiring()
2525
{
2626
static::bootKernel(array('root_config' => 'no_annotations_cache.yml', 'environment' => 'no_annotations_cache'));
27-
$container = static::$kernel->getContainer();
2827

29-
$annotationReader = $container->get('test.autowiring_types.autowired_services')->getAnnotationReader();
28+
$annotationReader = static::$container->get('test.autowiring_types.autowired_services')->getAnnotationReader();
3029
$this->assertInstanceOf(AnnotationReader::class, $annotationReader);
3130
}
3231

3332
public function testCachedAnnotationReaderAutowiring()
3433
{
3534
static::bootKernel();
36-
$container = static::$kernel->getContainer();
3735

38-
$annotationReader = $container->get('test.autowiring_types.autowired_services')->getAnnotationReader();
36+
$annotationReader = static::$container->get('test.autowiring_types.autowired_services')->getAnnotationReader();
3937
$this->assertInstanceOf(CachedReader::class, $annotationReader);
4038
}
4139

4240
public function testTemplatingAutowiring()
4341
{
4442
static::bootKernel();
45-
$container = static::$kernel->getContainer();
4643

47-
$autowiredServices = $container->get('test.autowiring_types.autowired_services');
44+
$autowiredServices = static::$container->get('test.autowiring_types.autowired_services');
4845
$this->assertInstanceOf(FrameworkBundleEngineInterface::class, $autowiredServices->getFrameworkBundleEngine());
4946
$this->assertInstanceOf(ComponentEngineInterface::class, $autowiredServices->getEngine());
5047
}
5148

5249
public function testEventDispatcherAutowiring()
5350
{
5451
static::bootKernel(array('debug' => false));
55-
$container = static::$kernel->getContainer();
5652

57-
$autowiredServices = $container->get('test.autowiring_types.autowired_services');
53+
$autowiredServices = static::$container->get('test.autowiring_types.autowired_services');
5854
$this->assertInstanceOf(EventDispatcher::class, $autowiredServices->getDispatcher(), 'The event_dispatcher service should be injected if the debug is not enabled');
5955

6056
static::bootKernel(array('debug' => true));
61-
$container = static::$kernel->getContainer();
6257

63-
$autowiredServices = $container->get('test.autowiring_types.autowired_services');
58+
$autowiredServices = static::$container->get('test.autowiring_types.autowired_services');
6459
$this->assertInstanceOf(TraceableEventDispatcher::class, $autowiredServices->getDispatcher(), 'The debug.event_dispatcher service should be injected if the debug is enabled');
6560
}
6661

6762
public function testCacheAutowiring()
6863
{
6964
static::bootKernel();
70-
$container = static::$kernel->getContainer();
7165

72-
$autowiredServices = $container->get('test.autowiring_types.autowired_services');
66+
$autowiredServices = static::$container->get('test.autowiring_types.autowired_services');
7367
$this->assertInstanceOf(FilesystemAdapter::class, $autowiredServices->getCachePool());
7468
}
7569

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ public function testClearUnexistingPool()
7777

7878
private function createCommandTester()
7979
{
80-
$container = static::$kernel->getContainer();
8180
$application = new Application(static::$kernel);
82-
$application->add(new CachePoolClearCommand($container->get('cache.global_clearer')));
81+
$application->add(new CachePoolClearCommand(static::$container->get('cache.global_clearer')));
8382

8483
return new CommandTester($application->find('cache:pool:clear'));
8584
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testRedisCustomCachePools()
7070
private function doTestCachePools($options, $adapterClass)
7171
{
7272
static::bootKernel($options);
73-
$container = static::$kernel->getContainer();
73+
$container = static::$container;
7474

7575
$pool1 = $container->get('cache.pool1');
7676
$this->assertInstanceOf($adapterClass, $pool1);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ public function testDumpContainerIfNotExists()
2626
$application = new Application(static::$kernel);
2727
$application->setAutoExit(false);
2828

29-
@unlink(static::$kernel->getContainer()->getParameter('debug.container.dump'));
29+
@unlink(static::$container->getParameter('debug.container.dump'));
3030

3131
$tester = new ApplicationTester($application);
3232
$tester->run(array('command' => 'debug:container'));
3333

34-
$this->assertFileExists(static::$kernel->getContainer()->getParameter('debug.container.dump'));
34+
$this->assertFileExists(static::$container->getParameter('debug.container.dump'));
3535
}
3636

3737
public function testNoDebug()

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,8 @@ class SerializerTest extends WebTestCase
1919
public function testDeserializeArrayOfObject()
2020
{
2121
static::bootKernel(array('test_case' => 'Serializer'));
22-
$container = static::$kernel->getContainer();
2322

24-
$result = $container->get('serializer')->deserialize('{"bars": [{"id": 1}, {"id": 2}]}', Foo::class, 'json');
23+
$result = static::$container->get('serializer')->deserialize('{"bars": [{"id": 1}, {"id": 2}]}', Foo::class, 'json');
2524

2625
$bar1 = new Bar();
2726
$bar1->id = 1;

src/Symfony/Bundle/SecurityBundle/Tests/Functional/AutowiringTypesTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ class AutowiringTypesTest extends WebTestCase
1919
public function testAccessDecisionManagerAutowiring()
2020
{
2121
static::bootKernel(array('debug' => false));
22-
$container = static::$kernel->getContainer();
2322

24-
$autowiredServices = $container->get('test.autowiring_types.autowired_services');
23+
$autowiredServices = static::$container->get('test.autowiring_types.autowired_services');
2524
$this->assertInstanceOf(AccessDecisionManager::class, $autowiredServices->getAccessDecisionManager(), 'The security.access.decision_manager service should be injected in debug mode');
2625

2726
static::bootKernel(array('debug' => true));
28-
$container = static::$kernel->getContainer();
2927

30-
$autowiredServices = $container->get('test.autowiring_types.autowired_services');
28+
$autowiredServices = static::$container->get('test.autowiring_types.autowired_services');
3129
$this->assertInstanceOf(TraceableAccessDecisionManager::class, $autowiredServices->getAccessDecisionManager(), 'The debug.security.access.decision_manager service should be injected in non-debug mode');
3230
}
3331

src/Symfony/Bundle/SecurityBundle/Tests/Functional/LogoutTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ public function testSessionLessRememberMeLogout()
3535
public function testCsrfTokensAreClearedOnLogout()
3636
{
3737
$client = $this->createClient(array('test_case' => 'LogoutWithoutSessionInvalidation', 'root_config' => 'config.yml'));
38-
static::$kernel->getContainer()->get('test.security.csrf.token_storage')->setToken('foo', 'bar');
38+
$client->getContainer()->get('security.csrf.token_storage')->setToken('foo', 'bar');
3939

4040
$client->request('POST', '/login', array(
4141
'_username' => 'johannes',
4242
'_password' => 'test',
4343
));
4444

45-
$this->assertTrue(static::$kernel->getContainer()->get('test.security.csrf.token_storage')->hasToken('foo'));
46-
$this->assertSame('bar', static::$kernel->getContainer()->get('test.security.csrf.token_storage')->getToken('foo'));
45+
$this->assertTrue($client->getContainer()->get('security.csrf.token_storage')->hasToken('foo'));
46+
$this->assertSame('bar', $client->getContainer()->get('security.csrf.token_storage')->getToken('foo'));
4747

4848
$client->request('GET', '/logout');
4949

50-
$this->assertFalse(static::$kernel->getContainer()->get('test.security.csrf.token_storage')->hasToken('foo'));
50+
$this->assertFalse($client->getContainer()->get('security.csrf.token_storage')->hasToken('foo'));
5151
}
5252
}

src/Symfony/Bundle/SecurityBundle/Tests/Functional/app/LogoutWithoutSessionInvalidation/config.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
imports:
22
- { resource: ./../config/framework.yml }
33

4-
services:
5-
test.security.csrf.token_storage:
6-
alias: security.csrf.token_storage
7-
public: true
8-
94
security:
105
encoders:
116
Symfony\Component\Security\Core\User\User: plaintext

src/Symfony/Bundle/SecurityBundle/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"symfony/security": "4.1.0-beta1|4.1.0-beta2",
4848
"symfony/var-dumper": "<3.4",
4949
"symfony/event-dispatcher": "<3.4",
50-
"symfony/framework-bundle": "<4.1",
50+
"symfony/framework-bundle": "<=4.1-beta2",
5151
"symfony/console": "<3.4"
5252
},
5353
"autoload": {

0 commit comments

Comments
 (0)
0