Esempio n. 1
0
 /**
  * @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;
 }
Esempio n. 2
0
 public function it_can_add_next_link()
 {
     $this->addNext('http://yolo');
     $this->getLinks()->shouldBeArray();
     $this->getLinks()->shouldHaveCount(1);
     $this->hasLink(Link::createNext('http://yolo'));
 }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
 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);
 }
Esempio n. 6
0
 /**
  * @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'));
 }
Esempio n. 8
0
 public function addNext($href)
 {
     $this->addLink(Link::createNext($href));
 }
Esempio n. 9
0
 public function it_cannot_add_other_links()
 {
     $link = Link::createNext('http://yolo.com');
     $this->shouldThrow(\Exception::class)->duringAddAboutLink($link);
 }
Esempio n. 10
0
 /**
  * @param $output
  * @param Link $link
  *
  * @return \stdClass
  */
 public function buildSimpleLink($output, Link $link)
 {
     $name = $link->getName();
     $output->{$name} = $link->getHref();
     return $output;
 }