Completed
Pull Request — master (#306)
by Benoît
33:19
created

testItImplementsScopeFactoryInterface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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
        $manager = $this->createManager();
22
        $resource = $this->createResource();
23
        $scopeIdentifier = 'foo_identifier';
24
25
        $scope = $sut->createScopeFor($manager, $resource, $scopeIdentifier);
26
27
        $this->assertInstanceOf('League\\Fractal\\Scope', $scope);
28
        $this->assertSame($resource, $scope->getResource());
29
        $this->assertSame($scopeIdentifier, $scope->getScopeIdentifier());
30
    }
31
32
    public function testItCreatesScopesWithParent()
33
    {
34
        $manager = $this->createManager();
35
36
        $scope = new Scope($manager, $this->createResource(), 'parent_identifier');
37
        $scope->setParentScopes([
38
            'parent_scope',
39
        ]);
40
41
        $resource = $this->createResource();
42
        $scopeIdentifier = 'foo_identifier';
43
44
        $expectedParentScopes = [
45
            'parent_scope',
46
            'parent_identifier',
47
        ];
48
49
        $sut = $this->createSut();
50
        $scope = $sut->createChildScopeFor($manager, $scope, $resource, $scopeIdentifier);
51
52
        $this->assertInstanceOf('League\\Fractal\\Scope', $scope);
53
        $this->assertSame($resource, $scope->getResource());
54
        $this->assertSame($scopeIdentifier, $scope->getScopeIdentifier());
55
        $this->assertEquals($expectedParentScopes, $scope->getParentScopes());
56
    }
57
58
    /**
59
     * @return ScopeFactory
60
     */
61
    private function createSut()
62
    {
63
        return new ScopeFactory();
64
    }
65
66
    /**
67
     * @return Manager
68
     */
69
    private function createManager()
70
    {
71
        return $this->getMock('League\\Fractal\\Manager');
72
    }
73
74
    /**
75
     * @return ResourceInterface
76
     */
77
    private function createResource()
78
    {
79
        return $this->getMock('League\\Fractal\\Resource\\ResourceInterface');
80
    }
81
}
82