菜谱项目

RequestStackTest.php 2.0KB

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