diff --git a/core/lib/Drupal/Core/Entity/ChunkedIterator.php b/core/lib/Drupal/Core/Entity/ChunkedIterator.php index faad0fc..fefc13e 100644 --- a/core/lib/Drupal/Core/Entity/ChunkedIterator.php +++ b/core/lib/Drupal/Core/Entity/ChunkedIterator.php @@ -45,7 +45,9 @@ class ChunkedIterator implements \IteratorAggregate, \Countable { * @param int $chunk_size */ public function __construct(EntityStorageInterface $entity_storage_controller, array $ids, $chunk_size = 50) { - $this->entityStorage = $entity_storage_controller; + // Create a clone of the storage controller so the static cache of the + // actual storage controller remains intact. + $this->entityStorage = clone $entity_storage_controller; // Make sure we don't use a keyed array. $this->entityIds = array_values($ids); $this->chunkSize = (int) $chunk_size; diff --git a/core/tests/Drupal/Tests/Core/Entity/ChunkedIteratorTest.php b/core/tests/Drupal/Tests/Core/Entity/ChunkedIteratorTest.php index 136867a..649a1ac 100644 --- a/core/tests/Drupal/Tests/Core/Entity/ChunkedIteratorTest.php +++ b/core/tests/Drupal/Tests/Core/Entity/ChunkedIteratorTest.php @@ -56,10 +56,7 @@ public function testIterationWithNoItems() { $this->entityStorage->loadMultiple()->shouldNotBeCalled(); $iterator = new ChunkedIterator($this->entityStorage->reveal(), []); - - foreach ($iterator as $entity) { - - } + iterator_to_array($iterator); } /** @@ -73,10 +70,7 @@ public function testIteratorWithNoValidItems() { ->shouldBeCalled(); $iterator = new ChunkedIterator($this->entityStorage->reveal(), [1,2,3]); - - foreach ($iterator as $entity) { - - } + iterator_to_array($iterator); } /**