8000 [FrameworkBundle] Fix using test.service_container when Client is rebooted by nicolas-grekas · Pull Request #27379 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Fix using test.service_container when Client is rebooted #27379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Symfony/Bundle/FrameworkBundle/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class Client extends BaseClient
private $hasPerformedRequest = false;
private $profiler = false;
private $reboot = true;
private $container;
private $testContainerId;

/**
* {@inheritdoc}
*/
public function __construct(KernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null, ContainerInterface $container = null)
public function __construct(KernelInterface $kernel, array $server = array(), History $history = null, CookieJar $cookieJar = null, string $testContainerId = null)
{
parent::__construct($kernel, $server, $history, $cookieJar);
$this->container = $container;
$this->testContainerId = $testContainerId;
}

/**
Expand All @@ -48,7 +48,9 @@ public function __construct(KernelInterface $kernel, array $server = array(), Hi
*/
public function getContainer()
{
return $this->container ?? $this->kernel->getContainer();
$container = $this->kernel->getContainer();

return null !== $this->testContainerId ? $container->get($this->testContainerId) : $container;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<argument>%test.client.parameters%</argument>
<argument type="service" id="test.client.history" />
<argument type="service" id="test.client.cookiejar" />
<argument type="service" id="test.service_container" />
<argument>test.service_container</argument>
</service>

<service id="test.client.history" class="Symfony\Component\BrowserKit\History" shared="false" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,52 +24,46 @@ class AutowiringTypesTest extends WebTestCase
public function testAnnotationReaderAutowiring()
{
static::bootKernel(array('root_config' => 'no_annotations_cache.yml', 'environment' => 'no_annotations_cache'));
$container = static::$kernel->getContainer();

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

public function testCachedAnnotationReaderAutowiring()
{
static::bootKernel();
$container = static::$kernel->getContainer();

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

public function testTemplatingAutowiring()
{
static::bootKernel();
$container = static::$kernel->getContainer();

$autowiredServices = $container->get('test.autowiring_types.autowired_services');
$autowiredServices = static::$container->get('test.autowiring_types.autowired_services');
$this->assertInstanceOf(FrameworkBundleEngineInterface::class, $autowiredServices->getFrameworkBundleEngine());
$this->assertInstanceOf(ComponentEngineInterface::class, $autowiredServices->getEngine());
}

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

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

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

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

public function testCacheAutowiring()
{
static::bootKernel();
$container = static::$kernel->getContainer();

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ public function testClearUnexistingPool()

private function createCommandTester()
{
$container = static::$kernel->getContainer();
$application = new Application(static::$kernel);
$application->add(new CachePoolClearCommand($container->get('cache.global_clearer')));
$application->add(new CachePoolClearCommand(static::$container->get('cache.global_clearer')));

return new CommandTester($application->find('cache:pool:clear'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function testRedisCustomCachePools()
private function doTestCachePools($options, $adapterClass)
{
static::bootKernel($options);
$container = static::$kernel->getContainer();
$container = static::$container;

$pool1 = $container->get('cache.pool1');
$this->assertInstanceOf($adapterClass, $pool1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public function testDumpContainerIfNotExists()
$application = new Application(static::$kernel);
$application->setAutoExit(false);

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

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

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

public function testNoDebug()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ class SerializerTest extends WebTestCase
public function testDeserializeArrayOfObject()
{
static::bootKernel(array('test_case' => 'Serializer'));
$container = static::$kernel->getContainer();

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

$bar1 = new Bar();
$bar1->id = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,13 @@ class AutowiringTypesTest extends WebTestCase
public function testAccessDecisionManagerAutowiring()
{
static::bootKernel(array('debug' => false));
$container = static::$kernel->getContainer();

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ public function testSessionLessRememberMeLogout()
public function testCsrfTokensAreClearedOnLogout()
{
$client = $this->createClient(array('test_case' => 'LogoutWithoutSessionInvalidation', 'root_config' => 'config.yml'));
static::$kernel->getContainer()->get('test.security.csrf.token_storage')->setToken('foo', 'bar');
$client->getContainer()->get('security.csrf.token_storage')->setToken('foo', 'bar');

$client->request('POST', '/login', array(
'_username' => 'johannes',
'_password' => 'test',
));

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

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

$this->assertFalse(static::$kernel->getContainer()->get('test.security.csrf.token_storage')->hasToken('foo'));
$this->assertFalse($client->getContainer()->get('security.csrf.token_storage')->hasToken('foo'));
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
imports:
- { resource: ./../config/framework.yml }

services:
test.security.csrf.token_storage:
alias: security.csrf.token_storage
public: true

security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/SecurityBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"symfony/security": "4.1.0-beta1|4.1.0-beta2",
"symfony/var-dumper": "<3.4",
"symfony/event-dispatcher": "<3.4",
"symfony/framework-bundle": "<4.1",
"symfony/framework-bundle": "<=4.1-beta2",
"symfony/console": "<3.4"
},
"autoload": {
Expand Down
0