RequestDataCollectorTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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\DataCollector;
  11. use Symfony\Component\HttpKernel\DataCollector\RequestDataCollector;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpFoundation\Cookie;
  15. class RequestDataCollectorTest extends \PHPUnit_Framework_TestCase
  16. {
  17. /**
  18. * @dataProvider provider
  19. */
  20. public function testCollect(Request $request, Response $response)
  21. {
  22. $c = new RequestDataCollector();
  23. $c->collect($request, $response);
  24. $this->assertSame('request',$c->getName());
  25. $this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag',$c->getRequestHeaders());
  26. $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestServer());
  27. $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestCookies());
  28. $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestAttributes());
  29. $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestRequest());
  30. $this->assertInstanceOf('Symfony\Component\HttpFoundation\ParameterBag',$c->getRequestQuery());
  31. $this->assertEquals('html',$c->getFormat());
  32. $this->assertEquals(array(),$c->getSessionAttributes());
  33. $this->assertInstanceOf('Symfony\Component\HttpFoundation\HeaderBag',$c->getResponseHeaders());
  34. $this->assertEquals(200,$c->getStatusCode());
  35. $this->assertEquals('application/json',$c->getContentType());
  36. }
  37. public function provider()
  38. {
  39. $request = Request::create('http://test.com/foo?bar=baz');
  40. $request->attributes->set('foo', 'bar');
  41. $response = new Response();
  42. $response->setStatusCode(200);
  43. $response->headers->set('Content-Type', 'application/json');
  44. $response->headers->setCookie(new Cookie('foo','bar',1,'/foo','localhost',true,true));
  45. $response->headers->setCookie(new Cookie('bar','foo',new \DateTime('@946684800')));
  46. $response->headers->setCookie(new Cookie('bazz','foo','2000-12-12'));
  47. return array(
  48. array($request,$response)
  49. );
  50. }
  51. }