예제 #1
0
 /**
  * @test
  */
 public function shouldReturnAppropriateResponseFactory()
 {
     $request = Request::create('http://test.com/api/pets/my-cat', Request::METHOD_GET);
     $request->headers->add(['Content-Type' => 'application/vnd.json+api', 'Accept' => 'application/vnd.json+api']);
     $request->query->set('include', 'store');
     $request->query->set('fields', ['pets' => 'family,store', 'stores' => 'name']);
     $environment = new Environment();
     $environment->setQueryType(PetsListQuery::class)->setMatcherConfiguration(['decoders' => ['application/vnd.json+api' => 'jsonapi.decoders.jsonapi'], 'encoders' => ['application/vnd.json+api' => 'jsonapi.encoders.jsonapi']])->setUrlPrefix('http://my-api.org');
     $request->attributes->set('_jsonapi', $environment);
     $apiRequest = $this->service->parseRequest($request);
     $store = new Store();
     $store->setId('my-store')->setName('My store')->setAddress('Unknown street');
     $cat = new Cat();
     $cat->id = 'my-cat';
     $cat->family = 'cats';
     $cat->name = 'Kitty';
     $cat->store = $store;
     $dog = new Dog();
     $dog->id = 'my-dog';
     $dog->family = 'dogs';
     $dog->name = 'Sharik';
     $dog->store = $store;
     $responseFactory = $this->service->getResponseFactory($apiRequest);
     /* @var $responseFactory ResponsesInterface */
     $response = $responseFactory->getContentResponse([$cat, $dog]);
     $this->assertInstanceOf(Response::class, $response);
     /* @var $response Response */
     $this->assertSame(200, $response->getStatusCode());
     $this->assertSame('application/vnd.json+api', $response->headers->get('Content-Type'));
     $expected = json_decode($this->getDataFromFile('pets-list-response.json'), true);
     $actual = json_decode($response->getContent(), true);
     $this->assertSame($expected, $actual);
 }
예제 #2
0
 /**
  * @param mixed $value
  * @return Store
  */
 public static function convert(Store $value)
 {
     $value->setConverted(true);
     return $value;
 }