/** * * @param TimetableManagerEvent $event */ public function getTime(TimetableManagerEvent $event) { if ($this->getRequest()->getCookie()->offsetExists(self::COOKIE_NAME)) { $point = $this->getRequest()->getCookie()->offsetGet(self::COOKIE_NAME); $event->setPointInTime(new \DateTime($point)); } }
/** * Saves the current point in time for the next request * * @return TimetableManagerInterface */ public function savePointInTime() : TimetableManagerInterface { $event = new TimetableManagerEvent(); $event->setPointInTime($this->point)->setName(TimetableManagerEvents::STORE_TIME); $this->getEventManager()->trigger($event, $this); return $this; }
public function testGettersAndSetters() { $event = new TimetableManagerEvent(); $expectedPointInTime = new DateTime(); $this->assertFalse($event->hasPointInTime()); $this->assertInstanceOf(TimetableManagerEvent::class, $event->setPointInTime($expectedPointInTime)); $this->assertTrue($event->hasPointInTime()); $this->assertEquals($expectedPointInTime, $event->getPointInTime()); }
public function testSave() { $expectedDate = new \DateTime('2015-01-01'); $request = new Request('GET', 'http://example.com'); $response = new Response(); $listener = new TimetableCookieListener($request, $response); $event = new TimetableManagerEvent(); $event->setPointInTime($expectedDate); $listener->storeTime($event); $this->assertTrue($response->getHeaders()->has('Set-Cookie')); $cookie = current($response->getHeaders()->get('Set-Cookie')); $this->assertEquals($expectedDate, new \DateTime($cookie->getValue())); }