Skip to content

Commit

Permalink
Fractal: explode can't be null in php 8 - set default include input t…
Browse files Browse the repository at this point in the history
…o empty string (#25)

* explode can't be null in php 8 set default include input to empty string

* additional test to validate working fractal without includes

Co-authored-by: Christoph Kluge <[email protected]>
  • Loading branch information
germ1f and christoph-kluge authored Aug 31, 2022
1 parent 25ebd2d commit e2980b6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Transformer/Adapter/Fractal.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ protected function createResource($response, $transformer, array $parameters)
*/
public function parseFractalIncludes(Request $request)
{
$includes = $request->input($this->includeKey);
$includes = $request->input($this->includeKey, '');

if (! is_array($includes)) {
$includes = array_map('trim', array_filter(explode($this->includeSeparator, $includes)));
Expand Down
9 changes: 9 additions & 0 deletions tests/Transformer/Adapter/FractalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,13 @@ public function testParseFractalIncludesWithSpaces()

$this->assertEquals(['foo', 'bar'], $requestedIncludes);
}

public function testParseFractalWithoutAnyGivenIncludes()
{
$request = Request::create('/', 'GET');
$this->fractal->parseFractalIncludes($request);
$requestedIncludes = $this->fractal->getFractal()->getRequestedIncludes();

$this->assertEquals([], $requestedIncludes);
}
}

0 comments on commit e2980b6

Please sign in to comment.