CollectionTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 118
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 5
dl 0
loc 118
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetData() 0 8 1
A testSetData() 0 6 1
A testGetTransformer() 0 9 1
A testSetTransformer() 0 6 1
A testSetCursor() 0 6 1
A testGetCursor() 0 7 1
A testGetSetPaginator() 0 7 1
A testGetSetMeta() 0 10 1
A testSetResourceKey() 0 5 1
A testGetResourceKey() 0 6 1
A tearDown() 0 4 1
1
<?php namespace League\Fractal\Test\Resource;
2
3
use League\Fractal\Pagination\Cursor;
4
use League\Fractal\Resource\Collection;
5
use Mockery;
6
use PHPUnit\Framework\TestCase;
7
8
class CollectionTest extends TestCase
9
{
10
    protected $simpleCollection = [
11
        ['foo' => 'bar'],
12
        ['baz' => 'ban'],
13
    ];
14
15
    public function testGetData()
16
    {
17
        $resource = new Collection($this->simpleCollection, function (array $data) {
18
            return $data;
19
        });
20
21
        $this->assertSame($resource->getData(), $this->simpleCollection);
22
    }
23
24
    /**
25
     * @covers \League\Fractal\Resource\Collection::setData
26
     */
27
    public function testSetData()
28
    {
29
        $collection = Mockery::mock('League\Fractal\Resource\Collection')->makePartial();
30
        $collection->setData('foo');
31
        $this->assertSame('foo', $collection->getData());
32
    }
33
34
    public function testGetTransformer()
35
    {
36
        $resource = new Collection($this->simpleCollection, function () {
37
        });
38
        $this->assertTrue(is_callable($resource->getTransformer()));
39
40
        $resource = new Collection($this->simpleCollection, 'SomeClass');
41
        $this->assertSame($resource->getTransformer(), 'SomeClass');
42
    }
43
44
    /**
45
     * @covers \League\Fractal\Resource\Collection::setTransformer
46
     */
47
    public function testSetTransformer()
48
    {
49
        $collection = Mockery::mock('League\Fractal\Resource\Collection')->makePartial();
50
        $collection->setTransformer('foo');
51
        $this->assertSame('foo', $collection->getTransformer());
52
    }
53
54
    /**
55
     * @covers \League\Fractal\Resource\Collection::setCursor
56
     */
57
    public function testSetCursor()
58
    {
59
        $cursor = Mockery::mock('League\Fractal\Pagination\Cursor');
60
        $collection = Mockery::mock('League\Fractal\Resource\Collection')->makePartial();
61
        $this->assertInstanceOf('League\Fractal\Resource\Collection', $collection->setCursor($cursor));
62
    }
63
64
    /**
65
     * @covers \League\Fractal\Resource\Collection::getCursor
66
     */
67
    public function testGetCursor()
68
    {
69
        $cursor = new Cursor();
70
        $collection = Mockery::mock('League\Fractal\Resource\Collection')->makePartial();
71
        $collection->setCursor($cursor);
72
        $this->assertInstanceOf('League\Fractal\Pagination\Cursor', $collection->getCursor());
73
    }
74
75
    /**
76
     * @covers \League\Fractal\Resource\Collection::setPaginator
77
     * @covers \League\Fractal\Resource\Collection::getPaginator
78
     */
79
    public function testGetSetPaginator()
80
    {
81
        $paginator = Mockery::mock('League\Fractal\Pagination\IlluminatePaginatorAdapter');
82
        $collection = Mockery::mock('League\Fractal\Resource\Collection')->makePartial();
83
        $this->assertInstanceOf('League\Fractal\Resource\Collection', $collection->setPaginator($paginator));
84
        $this->assertInstanceOf('League\Fractal\Pagination\PaginatorInterface', $collection->getPaginator());
85
    }
86
87
    /**
88
     * @covers \League\Fractal\Resource\Collection::setMetaValue
89
     * @covers \League\Fractal\Resource\Collection::getMetaValue
90
     */
91
    public function testGetSetMeta()
92
    {
93
        $collection = Mockery::mock('League\Fractal\Resource\Collection')->makePartial();
94
        $this->assertInstanceOf('League\Fractal\Resource\Collection', $collection->setMetaValue('foo', 'bar'));
95
96
        $this->assertSame(['foo' => 'bar'], $collection->getMeta());
97
        $this->assertSame('bar', $collection->getMetaValue('foo'));
98
        $collection->setMeta(['baz' => 'bat']);
99
        $this->assertSame(['baz' => 'bat'], $collection->getMeta());
100
    }
101
102
    /**
103
     * @covers \League\Fractal\Resource\Collection::setResourceKey
104
     */
105
    public function testSetResourceKey()
106
    {
107
        $collection = Mockery::mock('League\Fractal\Resource\Collection')->makePartial();
108
        $this->assertInstanceOf('League\Fractal\Resource\Collection', $collection->setResourceKey('foo'));
109
    }
110
111
    /**
112
     * @covers \League\Fractal\Resource\Collection::getResourceKey
113
     */
114
    public function testGetResourceKey()
115
    {
116
        $collection = Mockery::mock('League\Fractal\Resource\Collection')->makePartial();
117
        $collection->setResourceKey('foo');
118
        $this->assertSame('foo', $collection->getResourceKey());
119
    }
120
121
    public function tearDown()
122
    {
123
        Mockery::close();
124
    }
125
}
126