1 | <?php |
||
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 |