Questions & Feedback
Found a typo or an error?
Want to improve this document? Edit it.
Need support or have a technical question?
Post to the user mailing-list.
Master Symfony2 fundamentals
Be trained by SensioLabs experts (2 to 6 day sessions -- French or English).
trainings.sensiolabs.com
Symfony hosting done right
ServerGrove, outstanding support at the right price for your Symfony hosting needs.
servergrove.com
Discover the SensioLabs Support
Access to the SensioLabs Competency Center for an exclusive and tailor-made support on Symfony
sensiolabs.com
2.3 version
How to test the Interaction of several Clients
How to test the Interaction of several Clients¶
If you need to simulate an interaction between different Clients (think of a chat for instance), create several Clients:
1 2 3 4 5 6 7 8 | $harry = static::createClient();
$sally = static::createClient();
$harry->request('POST', '/say/sally/Hello');
$sally->request('GET', '/messages');
$this->assertEquals(201, $harry->getResponse()->getStatusCode());
$this->assertRegExp('/Hello/', $sally->getResponse()->getContent());
|
This works except when your code maintains a global state or if it depends on a third-party library that has some kind of global state. In such a case, you can insulate your clients:
1 2 3 4 5 6 7 8 9 10 11 | $harry = static::createClient();
$sally = static::createClient();
$harry->insulate();
$sally->insulate();
$harry->request('POST', '/say/sally/Hello');
$sally->request('GET', '/messages');
$this->assertEquals(201, $harry->getResponse()->getStatusCode());
$this->assertRegExp('/Hello/', $sally->getResponse()->getContent());
|
Insulated clients transparently execute their requests in a dedicated and clean PHP process, thus avoiding any side-effects.
Tip
As an insulated client is slower, you can keep one client in the main process, and insulate the other ones.





is a trademark of Fabien Potencier. All rights reserved.