예제 #1
0
 /**
  * @return \League\Fractal\Scope
  */
 protected function getResource()
 {
     if (null !== $this->item) {
         return $this->transformer->transformItem($this->item);
     } else {
         if (null !== $this->collection && false === empty($this->collection)) {
             return $this->transformer->transformCollection($this->collection);
         }
     }
     return $this->transformer->transformNull();
 }
예제 #2
0
 /** @test */
 public function it_should_transform_collection_with_paginator()
 {
     $userOne = new UserEntityStub();
     $userOne->setName('John Doe');
     $userOne->setEmail('*****@*****.**');
     $userTwo = new UserEntityStub();
     $userTwo->setName('Jane Doe');
     $userTwo->setEmail('*****@*****.**');
     $this->transformer->setPaginator(new LengthAwarePaginator([$userOne, $userTwo], 2, 10));
     $scope = $this->transformer->transformCollection([$userOne, $userTwo]);
     $this->assertInstanceOf(\League\Fractal\Scope::class, $scope);
     $this->assertEquals(['data' => [['name' => 'John Doe', 'email' => '*****@*****.**'], ['name' => 'Jane Doe', 'email' => '*****@*****.**']], 'meta' => ['pagination' => ['total' => 2, 'count' => 2, 'per_page' => 10, 'current_page' => 1, 'total_pages' => 1, 'links' => []]]], $scope->toArray());
 }