|
@@ 168-183 (lines=16) @@
|
| 165 |
|
$this->assertSame('book.author.profile', $grandChildScope->getIdentifier()); |
| 166 |
|
} |
| 167 |
|
|
| 168 |
|
public function testGetParentScopes() |
| 169 |
|
{ |
| 170 |
|
$manager = new Manager(); |
| 171 |
|
|
| 172 |
|
$resource = new Item(['name' => 'Larry Ullman'], function () { |
| 173 |
|
}); |
| 174 |
|
|
| 175 |
|
$scope = new Scope($manager, $resource, 'book'); |
| 176 |
|
|
| 177 |
|
$childScope = $scope->embedChildScope('author', $resource); |
| 178 |
|
|
| 179 |
|
$this->assertSame(['book'], $childScope->getParentScopes()); |
| 180 |
|
|
| 181 |
|
$grandChildScope = $childScope->embedChildScope('profile', $resource); |
| 182 |
|
$this->assertSame(['book', 'author'], $grandChildScope->getParentScopes()); |
| 183 |
|
} |
| 184 |
|
|
| 185 |
|
public function testIsRequested() |
| 186 |
|
{ |
|
@@ 607-626 (lines=20) @@
|
| 604 |
|
* @covers \League\Fractal\Scope::toArray |
| 605 |
|
* @dataProvider fieldsetsWithMandatorySerializerFieldsProvider |
| 606 |
|
*/ |
| 607 |
|
public function testToArrayWithFieldsetsAndMandatorySerializerFields($fieldsetsToParse, $expected) |
| 608 |
|
{ |
| 609 |
|
$serializer = Mockery::mock('League\Fractal\Serializer\DataArraySerializer')->makePartial(); |
| 610 |
|
$serializer->shouldReceive('getMandatoryFields')->andReturn(['foo']); |
| 611 |
|
|
| 612 |
|
$resource = new Item( |
| 613 |
|
['foo' => 'bar', 'baz' => 'qux'], |
| 614 |
|
function ($data) { |
| 615 |
|
return $data; |
| 616 |
|
}, |
| 617 |
|
'resourceName' |
| 618 |
|
); |
| 619 |
|
|
| 620 |
|
$manager = new Manager(); |
| 621 |
|
$manager->setSerializer($serializer); |
| 622 |
|
$scope = new Scope($manager, $resource); |
| 623 |
|
|
| 624 |
|
$manager->parseFieldsets($fieldsetsToParse); |
| 625 |
|
$this->assertSame($expected, $scope->toArray()); |
| 626 |
|
} |
| 627 |
|
|
| 628 |
|
public function fieldsetsWithMandatorySerializerFieldsProvider() |
| 629 |
|
{ |
|
@@ 647-663 (lines=17) @@
|
| 644 |
|
/** |
| 645 |
|
* @dataProvider fieldsetsWithIncludesProvider |
| 646 |
|
*/ |
| 647 |
|
public function testToArrayWithIncludesAndFieldsets($fieldsetsToParse, $expected) |
| 648 |
|
{ |
| 649 |
|
$transformer = $this->createTransformerWithIncludedResource('book', ['book' => ['yin' => 'yang']]); |
| 650 |
|
|
| 651 |
|
$resource = new Item( |
| 652 |
|
['foo' => 'bar', 'baz' => 'qux'], |
| 653 |
|
$transformer, |
| 654 |
|
'resourceName' |
| 655 |
|
); |
| 656 |
|
$manager = new Manager(); |
| 657 |
|
$scope = new Scope($manager, $resource); |
| 658 |
|
|
| 659 |
|
$manager->parseIncludes('book'); |
| 660 |
|
|
| 661 |
|
$manager->parseFieldsets($fieldsetsToParse); |
| 662 |
|
$this->assertSame($expected, $scope->toArray()); |
| 663 |
|
} |
| 664 |
|
|
| 665 |
|
public function fieldsetsWithIncludesProvider() |
| 666 |
|
{ |