add when() method

This commit is contained in:
Mert Aşan
2021-09-23 03:35:41 +03:00
parent facbf05016
commit 847b06e558

View File

@ -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