From be49a3ce18d7271419cd86c7bcbbb99b44773dbc Mon Sep 17 00:00:00 2001 From: Punyapal Shah <53343069+MrPunyapal@users.noreply.github.com> Date: Thu, 11 Jun 2026 14:46:07 +0530 Subject: [PATCH] Fix: dd (#1692) * fix: update dd method to return never type Co-authored-by: Copilot * fix: enhance var_dump calls to accept additional arguments * fix: update dd method to handle paratest and collision printer environments * test: add dd method tests for ExpectationFailedException in parallel mode Co-authored-by: Copilot --------- Co-authored-by: Copilot --- src/Expectation.php | 16 +++++++++++---- tests/Features/Expect/dd.php | 39 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 tests/Features/Expect/dd.php diff --git a/src/Expectation.php b/src/Expectation.php index 69bf52f3..c9fd2d6b 100644 --- a/src/Expectation.php +++ b/src/Expectation.php @@ -112,7 +112,7 @@ final class Expectation if (function_exists('dump')) { dump($this->value, ...$arguments); } else { - var_dump($this->value); + var_dump($this->value, ...$arguments); } return $this; @@ -123,15 +123,23 @@ final class Expectation * * @return never */ - public function dd(mixed ...$arguments): void + public function dd(mixed ...$arguments): never { if (function_exists('dd')) { dd($this->value, ...$arguments); } - var_dump($this->value); + if (getenv('PARATEST') !== false || isset($_SERVER['COLLISION_PRINTER'])) { + ob_start(); + var_dump($this->value, ...$arguments); + $output = (string) ob_get_clean(); - exit(1); + throw new ExpectationFailedException($output); + } + + var_dump($this->value, ...$arguments); + + exit(0); } /** diff --git a/tests/Features/Expect/dd.php b/tests/Features/Expect/dd.php new file mode 100644 index 00000000..a658178a --- /dev/null +++ b/tests/Features/Expect/dd.php @@ -0,0 +1,39 @@ +dd(); + } catch (ExpectationFailedException $e) { + expect($e->getMessage())->toContain('42'); + } finally { + putenv('PARATEST'); + } +}); + +it('dd throws ExpectationFailedException with all dumped arguments in parallel mode', function () { + putenv('PARATEST=1'); + + try { + expect('hello')->dd('extra'); + } catch (ExpectationFailedException $e) { + expect($e->getMessage()) + ->toContain('hello') + ->toContain('extra'); + } finally { + putenv('PARATEST'); + } +}); + +it('dd throws ExpectationFailedException with dumped value when running under pest', function () { + expect($_SERVER['COLLISION_PRINTER'])->toBe('DefaultPrinter'); + + try { + expect(42)->dd(); + } catch (ExpectationFailedException $e) { + expect($e->getMessage())->toContain('42'); + } +}); \ No newline at end of file