@@ 151-166 (lines=16) @@ | ||
148 | $this->assertSame('book.author.profile', $grandChildScope->getIdentifier()); |
|
149 | } |
|
150 | ||
151 | public function testGetParentScopes() |
|
152 | { |
|
153 | $manager = new Manager(); |
|
154 | ||
155 | $resource = new Item(['name' => 'Larry Ullman'], function () { |
|
156 | }); |
|
157 | ||
158 | $scope = new Scope($manager, $resource, 'book'); |
|
159 | ||
160 | $childScope = $scope->embedChildScope('author', $resource); |
|
161 | ||
162 | $this->assertSame(['book'], $childScope->getParentScopes()); |
|
163 | ||
164 | $grandChildScope = $childScope->embedChildScope('profile', $resource); |
|
165 | $this->assertSame(['book', 'author'], $grandChildScope->getParentScopes()); |
|
166 | } |
|
167 | ||
168 | public function testIsRequested() |
|
169 | { |
|
@@ 590-609 (lines=20) @@ | ||
587 | * @covers \League\Fractal\Scope::toArray |
|
588 | * @dataProvider fieldsetsWithMandatorySerializerFieldsProvider |
|
589 | */ |
|
590 | public function testToArrayWithFieldsetsAndMandatorySerializerFields($fieldsetsToParse, $expected) |
|
591 | { |
|
592 | $serializer = Mockery::mock('League\Fractal\Serializer\DataArraySerializer')->makePartial(); |
|
593 | $serializer->shouldReceive('getMandatoryFields')->andReturn(['foo']); |
|
594 | ||
595 | $resource = new Item( |
|
596 | ['foo' => 'bar', 'baz' => 'qux'], |
|
597 | function ($data) { |
|
598 | return $data; |
|
599 | }, |
|
600 | 'resourceName' |
|
601 | ); |
|
602 | ||
603 | $manager = new Manager(); |
|
604 | $manager->setSerializer($serializer); |
|
605 | $scope = new Scope($manager, $resource); |
|
606 | ||
607 | $manager->parseFieldsets($fieldsetsToParse); |
|
608 | $this->assertSame($expected, $scope->toArray()); |
|
609 | } |
|
610 | ||
611 | public function fieldsetsWithMandatorySerializerFieldsProvider() |
|
612 | { |
|
@@ 630-646 (lines=17) @@ | ||
627 | /** |
|
628 | * @dataProvider fieldsetsWithIncludesProvider |
|
629 | */ |
|
630 | public function testToArrayWithIncludesAndFieldsets($fieldsetsToParse, $expected) |
|
631 | { |
|
632 | $transformer = $this->createTransformerWithIncludedResource('book', ['book' => ['yin' => 'yang']]); |
|
633 | ||
634 | $resource = new Item( |
|
635 | ['foo' => 'bar', 'baz' => 'qux'], |
|
636 | $transformer, |
|
637 | 'resourceName' |
|
638 | ); |
|
639 | $manager = new Manager(); |
|
640 | $scope = new Scope($manager, $resource); |
|
641 | ||
642 | $manager->parseIncludes('book'); |
|
643 | ||
644 | $manager->parseFieldsets($fieldsetsToParse); |
|
645 | $this->assertSame($expected, $scope->toArray()); |
|
646 | } |
|
647 | ||
648 | public function fieldsetsWithIncludesProvider() |
|
649 | { |