Skip to content

Commit

Permalink
Merge pull request #19 from countless-integers/patch-1
Browse files Browse the repository at this point in the history
fixes behaviour for passing empty values to parseIncludes
  • Loading branch information
freekmurze committed Dec 16, 2015
2 parents 5bde517 + 8d91785 commit 189c6b4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Fractal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
24 changes: 24 additions & 0 deletions tests/Integration/IncludesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 189c6b4

Please sign in to comment.