Passed
Push — master ( 7f5941...009dcf )
by Radosław
02:23
created

CollectionTest::testIterator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Radowoj\Searcher\SearchResult;
4
5
use PHPUnit\Framework\TestCase;
6
use Radowoj\Searcher\SearchResult\Collection;
7
use Radowoj\Searcher\SearchResult\ICollection;
8
use Radowoj\Searcher\SearchResult\Item;
9
use Radowoj\Searcher\SearchResult\IItem;
10
11
use Traversable;
12
use Countable;
13
/**
14
 * @covers Radowoj\Searcher\SearchResult\Collection
15
 */
16
class CollectionTest extends TestCase
17
{
18
19
    protected $collection;
20
21
22
    public function setUp()
23
    {
24
        $this->collection = new Collection([
25
            0 => new Item([]),
26
            1 => new Item([]),
27
        ], 42);
28
    }
29
30
31
    public function testInstantiation()
32
    {
33
        $collection = new Collection();
34
        $this->assertInstanceOf(ICollection::class, $collection);
35
    }
36
37
38
    public function testOffsetExists()
39
    {
40
        $this->assertTrue($this->collection->offsetExists(0));
41
        $this->assertTrue($this->collection->offsetExists(1));
42
        $this->assertFalse($this->collection->offsetExists(2));
43
    }
44
45
46
    /**
47
     * @expectedException OutOfRangeException
48
     * @expectedExceptionMessage Invalid collection index: 2
49
     */
50
    public function testOffsetGet()
51
    {
52
        $this->assertInstanceOf(IItem::class, $this->collection->offsetGet(0));
53
        $this->assertInstanceOf(IItem::class, $this->collection->offsetGet(1));
54
        $this->assertInstanceOf(IItem::class, $this->collection->offsetGet(2));
55
    }
56
57
58
    /**
59
     * @expectedException Exception
60
     * @expectedExceptionMessage Search result collection is immutable.
61
     */
62
    public function testOffsetSetImmutability()
63
    {
64
        $this->collection->offsetSet(1, 'asas');
65
    }
66
67
68
    /**
69
     * @expectedException Exception
70
     * @expectedExceptionMessage Search result collection is immutable.
71
     */
72
    public function testOffsetUnsetImmutability()
73
    {
74
        $this->collection->offsetUnset(1);
75
    }
76
77
78
    public function testIterator()
79
    {
80
        $this->assertInstanceOf(Traversable::class, $this->collection);
81
        $this->assertInstanceOf(Traversable::class, $this->collection->getIterator());
82
    }
83
84
85
    public function testCountable()
86
    {
87
        $this->assertInstanceOf(Countable::class, $this->collection);
88
        $this->assertSame(2, $this->collection->count());
89
    }
90
91
92
    public function testTotalCount()
93
    {
94
        $this->assertSame(42, $this->collection->totalCount());
95
    }
96
97
}
98