Merge branch 'master' into nested-higher-order-expectations

# Conflicts:
#	tests/.snapshots/success.txt
This commit is contained in:
luke
2021-06-18 22:01:30 +01:00
3 changed files with 31 additions and 7 deletions

View File

@ -127,7 +127,7 @@ final class Expectation
if (is_callable($callback)) {
foreach ($this->value as $item) {
$callback(expect($item));
$callback(new self($item));
}
}
@ -136,8 +136,12 @@ final class Expectation
/**
* Allows you to specify a sequential set of expectations for each item in a iterable "value".
*
* @template TValue
*
* @param callable(self, self): void|TValue ...$callbacks
*/
public function sequence(callable ...$callbacks): Expectation
public function sequence(...$callbacks): Expectation
{
if (!is_iterable($this->value)) {
throw new BadMethodCallException('Expectation value is not iterable.');
@ -155,7 +159,12 @@ final class Expectation
}
foreach ($values as $key => $item) {
call_user_func($callbacks[$key], expect($item), expect($keys[$key]));
if (is_callable($callbacks[$key])) {
call_user_func($callbacks[$key], new self($item), new self($keys[$key]));
continue;
}
(new self($item))->toEqual($callbacks[$key]);
}
return $this;