mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
add when() method
This commit is contained in:
@ -177,6 +177,26 @@ final class Expectation
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* It skips the tests in the callback if the condition is not truthy.
|
||||
*
|
||||
* @param Closure|bool|string $condition
|
||||
*/
|
||||
public function when($condition, callable $callback): Expectation
|
||||
{
|
||||
$condition = is_callable($condition)
|
||||
? $condition
|
||||
: function () use ($condition) {
|
||||
return $condition;
|
||||
};
|
||||
|
||||
if ($condition()) {
|
||||
$callback(new self($this->value));
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that two variables have the same type and
|
||||
* value. Used on objects, it asserts that two
|
||||
|
||||
Reference in New Issue
Block a user