mirror of
https://github.com/pestphp/pest.git
synced 2026-03-12 10:47:25 +01:00
feat: adds ddWhen and ddUnless
This commit is contained in:
@ -130,27 +130,35 @@ final class Expectation
|
|||||||
/**
|
/**
|
||||||
* Dump the expectation value when the result of the condition is truthy.
|
* Dump the expectation value when the result of the condition is truthy.
|
||||||
*
|
*
|
||||||
* @param bool $boolean
|
* @param (\Closure(TValue): bool)|bool $condition
|
||||||
* @return never
|
* @return self<TValue>
|
||||||
*/
|
*/
|
||||||
public function ddWhen($boolean, mixed ...$arguments): void
|
public function ddWhen(Closure|bool $condition, mixed ...$arguments): Expectation
|
||||||
{
|
{
|
||||||
if (! $boolean) {
|
$condition = $condition instanceof Closure ? $condition($this->value) : $condition;
|
||||||
return;
|
|
||||||
|
if (! $condition) {
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->dd($this->value, ...$arguments);
|
$this->dd(...$arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dump the expectation value when the result of the condition is falsy.
|
* Dump the expectation value when the result of the condition is falsy.
|
||||||
*
|
*
|
||||||
* @param bool $boolean
|
* @param (\Closure(TValue): bool)|bool $condition
|
||||||
* @return never
|
* @return self<TValue>
|
||||||
*/
|
*/
|
||||||
public function ddUnless($boolean, mixed ...$arguments): void
|
public function ddUnless(Closure|bool $condition, mixed ...$arguments): Expectation
|
||||||
{
|
{
|
||||||
$this->ddWhen(! $boolean, ...$arguments);
|
$condition = $condition instanceof Closure ? $condition($this->value) : $condition;
|
||||||
|
|
||||||
|
if ($condition) {
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->dd(...$arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user