示例#1
0
 /**
  * @param App                                               $app
  * @param \LaraPackage\Api\Contracts\Request\Parser         $requestParser
  * @param \LaraPackage\Api\Contracts\Factory\VersionFactory $versionFactory
  */
 protected function versionFactoryExpectations(App $app, \LaraPackage\Api\Contracts\Request\Parser $requestParser, \LaraPackage\Api\Contracts\Factory\VersionFactory $versionFactory, ApiVersion $apiVersion)
 {
     $requestParser->version()->shouldBeCalled()->willReturn($this->version);
     $apiVersion->factory($this->version)->shouldBeCalled()->willReturn(VersionFactory::class);
     $app->instance(\LaraPackage\Api\Contracts\Factory\VersionFactory::class, $versionFactory)->shouldBeCalled();
     $app->make(VersionFactory::class)->shouldBeCalledTimes(1)->willReturn($versionFactory);
 }
示例#2
0
 /**
  * @inheritdoc
  */
 public function make($data, $statusCode = 200, array $headers = [])
 {
     $acceptedMediaType = $this->requestParser->acceptedMediaType();
     $mediaType = $this->versionFactory->makeMediaType($acceptedMediaType);
     $representation = $mediaType->format($data);
     $headers = $this->setContentTypeHeader($headers, $acceptedMediaType);
     return $this->response->make($representation, $statusCode, $headers);
 }
示例#3
0
 /**
  * Create the VersionFactory for the Version
  *
  * @return \LaraPackage\Api\Contracts\Factory\VersionFactory
  * @internal param $version
  *
  */
 protected function createVersionFactory()
 {
     $version = $this->requestParser->version();
     $factory = $this->apiVersion->factory($version);
     $instance = $this->app->make($factory);
     $this->app->instance(\LaraPackage\Api\Contracts\Factory\VersionFactory::class, $instance);
     return $instance;
 }
示例#4
0
 /**
  * @inheritdoc
  */
 public function getCurrent()
 {
     $currentPositionParameter = $this->config->getIndexForVersion('collection.current_position', $this->requestParser->version());
     $current = $this->requestParser->query($currentPositionParameter);
     if (!empty($current)) {
         return (int) $current;
     }
     return 0;
 }
示例#5
0
 function it_returns_the_current_position_even_if_it_is_null(Parser $parser, ApiVersion $apiVersion)
 {
     $version = 4;
     $postionString = 'current';
     $parser->version()->shouldBeCalled()->willReturn($version);
     $apiVersion->collectionCurrentPositionString($version)->shouldBeCalled()->willReturn($postionString);
     $parser->query($postionString)->shouldBeCalled()->willReturn(null);
     $this->currentPosition()->shouldReturn(0);
 }
示例#6
0
 /**
  * @param Fractal\Resource\ResourceInterface $resource
  *
  * @return void
  */
 protected function setPayload(Fractal\Resource\ResourceInterface $resource)
 {
     $includes = $this->requestParser->includes();
     $manager = $this->fractalFactory->createManager();
     if ($includes) {
         $manager = $manager->parseIncludes($includes);
     }
     $payload = $manager->createData($resource)->toArray();
     $this->payload = $payload;
 }
 function it_makes_a_response(\LaraPackage\Api\Contracts\Request\Parser $requestParser, ResponseFactory $response, \LaraPackage\Api\Contracts\Factory\VersionFactory $versionFactory, \LaraPackage\Api\Contracts\MediaType\Json $media, \Illuminate\Http\Response $illuminateResponse, \LaraPackage\Api\Contracts\Config\ApiVersion $versionInfoRetriever)
 {
     $mediaType = 'json';
     $version = 4;
     $vendor = 'vnd.wps_api.';
     $versionDesignator = 'v4';
     $dataArray = ['data' => 'array'];
     $jsonData = json_encode($dataArray);
     $requestParser->acceptedMediaType()->shouldBeCalled()->willReturn($mediaType);
     $versionInfoRetriever->vendor($version)->shouldBeCalled()->willReturn($vendor);
     $versionInfoRetriever->versionDesignator($version)->shouldBeCalled()->willReturn($versionDesignator);
     $versionFactory->makeMediaType($mediaType)->shouldBeCalled()->willReturn($media);
     $media->format($dataArray)->shouldBeCalled()->willReturn($jsonData);
     $response->make($jsonData, 200, ['Content-Type' => 'application/' . $vendor . $versionDesignator . '+' . $mediaType])->shouldBeCalled()->willReturn($illuminateResponse);
     $this->make($dataArray)->shouldReturn($illuminateResponse);
 }
示例#8
0
 /**
  * @inheritdoc
  */
 public function query(Transformer $transformer)
 {
     $queryArray = $this->requestParser->query();
     return $transformer->reverseTransform($queryArray);
 }
示例#9
0
 /**
  * @param \LaraPackage\Api\Contracts\Config\Api $config
  * @param \LaraPackage\Api\Contracts\Request\Parser         $requestParser
  * @param                                  $requestParserReturn
  */
 protected function currentExpectations(\LaraPackage\Api\Contracts\Config\Api $config, \LaraPackage\Api\Contracts\Request\Parser $requestParser, $requestParserReturn)
 {
     $version = 4;
     $currentString = 'current';
     $requestParser->version()->shouldBeCalled()->willReturn($version);
     $config->getIndexForVersion('collection.current_position', $version)->shouldBeCalled()->willReturn($currentString);
     $requestParser->query($currentString)->shouldBeCalled()->willReturn($requestParserReturn);
 }