diff --git a/framework/Collections/TPriorityMap.php b/framework/Collections/TPriorityMap.php index 8e8c824dc..9ec3fea9a 100644 --- a/framework/Collections/TPriorityMap.php +++ b/framework/Collections/TPriorityMap.php @@ -98,6 +98,15 @@ private function getPriorityCombineStyle(): bool return false; } + /** + * @return int This is the key for the next appended item that doesn't have its + * own key. + */ + public function getNextIntegerKey(): int + { + return $this->_ic; + } + /** * @return int the number of items in the map */ diff --git a/tests/unit/Collections/TPriorityMapTest.php b/tests/unit/Collections/TPriorityMapTest.php index 9dec2608f..ae9a27c95 100644 --- a/tests/unit/Collections/TPriorityMapTest.php +++ b/tests/unit/Collections/TPriorityMapTest.php @@ -288,15 +288,24 @@ public function testArrayReadTPriorityMap() public function testArrayWriteTPriorityMap() { + $this->assertEquals(0, $this->map->getNextIntegerKey()); $this->map[] = $this->item1; + $this->assertEquals(1, $this->map->getNextIntegerKey()); $this->map->add(null, $this->item2, 15); + $this->assertEquals(2, $this->map->getNextIntegerKey()); $this->map[] = $this->item3; + $this->assertEquals(3, $this->map->getNextIntegerKey()); $this->map->add(null, $this->item4, 5); + $this->assertEquals(4, $this->map->getNextIntegerKey()); $this->assertEquals($this->item1, $this->map[0]); $this->assertEquals($this->item2, $this->map[1]); $this->assertEquals($this->item3, $this->map[2]); $this->assertEquals($this->item4, $this->map[3]); $this->assertNull($this->map[4]); + + $this->map[11] = $this->item1; + $this->assertEquals($this->item1, $this->map[11]); + $this->assertEquals(12, $this->map->getNextIntegerKey()); } // ** End TMap tests on TPriorityMap