Skip to content

Commit

Permalink
fix: empty param bag
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Dec 6, 2024
1 parent db8f02e commit fe5feb4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Fractal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down
52 changes: 43 additions & 9 deletions tests/ScopeTest.php
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'],
]),
],
]);

0 comments on commit fe5feb4

Please sign in to comment.