implemented pipe closure with $next as the first parameter

This commit is contained in:
Fabio Ivona
2021-10-10 01:02:04 +02:00
parent bc4e5b9b4e
commit fc53f08e37
6 changed files with 55 additions and 87 deletions

View File

@ -19,7 +19,7 @@ use PHPUnit\Framework\ExpectationFailedException;
* @template TValue
*
* @property Expectation $not Creates the opposite expectation.
* @property Each $each Creates an expectation on each element on the traversable value.
* @property Each $each Creates an expectation on each element on the traversable value.
*
* @mixin CoreExpectation
*/
@ -137,16 +137,16 @@ 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;
while (count($callbacks) < count($values)) {
$callbacks[] = $callbacks[$index];
$index = $index < count($values) - 1 ? $index + 1 : 0;
$index = $index < count($values) - 1 ? $index + 1 : 0;
}
if ($callbacksCount > count($values)) {
@ -170,7 +170,7 @@ final class Expectation
*
* @template TMatchSubject of array-key
*
* @param callable(): TMatchSubject|TMatchSubject $subject
* @param callable(): TMatchSubject|TMatchSubject $subject
* @param array<TMatchSubject, (callable(Expectation<TValue>): mixed)|TValue> $expressions
*/
public function match($subject, array $expressions): Expectation
@ -273,9 +273,16 @@ final class Expectation
private function getExpectationClosure(string $name): Closure
{
if (method_exists($this->coreExpectation, $name)) {
//@phpstan-ignore-next-line
return Closure::fromCallable([$this->coreExpectation, $name]);
} elseif (self::hasExtend($name)) {
return self::$extends[$name];
}
if (self::hasExtend($name)) {
$extend = self::$extends[$name]->bindTo($this, Expectation::class);
if ($extend != false) {
return $extend;
}
}
throw PipeException::expectationNotFound($name);