PageRenderTime 56ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/symfony/symfony/src/Symfony/Component/Security/Http/Tests/RememberMe/ResponseListenerTest.php

https://gitlab.com/Marwamimo/Crowdrise_Web
PHP | 85 lines | 57 code | 20 blank | 8 comment | 0 complexity | 206ecb1e864746dcda3d41c0a4717f97 MD5 | raw file
  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\Security\Http\Tests\RememberMe;
  11. use Symfony\Component\Security\Http\RememberMe\ResponseListener;
  12. use Symfony\Component\Security\Http\RememberMe\RememberMeServicesInterface;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Cookie;
  15. use Symfony\Component\HttpKernel\KernelEvents;
  16. class ResponseListenerTest extends \PHPUnit_Framework_TestCase
  17. {
  18. public function testRememberMeCookieIsSentWithResponse()
  19. {
  20. $cookie = new Cookie('rememberme');
  21. $request = $this->getRequest(array(
  22. RememberMeServicesInterface::COOKIE_ATTR_NAME => $cookie,
  23. ));
  24. $response = $this->getResponse();
  25. $response->headers->expects($this->once())->method('setCookie')->with($cookie);
  26. $listener = new ResponseListener();
  27. $listener->onKernelResponse($this->getEvent($request, $response));
  28. }
  29. public function testRememberMeCookieIsNotSendWithResponse()
  30. {
  31. $request = $this->getRequest();
  32. $response = $this->getResponse();
  33. $response->headers->expects($this->never())->method('setCookie');
  34. $listener = new ResponseListener();
  35. $listener->onKernelResponse($this->getEvent($request, $response));
  36. }
  37. public function testItSubscribesToTheOnKernelResponseEvent()
  38. {
  39. $listener = new ResponseListener();
  40. $this->assertSame(array(KernelEvents::RESPONSE => 'onKernelResponse'), ResponseListener::getSubscribedEvents());
  41. }
  42. private function getRequest(array $attributes = array())
  43. {
  44. $request = new Request();
  45. foreach ($attributes as $name => $value) {
  46. $request->attributes->set($name, $value);
  47. }
  48. return $request;
  49. }
  50. private function getResponse()
  51. {
  52. $response = $this->getMock('Symfony\Component\HttpFoundation\Response');
  53. $response->headers = $this->getMock('Symfony\Component\HttpFoundation\ResponseHeaderBag');
  54. return $response;
  55. }
  56. private function getEvent($request, $response)
  57. {
  58. $event = $this->getMockBuilder('Symfony\Component\HttpKernel\Event\FilterResponseEvent')
  59. ->disableOriginalConstructor()
  60. ->getMock();
  61. $event->expects($this->any())->method('getRequest')->will($this->returnValue($request));
  62. $event->expects($this->any())->method('getResponse')->will($this->returnValue($response));
  63. return $event;
  64. }
  65. }