diff --git a/src/helpers/RequestParser.php b/src/helpers/RequestParser.php index f87e4c8..5ae8f25 100644 --- a/src/helpers/RequestParser.php +++ b/src/helpers/RequestParser.php @@ -144,7 +144,7 @@ public function getIncludePaths(array $options=[]) { $wrapped = [$lastStep => $wrapped]; } - $restructured = array_merge($restructured, $wrapped); + $restructured = array_merge_recursive($restructured, $wrapped); } return $restructured; diff --git a/tests/helpers/RequestParserTest.php b/tests/helpers/RequestParserTest.php index de9288e..6410c78 100644 --- a/tests/helpers/RequestParserTest.php +++ b/tests/helpers/RequestParserTest.php @@ -214,9 +214,36 @@ public function testHasIncludePaths() { } public function testGetIncludePaths_Reformatted() { - $queryParameters = ['include' => 'foo,bar,baz.baf']; + $paths = [ + 'foo', + 'bar', + 'baz.baf', + 'baz.bat', + 'user.ship.wing', + 'user.ship.nose.window', + 'user.friends', + ]; + $expected = [ + 'foo' => [], + 'bar' => [], + 'baz' => [ + 'baf' => [], + 'bat' => [], + ], + 'user' => [ + 'ship' => [ + 'wing' => [], + 'nose' => [ + 'window' => [], + ], + ], + 'friends' => [], + ], + ]; + + $queryParameters = ['include' => implode(',', $paths)]; $requestParser = new RequestParser($selfLink='', $queryParameters); - $this->assertSame(['foo' => [], 'bar' => [], 'baz' => ['baf' => []]], $requestParser->getIncludePaths()); + $this->assertSame($expected, $requestParser->getIncludePaths()); } public function testGetIncludePaths_Raw() {