diff --git a/src/Fractal.php b/src/Fractal.php index 450c515..1c8ab91 100644 --- a/src/Fractal.php +++ b/src/Fractal.php @@ -160,7 +160,7 @@ public function parseIncludes($includes) }, explode(',', $includes)); } - $this->includes = array_merge($this->includes, $includes); + $this->includes = array_merge($this->includes, (array)$includes); return $this; } diff --git a/tests/Integration/IncludesTest.php b/tests/Integration/IncludesTest.php index dd8c734..47bed36 100644 --- a/tests/Integration/IncludesTest.php +++ b/tests/Integration/IncludesTest.php @@ -82,4 +82,28 @@ public function it_can_handle_multiple_includes_at_once() $this->assertEquals($expectedArray, $array); } + + /** + * @test + */ + public function it_knows_to_ignore_invalid_includes_param() + { + $array = $this->fractal + ->collection($this->testBooks, new TestTransformer()) + ->parseIncludes(null) + ->toArray(); + + $expectedArray = ['data' => [ + ['id' => 1, 'author' => 'Philip K Dick', ], + ['id' => 2, 'author' => 'George R. R. Satan', ], + ]]; + + $this->assertEquals($expectedArray, $array); + + $array = $this->fractal + ->collection($this->testBooks, new TestTransformer()) + ->parseIncludes([]) + ->toArray(); + $this->assertEquals($expectedArray, $array); + } }