/** * @return \stdClass */ public function getOutput() { $output = new \stdClass(); foreach ($this->resource->getLinks() as $link) { if ($link->getMeta()) { $this->buildMetaLink($output, $link); } else { $this->buildSimpleLink($output, $link); } } return $output; }
public function it_can_get_output_with_meta_links() { $input = new LinkCollection(); $link = Link::createSelf('http://yolo'); $link->addMeta('jedi', 'yoda'); $link->addMeta('sith', 'darth vader'); $input->addLink($link); $this->beConstructedWith($input); $output = new \stdClass(); $output->self = new \stdClass(); $output->self->meta = new \stdClass(); $output->self->meta->jedi = 'yoda'; $output->self->meta->sith = 'darth vader'; $output->self->href = 'http://yolo'; $this->getOutput()->shouldObjectMatch($output); }
/** * @param Link $link * * @throws \Exception */ public function addAboutLink(Link $link) { if ($link->getName() !== 'about') { throw new \Exception('Error Objects only support "about" links'); } $this->links->addLink($link); }
public function it_can_output_link_collections_with_meta(Serializer $serializer) { $collection = new LinkCollection(); $link = Link::createSelf('http://example.com/articles/1'); $link->addMeta('jedi', 'yoda'); $collection->addLink($link); $serializer->beConstructedWith([$collection]); $this->addMember($serializer); $this->getMembers()->shouldBeArray(); $this->getMembers()->shouldContain($serializer); $serializer->getTopLevelName()->willReturn('links'); $output = new \stdClass(); $output->self = new \stdClass(); $output->self->href = 'http://example.com/articles/1'; $output->self->meta = new \stdClass(); $output->self->meta->jedi = 'yoda'; $serializer->getOutput()->willReturn($output); $this->getOutput()->shouldReturn('{"links":{"self":{"href":"http://example.com/articles/1","meta":{"jedi":"yoda"}}}}'); }