/** * @param \stdClass $obj * @param array $context * @return TwitterEntities */ public function unserialize($obj, array $context = []) { Assertion::true($this->canUnserialize($obj), 'object is not unserializable'); // Hashtags $hashtags = []; if (isset($obj->hashtags)) { foreach ($obj->hashtags as $hashtag) { $hashtags[] = $this->hashtagSerializer->unserialize($hashtag); } } // Symbols $symbols = []; if (isset($obj->symbols)) { foreach ($obj->symbols as $symbol) { $symbols[] = $this->symbolSerializer->unserialize($symbol); } } // URLs $urls = []; if (isset($obj->urls)) { foreach ($obj->urls as $url) { $urls[] = $this->urlSerializer->unserialize($url); } } // User mentions $userMentions = []; if (isset($obj->user_mentions)) { foreach ($obj->user_mentions as $userMention) { $userMentions[] = $this->userMentionSerializer->unserialize($userMention); } } // Media $media = []; if (isset($obj->media)) { foreach ($obj->media as $medium) { $media[] = $this->mediaSerializer->unserialize($medium); } } // Extended entities $extendedEntities = []; if (isset($obj->extended_entities)) { foreach ($obj->extended_entities as $extendedEntity) { $extendedEntities[] = $this->extendedEntitySerializer->unserialize($extendedEntity); } } return TwitterEntities::create($hashtags, $userMentions, $urls, $media, $symbols, $extendedEntities); }
/** * @test */ public function itShouldNotUnserializeIllegalObject() { $this->setExpectedException(\InvalidArgumentException::class); $this->serviceUnderTest->unserialize($this->getInvalidSerializedObject()); }