/** * @param Link $link * * @return \stdClass */ public function buildMetaLink($output, Link $link) { $name = $link->getName(); $output->{$name} = new \stdClass(); $output->{$name}->href = $link->getHref(); $output->{$name}->meta = (object) $link->getMeta(); return $output; }
public function it_can_add_next_link() { $this->addNext('http://yolo'); $this->getLinks()->shouldBeArray(); $this->getLinks()->shouldHaveCount(1); $this->hasLink(Link::createNext('http://yolo')); }
public function it_can_get_output(Input $pagination) { $this->beConstructedWith($pagination); $pag = new \stdClass(); $pag->first = 'http://yolo.com'; $pag->last = 'http://yolo.com'; $pagination->getLinks()->willReturn([Link::createFirst('http://yolo.com'), Link::createLast('http://yolo.com')]); $this->getOutput()->shouldObjectMatch($pag); }
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"}}}}'); }
public function it_can_add_a_named_link(Link $link) { $link->beConstructedWith(['name', 'http://yolo']); $this->addLink($link); $this->hasLink($link)->shouldReturn(true); }
/** * @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_must_pass_link_collection() { $this->shouldThrow(\Exception::class)->duringInstantiation(Link::createFirst('http')); }
public function addNext($href) { $this->addLink(Link::createNext($href)); }
public function it_cannot_add_other_links() { $link = Link::createNext('http://yolo.com'); $this->shouldThrow(\Exception::class)->duringAddAboutLink($link); }
/** * @param $output * @param Link $link * * @return \stdClass */ public function buildSimpleLink($output, Link $link) { $name = $link->getName(); $output->{$name} = $link->getHref(); return $output; }