19 declare(strict_types=1);
25 #[DataProvider('provideElements')] 30 $this->assertFalse($collection->isEmpty());
31 $this->assertSame($elements, $collection->toArray());
32 $this->assertSame(array_values($elements), $collection->getValues());
33 $this->assertSame(array_keys($elements), $collection->getKeys());
35 foreach ($elements as $key => $elm) {
36 $this->assertArrayHasKey($collection->getKey($elm), $elements);
37 $this->assertTrue(isset($collection[$key]));
38 $this->assertEquals($collection[$key], $elm);
42 #[DataProvider('provideElements')] 46 $this->assertTrue($collection->isEmpty());
48 foreach ($elements as $elm) {
49 $collection->add($elm);
50 $this->assertTrue($collection->contains($elm));
53 foreach ($elements as $elm) {
54 $collection->removeElement($elm);
55 $this->assertFalse($collection->contains($elm));
58 $this->assertTrue($collection->isEmpty());
60 foreach ($elements as $elm) {
61 $collection->add($elm);
62 $this->assertTrue($collection->contains($elm));
65 foreach ($elements as $elm) {
66 $key = $collection->getKey($elm);
67 $collection->remove($key);
68 $this->assertFalse($collection->contains($elm));
71 $this->assertTrue($collection->isEmpty());
73 foreach ($elements as $key => $elm) {
74 $collection[$key] = $elm;
75 $this->assertTrue($collection->contains($elm));
78 foreach ($elements as $key => $elm) {
79 unset($collection[$key]);
80 $this->assertFalse($collection->contains($elm));
83 $this->assertTrue($collection->isEmpty());
87 $data = $collection->toArray();
88 $this->assertSame(5, reset(
$data));
91 #[DataProvider('provideElements')] 96 foreach ($collection as $key => $item) {
97 $this->assertSame($elements[$key], $item,
"Item $key not match");
100 $this->assertCount($iterations, $elements,
'Number of iterations not match');
105 $this->expectException(InvalidArgumentException::class);
107 $collection->removeElement(5);
112 $this->expectException(InvalidArgumentException::class);
114 $collection->remove(
'phpunit');
125 $this->assertCount(2, $collection->filter(fn(
int $elm):
bool => $elm % 2 === 0)->toArray());
136 $this->assertSame([3], $collection->slice(2, 1)->getValues());
151 'indexed' => [[0, 1, 2, 3, 4, 5]],
152 'associative' => [[
'A' =>
'a',
'B' =>
'b',
'C' =>
'c']],
153 'mixed' => [[0,
'A' =>
'a', 1,
'B' =>
'b', 2, 3]],
154 'relations' => [[$relation1, $relation2, $relation3, $relation4, $relation5]]
testElementsCanBeSliced()
Class ilBuddySystemUnlinkedRelationState.
testElementsCanBeAddedAndRemoved(array $elements)
testElementsCanBeFiltered()
testElementsCanBeInitiallyAdded(array $elements)
testRemovingAnNonExistingElementRaisesAnException()
testIterator(array $elements)
testRemovingAnNonExistingElementByKeyRaisesAnException()