ClientTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\Tests\Component\HttpKernel;
  11. use Symfony\Component\HttpKernel\Client;
  12. use Symfony\Component\HttpKernel\HttpKernel;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\EventDispatcher\EventDispatcher;
  16. use Symfony\Component\EventDispatcher\Event;
  17. require_once __DIR__.'/TestHttpKernel.php';
  18. class TestClient extends Client
  19. {
  20. protected function getScript($request)
  21. {
  22. $script = parent::getScript($request);
  23. $script = preg_replace('/(\->register\(\);)/', "$0\nrequire_once '".__DIR__."/TestHttpKernel.php';", $script);
  24. return $script;
  25. }
  26. }
  27. class ClientTest extends \PHPUnit_Framework_TestCase
  28. {
  29. public function testDoRequest()
  30. {
  31. $client = new Client(new TestHttpKernel());
  32. $client->request('GET', '/');
  33. $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
  34. $client->request('GET', 'http://www.example.com/');
  35. $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
  36. $this->assertEquals('www.example.com', $client->getRequest()->getHost(), '->doRequest() uses the request handler to make the request');
  37. }
  38. public function testGetScript()
  39. {
  40. $client = new TestClient(new TestHttpKernel());
  41. $client->insulate();
  42. $client->request('GET', '/');
  43. $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->getScript() returns a script that uses the request handler to make the request');
  44. }
  45. }