mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
Merge branch 'master' into method-match
This commit is contained in:
@ -221,15 +221,16 @@ final class Expectation
|
||||
}
|
||||
|
||||
/**
|
||||
* It skips the tests in the callback if the condition is not truthy.
|
||||
* Apply the callback if the given "condition" is truthy.
|
||||
*
|
||||
* @param Closure|bool|string $condition
|
||||
* @param (callable(): bool)|bool $condition
|
||||
* @param callable(Expectation<TValue>): mixed $callback
|
||||
*/
|
||||
public function when($condition, callable $callback): Expectation
|
||||
{
|
||||
$condition = is_callable($condition)
|
||||
? $condition
|
||||
: function () use ($condition) {
|
||||
: static function () use ($condition): mixed {
|
||||
return $condition;
|
||||
};
|
||||
|
||||
|
||||
@ -78,6 +78,26 @@ final class TestCall
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Asserts that the test throws the given `$exceptionClass` when called if the given condition is true.
|
||||
*
|
||||
* @param (callable(): bool)|bool $condition
|
||||
*/
|
||||
public function throwsIf($condition, string $exception, string $exceptionMessage = null): TestCall
|
||||
{
|
||||
$condition = is_callable($condition)
|
||||
? $condition
|
||||
: static function () use ($condition): mixed {
|
||||
return $condition;
|
||||
};
|
||||
|
||||
if ($condition()) {
|
||||
return $this->throws($exception, $exceptionMessage);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the current test multiple times with
|
||||
* each item of the given `iterable`.
|
||||
|
||||
Reference in New Issue
Block a user