diff --git a/src/Collection/Collection.php b/src/Collection/Collection.php index d243cae4750..ba9e47eff26 100644 --- a/src/Collection/Collection.php +++ b/src/Collection/Collection.php @@ -73,25 +73,17 @@ public function unserialize($collection) } /** - * Dynamic method handler + * Throws an exception. * - * Collections do not allow access to methods of the inner iterator, - * if that iterator is one of the PHP base classes as many of - * these methods allow in-place mutation which breaks the immutability - * Collection tries to provide. + * Collection doesn't permit access to methods of the inner iterator. * * @param string $name Method name. * @param array $args Method arguments. - * @return mixed + * @return void * @throws \BadMethodCallException */ public function __call($name, $args) { - if (!method_exists(ArrayIterator::class, $name)) { - $inner = $this->getInnerIterator(); - - return call_user_func_array([$inner, $name], $args); - } throw new BadMethodCallException(sprintf('Call to undefined method %s::%s()', get_class($this), $name)); } diff --git a/tests/TestCase/Collection/CollectionTest.php b/tests/TestCase/Collection/CollectionTest.php index b7868fa5e82..e47629f3c20 100644 --- a/tests/TestCase/Collection/CollectionTest.php +++ b/tests/TestCase/Collection/CollectionTest.php @@ -2547,7 +2547,7 @@ public function testArrayIteratorExtend() $this->assertTrue(method_exists($iterator, 'checkValues')); $this->assertTrue($iterator->checkValues()); - // We need to perform at least two collection operation to trigger the issue. + //We need to perform at least two collection operation to trigger the issue. $newIterator = $iterator ->filter(function ($item) { return $item < 5; @@ -2556,6 +2556,7 @@ public function testArrayIteratorExtend() return $item > 2; }); + $this->assertTrue(method_exists($newIterator, 'checkValues'), 'Our method has gone missing!'); $this->assertTrue($newIterator->checkValues()); $this->assertCount(3, $newIterator->toArray()); }