4 require_once
'Services/Contact/BuddySystem/test/ilBuddySystemBaseTest.php';
33 $this->assertFalse($collection->isEmpty());
34 $this->assertSame($elements, $collection->toArray());
35 $this->assertSame(array_values($elements), $collection->getValues());
36 $this->assertSame(array_keys($elements), $collection->getKeys());
38 foreach ($elements as
$key => $elm) {
39 $this->assertArrayHasKey($collection->getKey($elm), $elements);
40 $this->assertTrue(isset($collection[
$key]));
41 $this->assertEquals($collection[$key], $elm);
52 $this->assertTrue($collection->isEmpty());
54 foreach ($elements as $elm) {
55 $collection->add($elm);
56 $this->assertTrue($collection->contains($elm));
59 foreach ($elements as $elm) {
60 $collection->removeElement($elm);
61 $this->assertFalse($collection->contains($elm));
64 $this->assertTrue($collection->isEmpty());
66 foreach ($elements as $elm) {
67 $collection->add($elm);
68 $this->assertTrue($collection->contains($elm));
71 foreach ($elements as $elm) {
72 $key = $collection->getKey($elm);
73 $collection->remove(
$key);
74 $this->assertFalse($collection->contains($elm));
77 $this->assertTrue($collection->isEmpty());
79 foreach ($elements as
$key => $elm) {
80 $collection[
$key] = $elm;
81 $this->assertTrue($collection->contains($elm));
84 foreach ($elements as
$key => $elm) {
85 unset($collection[
$key]);
86 $this->assertFalse($collection->contains($elm));
89 $this->assertTrue($collection->isEmpty());
93 $data = $collection->toArray();
94 $this->assertSame(5, reset(
$data));
105 foreach ($collection->getIterator() as
$key => $item) {
106 $this->assertSame($elements[$key], $item,
"Item {$key} not match");
109 $this->assertCount($iterations, $elements,
"Number of iterations not match");
119 $collection->removeElement(5);
129 $collection->remove(
"phpunit");
143 $this->assertCount(2, $collection->filter(
function ($elm) {
144 return $elm % 2 === 0;
159 $this->assertSame(array(3), $collection->slice(2, 1)->getValues());
167 $relation_1 = $this->getMockBuilder(
'ilBuddySystemRelation')->disableOriginalConstructor()->getMock();
168 $relation_2 = $this->getMockBuilder(
'ilBuddySystemRelation')->disableOriginalConstructor()->getMock();
169 $relation_3 = $this->getMockBuilder(
'ilBuddySystemRelation')->disableOriginalConstructor()->getMock();
170 $relation_4 = $this->getMockBuilder(
'ilBuddySystemRelation')->disableOriginalConstructor()->getMock();
171 $relation_5 = $this->getMockBuilder(
'ilBuddySystemRelation')->disableOriginalConstructor()->getMock();
174 'indexed' => array(array(0, 1, 2, 3, 4, 5)),
175 'associative' => array(array(
'A' =>
'a',
'B' =>
'b',
'C' =>
'c')),
176 'mixed' => array(array(0,
'A' =>
'a', 1,
'B' =>
'b', 2, 3)),
177 'relations' => array(array($relation_1, $relation_2, $relation_3, $relation_4, $relation_5))
testRemovingAnNonExistingElementByKeyRaisesAnException()
InvalidArgumentException
testElementsCanBeAddedAndRemoved($elements)
provideElements
Class ilBuddySystemRelationCollectionTest.
assertException($exception_class)
Class ilBuddySystemRelationCollection A collection which contains all entries of a buddy list...
testElementsCanBeInitiallyAdded($elements)
provideElements
testElementsCanBeSliced()
testElementsCanBeFiltered()
testRemovingAnNonExistingElementRaisesAnException()
InvalidArgumentException
toArray($value)
Wrap the given value in an array if it is no array.
testIterator($elements)
provideElements