Skip to content

Commit

Permalink
Merge pull request #337 from CoInvestor/fix-getAll
Browse files Browse the repository at this point in the history
Fix: Don't try to retrieve next set of items when using an iterator, if no next items are expected to exist
  • Loading branch information
vgrem authored Nov 8, 2023
2 parents 2146c92 + e254517 commit e41cb80
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Runtime/ClientObjectCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 17 additions & 0 deletions tests/sharepoint/ListItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e41cb80

Please sign in to comment.