1 <?php declare(strict_types=1);
4 require_once
'Services/Contact/BuddySystem/test/ilBuddySystemBaseTest.php';
26 $this->assertFalse($collection->isEmpty());
27 $this->assertSame($elements, $collection->toArray());
28 $this->assertSame(array_values($elements), $collection->getValues());
29 $this->assertSame(array_keys($elements), $collection->getKeys());
31 foreach ($elements as $key => $elm) {
32 $this->assertArrayHasKey($collection->getKey($elm), $elements);
33 $this->assertTrue(isset($collection[$key]));
34 $this->assertEquals($collection[$key], $elm);
45 $this->assertTrue($collection->isEmpty());
47 foreach ($elements as $elm) {
48 $collection->add($elm);
49 $this->assertTrue($collection->contains($elm));
52 foreach ($elements as $elm) {
53 $collection->removeElement($elm);
54 $this->assertFalse($collection->contains($elm));
57 $this->assertTrue($collection->isEmpty());
59 foreach ($elements as $elm) {
60 $collection->add($elm);
61 $this->assertTrue($collection->contains($elm));
64 foreach ($elements as $elm) {
65 $key = $collection->getKey($elm);
66 $collection->remove($key);
67 $this->assertFalse($collection->contains($elm));
70 $this->assertTrue($collection->isEmpty());
72 foreach ($elements as $key => $elm) {
73 $collection[$key] = $elm;
74 $this->assertTrue($collection->contains($elm));
77 foreach ($elements as $key => $elm) {
78 unset($collection[$key]);
79 $this->assertFalse($collection->contains($elm));
82 $this->assertTrue($collection->isEmpty());
86 $data = $collection->toArray();
87 $this->assertSame(5, reset(
$data));
98 foreach ($collection->getIterator() as $key => $item) {
99 $this->assertSame($elements[$key], $item,
"Item {$key} not match");
102 $this->assertCount($iterations, $elements,
'Number of iterations not match');
110 $this->expectException(InvalidArgumentException::class);
112 $collection->removeElement(5);
120 $this->expectException(InvalidArgumentException::class);
122 $collection->remove(
'phpunit');
136 $this->assertCount(2, $collection->filter(
function ($elm) {
137 return $elm % 2 === 0;
152 $this->assertSame([3], $collection->slice(2, 1)->getValues());
160 $relation1 = $this->getMockBuilder(ilBuddySystemRelation::class)->disableOriginalConstructor()->getMock();
161 $relation2 = $this->getMockBuilder(ilBuddySystemRelation::class)->disableOriginalConstructor()->getMock();
162 $relation3 = $this->getMockBuilder(ilBuddySystemRelation::class)->disableOriginalConstructor()->getMock();
163 $relation4 = $this->getMockBuilder(ilBuddySystemRelation::class)->disableOriginalConstructor()->getMock();
164 $relation5 = $this->getMockBuilder(ilBuddySystemRelation::class)->disableOriginalConstructor()->getMock();
167 'indexed' => [[0, 1, 2, 3, 4, 5]],
168 'associative' => [[
'A' =>
'a',
'B' =>
'b',
'C' =>
'c']],
169 'mixed' => [[0,
'A' =>
'a', 1,
'B' =>
'b', 2, 3]],
170 'relations' => [[$relation1, $relation2, $relation3, $relation4, $relation5]]
testRemovingAnNonExistingElementByKeyRaisesAnException()
Class ilBuddySystemRelationCollectionTest.
testElementsCanBeAddedAndRemoved(array $elements)
provideElements
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
testElementsCanBeInitiallyAdded(array $elements)
provideElements
testElementsCanBeSliced()
testElementsCanBeFiltered()
testRemovingAnNonExistingElementRaisesAnException()
testIterator(array $elements)
provideElements
toArray($value)
Wrap the given value in an array if it is no array.