ClientTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Bundle\FrameworkBundle\Tests;
  11. use Symfony\Bundle\FrameworkBundle\Client;
  12. use Symfony\Bundle\FrameworkBundle\Tests\Functional\WebTestCase;
  13. use Symfony\Component\HttpFoundation\Response;
  14. class ClientTest extends WebTestCase
  15. {
  16. public function testRebootKernelBetweenRequests()
  17. {
  18. $mock = $this->getKernelMock();
  19. $mock->expects($this->once())->method('shutdown');
  20. $client = new Client($mock);
  21. $client->request('GET', '/');
  22. $client->request('GET', '/');
  23. }
  24. public function testDisabledRebootKernel()
  25. {
  26. $mock = $this->getKernelMock();
  27. $mock->expects($this->never())->method('shutdown');
  28. $client = new Client($mock);
  29. $client->disableReboot();
  30. $client->request('GET', '/');
  31. $client->request('GET', '/');
  32. }
  33. public function testEnableRebootKernel()
  34. {
  35. $mock = $this->getKernelMock();
  36. $mock->expects($this->once())->method('shutdown');
  37. $client = new Client($mock);
  38. $client->disableReboot();
  39. $client->request('GET', '/');
  40. $client->request('GET', '/');
  41. $client->enableReboot();
  42. $client->request('GET', '/');
  43. }
  44. private function getKernelMock()
  45. {
  46. $mock = $this->getMockBuilder($this->getKernelClass())
  47. ->setMethods(array('shutdown', 'boot', 'handle'))
  48. ->disableOriginalConstructor()
  49. ->getMock();
  50. $mock->expects($this->any())->method('handle')->willReturn(new Response('foo'));
  51. return $mock;
  52. }
  53. }