Example #1
0
 /** @test */
 public function it_should_generate_response()
 {
     $user = new UserEntityStub();
     $user->setName('John Doe');
     $user->setEmail('*****@*****.**');
     $responder = new JsonResponderStub(new Request(), new Transformer(new Manager(), new Container(), $this->map));
     $responder->setUser($user);
     $response = $responder->respond();
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertArraySubset(['content-type' => ['application/json']], $response->headers->all());
     $this->assertEquals('{"data":{"name":"John Doe","email":"*****@*****.**"}}', $response->getContent());
 }
 /** @test */
 public function it_should_transform_item_without_includes()
 {
     $userWorkplace = new UserWorkplaceEntityStub();
     $userWorkplace->setName('Doe\'s Constructions');
     $user = new UserEntityStub();
     $user->setName('John Doe');
     $user->setEmail('*****@*****.**');
     $user->setWorkplace($userWorkplace);
     $scope = $this->transformer->transformItem($user);
     $this->assertInstanceOf(\League\Fractal\Scope::class, $scope);
     $this->assertEquals(['data' => ['name' => 'John Doe', 'email' => '*****@*****.**']], $scope->toArray());
 }
 /**
  * @param UserEntityStub $entity
  * @return \League\Fractal\Resource\Item
  */
 public function includeWorkplace(UserEntityStub $entity)
 {
     return $this->item($entity->getWorkplace(), new UserWorkplaceEntityTransformerStub(), 'workplaces');
 }