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