function it_throws_session_unavailable_exception_when_it_listens_cookie_event(CookieEvent $cookieEvent, SessionInterface $session)
 {
     $cookieEvent->getSession()->shouldBeCalled()->willReturn($session);
     $session->has('access_token')->shouldBeCalled()->willReturn(true);
     $session->has('refresh_token')->shouldBeCalled()->willReturn(false);
     $this->shouldThrow(new SessionUnavailableException())->during('onCookieEvent', [$cookieEvent]);
 }
Exemplo n.º 2
0
 /**
  * Checks if the session has the tokens to create cookies that will be add into response.
  *
  * @param \Kreta\Bundle\UserBundle\Event\CookieEvent $event The cookie event
  */
 public function onCookieEvent(CookieEvent $event)
 {
     $session = $event->getSession();
     if (!$session->has('access_token') || !$session->has('refresh_token')) {
         throw new SessionUnavailableException();
     }
     $event->getResponse()->headers->setCookie($this->cookie('access_token', $session->get('access_token')));
     $event->getResponse()->headers->setCookie($this->cookie('refresh_token', $session->get('refresh_token')));
 }