|
@@ 136-152 (lines=17) @@
|
| 133 |
|
* @covers League\Fractal\TransformerAbstract::processIncludedResources |
| 134 |
|
* @covers League\Fractal\TransformerAbstract::callIncludeMethod |
| 135 |
|
*/ |
| 136 |
|
public function testProcessIncludedAvailableResources() |
| 137 |
|
{ |
| 138 |
|
$manager = new Manager(); |
| 139 |
|
$manager->parseIncludes('book'); |
| 140 |
|
$transformer = m::mock('League\Fractal\TransformerAbstract[transform]'); |
| 141 |
|
|
| 142 |
|
$transformer->shouldReceive('includeBook')->once()->andReturnUsing(function ($data) { |
| 143 |
|
return new Item(['included' => 'thing'], function ($data) { |
| 144 |
|
return $data; |
| 145 |
|
}); |
| 146 |
|
}); |
| 147 |
|
|
| 148 |
|
$transformer->setAvailableIncludes(['book', 'publisher']); |
| 149 |
|
$scope = new Scope($manager, new Item([], $transformer)); |
| 150 |
|
$included = $transformer->processIncludedResources($scope, ['meh']); |
| 151 |
|
$this->assertSame(['book' => ['data' => ['included' => 'thing']]], $included); |
| 152 |
|
} |
| 153 |
|
|
| 154 |
|
/** |
| 155 |
|
* @covers League\Fractal\TransformerAbstract::processIncludedResources |
|
@@ 250-265 (lines=16) @@
|
| 247 |
|
* @covers League\Fractal\TransformerAbstract::processIncludedResources |
| 248 |
|
* @covers League\Fractal\TransformerAbstract::callIncludeMethod |
| 249 |
|
*/ |
| 250 |
|
public function testProcessEmbeddedDefaultResources() |
| 251 |
|
{ |
| 252 |
|
$manager = new Manager(); |
| 253 |
|
$transformer = m::mock('League\Fractal\TransformerAbstract[transform]'); |
| 254 |
|
|
| 255 |
|
$transformer->shouldReceive('includeBook')->once()->andReturnUsing(function ($data) { |
| 256 |
|
return new Item(['included' => 'thing'], function ($data) { |
| 257 |
|
return $data; |
| 258 |
|
}); |
| 259 |
|
}); |
| 260 |
|
|
| 261 |
|
$transformer->setDefaultIncludes(['book']); |
| 262 |
|
$scope = new Scope($manager, new Item([], $transformer)); |
| 263 |
|
$included = $transformer->processIncludedResources($scope, ['meh']); |
| 264 |
|
$this->assertSame(['book' => ['data' => ['included' => 'thing']]], $included); |
| 265 |
|
} |
| 266 |
|
|
| 267 |
|
/** |
| 268 |
|
* @covers League\Fractal\TransformerAbstract::processIncludedResources |
|
@@ 271-287 (lines=17) @@
|
| 268 |
|
* @covers League\Fractal\TransformerAbstract::processIncludedResources |
| 269 |
|
* @covers League\Fractal\TransformerAbstract::callIncludeMethod |
| 270 |
|
*/ |
| 271 |
|
public function testIncludedItem() |
| 272 |
|
{ |
| 273 |
|
$manager = new Manager(); |
| 274 |
|
$manager->parseIncludes('book'); |
| 275 |
|
|
| 276 |
|
$transformer = m::mock('League\Fractal\TransformerAbstract[transform]'); |
| 277 |
|
$transformer->shouldReceive('includeBook')->once()->andReturnUsing(function ($data) { |
| 278 |
|
return new Item(['included' => 'thing'], function ($data) { |
| 279 |
|
return $data; |
| 280 |
|
}); |
| 281 |
|
}); |
| 282 |
|
|
| 283 |
|
$transformer->setAvailableIncludes(['book']); |
| 284 |
|
$scope = new Scope($manager, new Item([], $transformer)); |
| 285 |
|
$included = $transformer->processIncludedResources($scope, ['meh']); |
| 286 |
|
$this->assertSame(['book' => ['data' => ['included' => 'thing']]], $included); |
| 287 |
|
} |
| 288 |
|
|
| 289 |
|
public function testParamBagIsProvidedForIncludes() |
| 290 |
|
{ |