ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
ilCtrlArrayIteratorTest.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
29 {
31  {
32  $iterator = new ilCtrlArrayIterator([
33  'key0' => 'entry0',
34  'key1' => 'entry1',
35  'key2' => 'entry2',
36  ]);
37 
38  $expected_iterator_values = ['entry0', 'entry1', 'entry2'];
39  $expected_iterator_keys = ['key0', 'key1', 'key2'];
40 
41  for ($i = 0, $i_max = 3; $i < $i_max; $i++) {
42  $this->assertTrue($iterator->valid());
43  $this->assertEquals(
44  $expected_iterator_values[$i],
45  $iterator->current(),
46  );
47  $this->assertEquals(
48  $expected_iterator_keys[$i],
49  $iterator->key()
50  );
51 
52  $iterator->next();
53  }
54 
55  $this->assertFalse($iterator->valid());
56  }
57 
59  {
60  $iterator = new ilCtrlArrayIterator([
61  'entry0',
62  'entry1',
63  'entry2',
64  ]);
65 
66  $this->assertFalse($iterator->valid());
67  $this->assertNull($iterator->current());
68  $this->assertNull($iterator->key());
69  }
70 
71  public function testArrayIteratorWithMixedArray(): void
72  {
73  $iterator = new ilCtrlArrayIterator([
74  'key0' => 0,
75  1 => 'entry1',
76  2 => 2,
77  'key3' => 'entry3',
78  'key4' => false
79  ]);
80 
81  $this->assertTrue($iterator->valid());
82  $this->assertEquals(
83  'entry3',
84  $iterator->current()
85  );
86  $this->assertEquals(
87  'key3',
88  $iterator->key()
89  );
90 
91  $iterator->next();
92  $this->assertFalse($iterator->valid());
93  }
94 
95  public function testArrayIteratorWithEmptyArray(): void
96  {
97  $iterator = new ilCtrlArrayIterator([]);
98 
99  $this->assertFalse($iterator->valid());
100  $this->assertNull($iterator->current());
101  $this->assertNull($iterator->key());
102  }
103 }
Class ilCtrlArrayIteratorTest.
Class ilCtrlArrayIterator.