diff --git a/src/Runtime/ClientObjectCollection.php b/src/Runtime/ClientObjectCollection.php index 61d0951c..a077a022 100644 --- a/src/Runtime/ClientObjectCollection.php +++ b/src/Runtime/ClientObjectCollection.php @@ -369,8 +369,8 @@ public function getIterator(): Traversable } if($this->pagedMode){ - $nextItems = $this->getNext()->executeQuery(); if($this->hasNext()){ + $nextItems = $this->getNext()->executeQuery(); foreach ($nextItems as $item){ yield $item; } diff --git a/tests/sharepoint/ListItemTest.php b/tests/sharepoint/ListItemTest.php index 23a5bb28..7040374d 100644 --- a/tests/sharepoint/ListItemTest.php +++ b/tests/sharepoint/ListItemTest.php @@ -38,6 +38,23 @@ public function testItemsCount() $this->assertEquals($itemsCount, $items->getCount()); } + public function testIterator() + { + // Test that list items can be iterated over without crashing + // First, test a simple get with no paging + foreach (self::$targetList->getItems()->get()->executeQuery() as $item) { + $this->assertNotEmpty($item); + } + // Now test with explicit paging + foreach (self::$targetList->getItems()->get()->paged(1)->executeQuery() as $item) { + $this->assertNotEmpty($item); + } + // Now test with implicit paging via getAll() + foreach (self::$targetList->getItems()->getAll()->executeQuery() as $item) { + $this->assertNotEmpty($item); + } + } + public function testCreateFolderInList(){ //ensure Folder creation is enabled for a List