/** * @expectedException \InvalidArgumentException */ public function testThrowExceptionIfRespondWithPaginatedCollectionButContentIsNotPaginatorInterface() { $response = new Response($fractal = m::mock('League\\Fractal\\Manager'), m::mock('Paxifi\\Support\\Response\\Item'), $collection = m::mock('Paxifi\\Support\\Response\\Collection'), $paginator = m::mock('Paxifi\\Support\\Response\\Paginator'), m::mock('Paxifi\\Support\\Response\\Cursor')); $response->setContent('foo'); $response->setTransformer($transformer = m::mock('League\\Fractal\\TransformerAbstract')); $collection->shouldReceive('setData')->once()->with('foo'); $collection->shouldReceive('setTransformer')->once()->with($transformer); $response->withCollection(true); }
/** * Responds with collection. * * @param mixed $data * @param bool $paginated * * @return \Illuminate\Http\JsonResponse */ public function respondWithCollection($data, $paginated = false) { $this->response->setTransformer($this->getTransformer())->setContent($data); return $this->respond($this->response->withCollection($paginated)); }