From 12e63c7376659dc57ca33ad03b23a420b6e29499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mert=20A=C5=9Fan?= Date: Thu, 16 Sep 2021 18:09:45 +0300 Subject: [PATCH] add new assertion --- src/Expectation.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Expectation.php b/src/Expectation.php index 253b1e1e..9ec55142 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -154,9 +154,10 @@ final class Expectation throw new BadMethodCallException('Expectation value is not iterable.'); } - $value = is_array($this->value) ? $this->value : iterator_to_array($this->value); - $keys = array_keys($value); - $values = array_values($value); + $value = is_array($this->value) ? $this->value : iterator_to_array($this->value); + $keys = array_keys($value); + $values = array_values($value); + $callbacksCount = count($callbacks); $index = 0; @@ -165,6 +166,10 @@ final class Expectation $index = $index < count($values) - 1 ? $index + 1 : 0; } + if ($callbacksCount > count($values)) { + Assert::assertLessThanOrEqual(count($value), count($callbacks)); + } + foreach ($values as $key => $item) { if (is_callable($callbacks[$key])) { call_user_func($callbacks[$key], new self($item), new self($keys[$key]));