Ejemplo n.º 1
0
 function it_puts_the_supplied_ids_into_a_resource(Parser $parser)
 {
     $resource = '/sites/{random_id}/products/{random_id}/images/{random_id}';
     $ids = [1, 2, 3];
     $expected = '/sites/1/products/2/images/3/';
     $parser->entities($resource, '{random_id}')->shouldBeCalled()->willReturn(['sites', 'products', 'images']);
     $this->putIdsInUri($resource, $ids)->shouldReturn($expected);
 }
Ejemplo n.º 2
0
 /**
  * @inheritdoc
  */
 public function putIdsInUri($uri, array $ids, $idPlaceholder = '{random_id}')
 {
     $entities = $this->uriParser->entities($uri, $idPlaceholder);
     if (abs(count($entities) - count($ids)) > 1) {
         throw new \RuntimeException('Ids and entities count must be off by no more than 1');
     }
     return array_reduce($entities, function ($carry, $item) use(&$ids) {
         $id = array_shift($ids);
         if ($id) {
             return $carry . $item . '/' . $id . '/';
         }
         return $carry . $item;
     }, '/');
 }
Ejemplo n.º 3
0
 /**
  * @return array
  */
 protected function idEntities()
 {
     return $this->parser->idEntities($this->uri());
 }
Ejemplo n.º 4
0
 function it_returns_item_ids(Request $request, Parser $parser)
 {
     $uri = '/sites/1/products/2/images/1,4,5';
     $ids = [1, 2, [1, 4, 5]];
     $result = [1, 4, 5];
     $request->getRequestUri()->shouldBeCalled()->willReturn($uri);
     $parser->ids($uri)->shouldBeCalled()->willReturn($ids);
     $this->itemIds()->shouldReturn($result);
 }