Reputation: 340
I'm writing functional tests for my Symfony3 application. I have a test which looks like this:
public function testList()
{
$client = static::createClient();
$client->getCookieJar()->set($this->cookie);
$this->sender->method('isSuccessfull')->will($this->returnValue(true));
$container = $client->getContainer();
$container->set('app.service1', $this->object1);
$container->set('app.service2', $this->object2);
$crawler = $client->request('GET', '/list/1');
$form = $crawler->selectButton('Save')->form();
$client->submit($form);
}
Everything is good until submitting form. Kernel losing the setted container services while submitting a form. How can I these services into container also after submitting a form? Maybe there is other option to resolve my problem?
Upvotes: 2
Views: 222
Reputation: 96889
If you check the source code for Symfony\Component\HttpKernel\Client::doRequest()
class you can see that it terminates the kernel which is then started again later and that's why you loose all service you created manually.
I guess you have an app which you're testing so you could add the services to its services.yml
. Another way could be extending the Client
class with your own and overriding getContainer()
method to always add these extra services (then you'd have to update the service definition for test.client
in a compile pass with your customized class).
Upvotes: 1