RequestStackTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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\Component\HttpFoundation\Tests;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\RequestStack;
  13. class RequestStackTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testGetCurrentRequest()
  16. {
  17. $requestStack = new RequestStack();
  18. $this->assertNull($requestStack->getCurrentRequest());
  19. $request = Request::create('/foo');
  20. $requestStack->push($request);
  21. $this->assertSame($request, $requestStack->getCurrentRequest());
  22. $this->assertSame($request, $requestStack->pop());
  23. $this->assertNull($requestStack->getCurrentRequest());
  24. $this->assertNull($requestStack->pop());
  25. }
  26. public function testGetMasterRequest()
  27. {
  28. $requestStack = new RequestStack();
  29. $this->assertNull($requestStack->getMasterRequest());
  30. $masterRequest = Request::create('/foo');
  31. $subRequest = Request::create('/bar');
  32. $requestStack->push($masterRequest);
  33. $requestStack->push($subRequest);
  34. $this->assertSame($masterRequest, $requestStack->getMasterRequest());
  35. }
  36. public function testGetParentRequest()
  37. {
  38. $requestStack = new RequestStack();
  39. $this->assertNull($requestStack->getParentRequest());
  40. $masterRequest = Request::create('/foo');
  41. $requestStack->push($masterRequest);
  42. $this->assertNull($requestStack->getParentRequest());
  43. $firstSubRequest = Request::create('/bar');
  44. $requestStack->push($firstSubRequest);
  45. $this->assertSame($masterRequest, $requestStack->getParentRequest());
  46. $secondSubRequest = Request::create('/baz');
  47. $requestStack->push($secondSubRequest);
  48. $this->assertSame($firstSubRequest, $requestStack->getParentRequest());
  49. }
  50. }