Пример #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;
 }
Пример #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'));
 }
Пример #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);
 }
Пример #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"}}}}');
 }
Пример #5
0
 public function it_can_add_a_named_link(Link $link)
 {
     $link->beConstructedWith(['name', 'http://yolo']);
     $this->addLink($link);
     $this->hasLink($link)->shouldReturn(true);
 }
Пример #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);
 }
Пример #7
0
 public function it_must_pass_link_collection()
 {
     $this->shouldThrow(\Exception::class)->duringInstantiation(Link::createFirst('http'));
 }
Пример #8
0
 public function addNext($href)
 {
     $this->addLink(Link::createNext($href));
 }
Пример #9
0
 public function it_cannot_add_other_links()
 {
     $link = Link::createNext('http://yolo.com');
     $this->shouldThrow(\Exception::class)->duringAddAboutLink($link);
 }
Пример #10
0
 /**
  * @param $output
  * @param Link $link
  *
  * @return \stdClass
  */
 public function buildSimpleLink($output, Link $link)
 {
     $name = $link->getName();
     $output->{$name} = $link->getHref();
     return $output;
 }