ClientTest.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. require_once __DIR__.'/TestHttpKernel.php';
  16. class TestClient extends Client
  17. {
  18. protected function getScript($request)
  19. {
  20. $script = parent::getScript($request);
  21. $script = preg_replace('/(\->register\(\);)/', "$0\nrequire_once '".__DIR__."/TestHttpKernel.php';", $script);
  22. return $script;
  23. }
  24. }
  25. class ClientTest extends \PHPUnit_Framework_TestCase
  26. {
  27. public function testDoRequest()
  28. {
  29. $client = new Client(new TestHttpKernel());
  30. $client->request('GET', '/');
  31. $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
  32. $client->request('GET', 'http://www.example.com/');
  33. $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
  34. $this->assertEquals('www.example.com', $client->getRequest()->getHost(), '->doRequest() uses the request handler to make the request');
  35. $client->request('GET', 'http://www.example.com/?parameter=http://google.com');
  36. $this->assertEquals('http://www.example.com/?parameter='.urlencode('http://google.com'), $client->getRequest()->getUri(), '->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. }