diff --git a/src/Fractal.php b/src/Fractal.php index e6393e2..4b8dda0 100644 --- a/src/Fractal.php +++ b/src/Fractal.php @@ -405,7 +405,7 @@ public function createData() $this->manager->parseFieldsets($this->fieldsets); } - return $this->manager->createData($this->getResource(), $this->resourceName); + return $this->manager->createData($this->getResource()); } /** diff --git a/tests/ScopeTest.php b/tests/ScopeTest.php index 6cba108..babf89c 100644 --- a/tests/ScopeTest.php +++ b/tests/ScopeTest.php @@ -1,13 +1,47 @@ fractal - ->collection($this->testBooks, new TestTransformer(), 'books') - ->parseIncludes('characters') - ->createData(); +it('can parse include parameters', function ($resourceName, string $include, string $includeWithParams, ParamBag $expected): void { + $fractal = Fractal::create(getTestPublishers(), new PublisherTransformer()) + ->withResourceName($resourceName) + ->parseIncludes($includeWithParams); - assertEquals('books', $scope->getIdentifier()); -}); + $scope = $fractal->createData(); + + $identifier = $scope->getIdentifier($include); + $actualParams = $scope->getManager()->getIncludeParams($identifier); + expect($actualParams)->toEqual($expected); +})->with([ + [ + 'resource name: string' => 'Publisher', + ], + [ + 'resource name: null' => null, + ], +])->with([ + [ + 'include' => 'books', + 'include_with_params' => 'books:test(2|value)', + 'expected' => new ParamBag([ + 'test' => ['2', 'value'], + ]), + ], + [ + 'include' => 'books', + 'include_with_params' => 'books:test(another_value|3):another(1|2|3)', + 'expected' => new ParamBag([ + 'test' => ['another_value', '3'], + 'another' => ['1', '2', '3'], + ]), + ], + [ + 'include' => 'books.author', + 'include_with_params' => 'books.author:test(test|value)', + 'expected' => new ParamBag([ + 'test' => ['test', 'value'], + ]), + ], +]);