From ea967b439f9d987ba0711e41b031ca02dcb33a99 Mon Sep 17 00:00:00 2001 From: AJ Meireles Date: Mon, 17 Jul 2023 11:08:00 -0300 Subject: [PATCH 1/3] Feature: Introducing The Ability to Dump Conditionally --- src/Expectation.php | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/Expectation.php b/src/Expectation.php index cb9b0361..1733541c 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -118,6 +118,48 @@ final class Expectation exit(1); } + /** + * Dump the expectation value when the result of the condition is truthy. + * + * @param bool $boolean + * @return never + */ + public function ddWhen($boolean, mixed ...$arguments): void + { + if (! $boolean) { + return; + } + + if (function_exists('dd')) { + dd($this->value, ...$arguments); + } + + var_dump($this->value); + + exit(1); + } + + /** + * Dump the expectation value when the result of the condition is falsy. + * + * @param bool $boolean + * @return never + */ + public function ddUnless($boolean, mixed ...$arguments): void + { + if ($boolean) { + return; + } + + if (function_exists('dd')) { + dd($this->value, ...$arguments); + } + + var_dump($this->value); + + exit(1); + } + /** * Send the expectation value to Ray along with all given arguments. * From 8abc0d192039b5328de4c4b050dfce2d64e2dd66 Mon Sep 17 00:00:00 2001 From: AJ Meireles Date: Mon, 17 Jul 2023 14:12:54 -0300 Subject: [PATCH 2/3] applying enhancement to use ddWhen inside ddUnless --- src/Expectation.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/Expectation.php b/src/Expectation.php index 1733541c..5328052b 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -147,17 +147,7 @@ final class Expectation */ public function ddUnless($boolean, mixed ...$arguments): void { - if ($boolean) { - return; - } - - if (function_exists('dd')) { - dd($this->value, ...$arguments); - } - - var_dump($this->value); - - exit(1); + $this->ddWhen(! $boolean, ...$arguments); } /** From b00bc4d5ea8186b31ef2df14b16db0e8471591aa Mon Sep 17 00:00:00 2001 From: AJ Meireles Date: Mon, 17 Jul 2023 19:11:06 -0300 Subject: [PATCH 3/3] applying enhancement to use single dd function --- src/Expectation.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Expectation.php b/src/Expectation.php index 5328052b..c8f60d25 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -130,13 +130,7 @@ final class Expectation return; } - if (function_exists('dd')) { - dd($this->value, ...$arguments); - } - - var_dump($this->value); - - exit(1); + $this->dd($this->value, ...$arguments); } /**