mirror of
https://github.com/pestphp/pest.git
synced 2026-06-11 21:48:26 +02:00
Fix: dd (#1692)
* fix: update dd method to return never type Co-authored-by: Copilot <copilot@github.com> * 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 <copilot@github.com> --------- Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
39
tests/Features/Expect/dd.php
Normal file
39
tests/Features/Expect/dd.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use PHPUnit\Framework\ExpectationFailedException;
|
||||
|
||||
it('dd throws ExpectationFailedException with dumped value in parallel mode', function () {
|
||||
putenv('PARATEST=1');
|
||||
|
||||
try {
|
||||
expect(42)->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');
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user