ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilCtrlArrayIteratorTest.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /* Copyright (c) 2021 Thibeau Fuhrer <thf@studer-raimann.ch> Extended GPL, see docs/LICENSE */
6 
8 
14 class ilCtrlArrayIteratorTest extends TestCase
15 {
17  {
18  $iterator = new ilCtrlArrayIterator([
19  'key0' => 'entry0',
20  'key1' => 'entry1',
21  'key2' => 'entry2',
22  ]);
23 
24  $expected_iterator_values = ['entry0', 'entry1', 'entry2'];
25  $expected_iterator_keys = ['key0', 'key1', 'key2'];
26 
27  for ($i = 0, $i_max = 3; $i < $i_max; $i++) {
28  $this->assertTrue($iterator->valid());
29  $this->assertEquals(
30  $expected_iterator_values[$i],
31  $iterator->current(),
32  );
33  $this->assertEquals(
34  $expected_iterator_keys[$i],
35  $iterator->key()
36  );
37 
38  $iterator->next();
39  }
40 
41  $this->assertFalse($iterator->valid());
42  }
43 
45  {
46  $iterator = new ilCtrlArrayIterator([
47  'entry0',
48  'entry1',
49  'entry2',
50  ]);
51 
52  $this->assertFalse($iterator->valid());
53  $this->assertNull($iterator->current());
54  $this->assertNull($iterator->key());
55  }
56 
57  public function testArrayIteratorWithMixedArray(): void
58  {
59  $iterator = new ilCtrlArrayIterator([
60  'key0' => 0,
61  1 => 'entry1',
62  2 => 2,
63  'key3' => 'entry3',
64  'key4' => false
65  ]);
66 
67  $this->assertTrue($iterator->valid());
68  $this->assertEquals(
69  'entry3',
70  $iterator->current()
71  );
72  $this->assertEquals(
73  'key3',
74  $iterator->key()
75  );
76 
77  $iterator->next();
78  $this->assertFalse($iterator->valid());
79  }
80 
81  public function testArrayIteratorWithEmptyArray(): void
82  {
83  $iterator = new ilCtrlArrayIterator([]);
84 
85  $this->assertFalse($iterator->valid());
86  $this->assertNull($iterator->current());
87  $this->assertNull($iterator->key());
88  }
89 }
Class ilCtrlArrayIteratorTest.
Class ilCtrlArrayIterator.
$i
Definition: metadata.php:41