/** * @param \stdClass $obj * @param array $context * @return TwitterEvent */ public function unserialize($obj, array $context = []) { Assertion::true($this->canUnserialize($obj), 'object is not unserializable'); $createdAt = new \DateTimeImmutable($obj->created_at); Assertion::eq(new \DateTimeZone('UTC'), $createdAt->getTimezone()); return TwitterEvent::create($obj->event, $this->userSerializer->unserialize($obj->source), isset($obj->target) ? $this->userSerializer->unserialize($obj->target) : null, isset($obj->target_object) ? $this->targetSerializer->unserialize($obj->target_object) : null, $createdAt); }
/** * @test */ public function itShouldBuildTheObject() { $event = TwitterEvent::create($this->type, $this->source, $this->target, $this->object, $this->date); $this->targetObjectWillStringify(); $this->assertEquals($this->type, $event->getType()); $this->assertEquals($this->source, $event->getSource()); $this->assertEquals($this->target, $event->getTarget()); $this->assertEquals($this->object, $event->getObject()); $this->assertEquals($this->date, $event->getDate()); $this->assertEquals('Event [' . $this->type . ']: ' . $this->stringifiedTargetObject, (string) $event); }
/** * @return TwitterEvent */ private function getEvent() { return TwitterEvent::create($this->type, $this->source, $this->target, $this->targetObject, $this->date); }