|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace League\Fractal\Test; |
|
4
|
|
|
|
|
5
|
|
|
use League\Fractal\Manager; |
|
6
|
|
|
use League\Fractal\Resource\ResourceInterface; |
|
7
|
|
|
use League\Fractal\Scope; |
|
8
|
|
|
use League\Fractal\ScopeFactory; |
|
9
|
|
|
|
|
10
|
|
|
class ScopeFactoryTest extends \PHPUnit_Framework_TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
public function testItImplementsScopeFactoryInterface() |
|
13
|
|
|
{ |
|
14
|
|
|
$this->assertInstanceOf('League\\Fractal\\ScopeFactoryInterface', $this->createSut()); |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public function testItCreatesScopes() |
|
18
|
|
|
{ |
|
19
|
|
|
$sut = $this->createSut(); |
|
20
|
|
|
|
|
21
|
|
|
$resource = $this->createResource(); |
|
22
|
|
|
$scopeIdentifier = 'foo_identifier'; |
|
23
|
|
|
|
|
24
|
|
|
$scope = $sut->createScopeFor($resource, $scopeIdentifier); |
|
25
|
|
|
|
|
26
|
|
|
$this->assertInstanceOf('League\\Fractal\\Scope', $scope); |
|
27
|
|
|
$this->assertSame($resource, $scope->getResource()); |
|
28
|
|
|
$this->assertSame($scopeIdentifier, $scope->getScopeIdentifier()); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testItCreatesScopesWithParent() |
|
32
|
|
|
{ |
|
33
|
|
|
$manager = $this->createManager(); |
|
34
|
|
|
|
|
35
|
|
|
$scope = new Scope($manager, $this->createResource(), 'parent_identifier'); |
|
36
|
|
|
$scope->setParentScopes([ |
|
37
|
|
|
'parent_scope', |
|
38
|
|
|
]); |
|
39
|
|
|
|
|
40
|
|
|
$resource = $this->createResource(); |
|
41
|
|
|
$scopeIdentifier = 'foo_identifier'; |
|
42
|
|
|
|
|
43
|
|
|
$expectedParentScopes = [ |
|
44
|
|
|
'parent_scope', |
|
45
|
|
|
'parent_identifier', |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
$sut = $this->createSut($manager); |
|
49
|
|
|
$scope = $sut->createChildScopeFor($scope, $resource, $scopeIdentifier); |
|
50
|
|
|
|
|
51
|
|
|
$this->assertInstanceOf('League\\Fractal\\Scope', $scope); |
|
52
|
|
|
$this->assertSame($resource, $scope->getResource()); |
|
53
|
|
|
$this->assertSame($scopeIdentifier, $scope->getScopeIdentifier()); |
|
54
|
|
|
$this->assertEquals($expectedParentScopes, $scope->getParentScopes()); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param Manager $manager |
|
59
|
|
|
* @return ScopeFactory |
|
60
|
|
|
*/ |
|
61
|
|
|
private function createSut(Manager $manager = null) |
|
62
|
|
|
{ |
|
63
|
|
|
if ($manager === null) { |
|
64
|
|
|
$manager = $this->createManager(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return new ScopeFactory($manager); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* @return Manager |
|
72
|
|
|
*/ |
|
73
|
|
|
private function createManager() |
|
74
|
|
|
{ |
|
75
|
|
|
return $this->getMock('League\\Fractal\\Manager'); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @return ResourceInterface |
|
80
|
|
|
*/ |
|
81
|
|
|
private function createResource() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->getMock('League\\Fractal\\Resource\\ResourceInterface'); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|