/**
  *
  */
 public function setUp()
 {
     $this->serializer = new JsonApiSerializer(new JsonApiTransformer(new Mapper(HelperMapping::complex())));
     $this->fields = new Fields();
     $this->included = new Included();
     $this->resource = new GetResource($this->serializer, $this->fields, $this->included);
     $this->findOneCallable = function () {
         $user = new User(new UserId(1), 'Post Author');
         return new Post(new PostId(10), 'Old title', 'Old content', $user, []);
     };
 }
 /**
  *
  */
 public function setUp()
 {
     $this->serializer = new JsonApiSerializer(new JsonApiTransformer(new Mapper(HelperMapping::complex())));
     $this->resource = new CreateResource($this->serializer);
     $this->data = ['type' => 'post', 'attributes' => ['title' => 'My first blog post', 'content' => 'Ever heard of Lorem Ipsum?', 'author' => 1, 'comments' => []]];
     $this->callable = function (array $data, array $values, ErrorBag $errorBag) {
         $user = new User(new UserId(1), 'Post Author');
         $id = !empty($data['id']) ? $data['id'] : 1;
         return new Post(new PostId($id), $values['title'], $values['content'], $user, []);
     };
 }
 /**
  *
  */
 public function setUp()
 {
     $this->serializer = new JsonApiSerializer(new JsonApiTransformer(new Mapper(HelperMapping::complex())));
     $this->resource = new DeleteResource($this->serializer);
     $this->findOneCallable = function () {
         $user = new User(new UserId(1), 'Post Author');
         return new Post(new PostId(10), 'Old title', 'Old content', $user, []);
     };
     $this->deleteCallable = function () {
     };
 }
 /**
  *
  */
 public function setUp()
 {
     $this->included = new Included();
     $this->included->add('post.user_comment');
     //will cause error
     $this->fields = new Fields();
     $this->fields->addField('post', 'title');
     $this->fields->addField('blog', 'post');
     //will cause error
     $mappings = HelperMapping::complex();
     $this->serializer = new JsonApiSerializer(new JsonApiTransformer(new Mapper($mappings)));
 }
 /**
  *
  */
 public function setUp()
 {
     $this->serializer = new JsonApiSerializer(new JsonApiTransformer(new Mapper(HelperMapping::complex())));
     $this->resource = new PatchResource($this->serializer);
     $this->data = ['type' => 'post', 'id' => 10, 'attributes' => ['title' => 'My first blog post', 'content' => 'Ever heard of Lorem Ipsum?', 'author' => 1, 'comments' => []]];
     $this->findOneCallable = function () {
         $user = new User(new UserId(1), 'Post Author');
         return new Post(new PostId(10), 'Old title', 'Old Content', $user, []);
     };
     $this->updateCallable = function (Post $post, array $data, array $values, ErrorBag $errorBag) {
         $post->setTitle($values['title']);
         $post->setContent($values['content']);
         return $post;
     };
 }
 /**
  *
  */
 public function setUp()
 {
     $this->serializer = new JsonApiSerializer(new JsonApiTransformer(new Mapper(HelperMapping::complex())));
     $this->page = new Page(1, null, null, null, 10);
     $this->fields = new Fields();
     $this->sorting = new Sorting();
     $this->included = new Included();
     $this->resource = new ListResource($this->serializer, $this->page, $this->fields, $this->sorting, $this->included, $this->filters);
     $this->totalAmountCallable = function () {
         return 2015;
     };
     $this->resultsCallable = function () {
         $results = [];
         for ($i = 1; $i <= 10; ++$i) {
             $results[] = HelperFactory::complexPost();
         }
         return $results;
     };
 }
    /**
     *
     */
    public function testItWillSerializeToJsonApiAComplexObjectAndFilterFields()
    {
        $mappings = HelperMapping::complex();
        $mapper = new Mapper($mappings);
        $expected = <<<JSON
{
   "data":{
      "type":"post",
      "id":"9",
      "attributes":{
         "title":"Hello World"
      },
      "links":{
         "self":{
            "href":"http://example.com/posts/9"
         },
         "comments":{
            "href":"http://example.com/posts/9/comments"
         }
      }
   },
   "links":{
      "self":{
         "href":"http://example.com/posts/9"
      },
      "comments":{
         "href":"http://example.com/posts/9/comments"
      }
   },
   "meta":{
      "author":{
         "name":"Nil Portugués Calderó",
         "email":"*****@*****.**"
      },
      "is_devel":true
   },
   "jsonapi":{
      "version":"1.0"
   }
}
JSON;
        $post = HelperFactory::complexPost();
        $transformer = new JsonApiTransformer($mapper);
        $transformer->setMeta(['author' => ['name' => 'Nil Portugués Calderó', 'email' => '*****@*****.**']]);
        $transformer->addMeta('is_devel', true);
        $fields = new Fields();
        $fields->addField('post', 'title');
        $this->assertEquals(\json_decode($expected, true), \json_decode((new JsonApiSerializer($transformer))->serialize($post, $fields), true));
    }
 public function setUp()
 {
     $this->errorBag = new ErrorBag([]);
     $this->serializer = new JsonApiSerializer(new JsonApiTransformer(new Mapper(HelperMapping::complex())));
 }