-
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db8f02e
commit fe5feb4
Showing
2 changed files
with
44 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,47 @@ | ||
<?php | ||
|
||
use Spatie\Fractalistic\Test\TestClasses\TestTransformer; | ||
use function PHPUnit\Framework\assertEquals; | ||
use League\Fractal\ParamBag; | ||
use Spatie\Fractalistic\Fractal; | ||
use Spatie\Fractalistic\Test\TestClasses\PublisherTransformer; | ||
|
||
it('uses an identifier for the scope', function () { | ||
$scope = $this->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'], | ||
]), | ||
], | ||
]); |