2

When writing my test I used to be able to dump out variables using the dump and die function dd(). However on new projects it seems to throw "Test was run in child process and ended unexpectedly" whenever there is a die anywhere in the code instead of displaying the dumped variable result.

This is making developing/debugging test really difficult and slow. Has anyone else experienced this recently?

I am currently using phpUnit version 9.5.2 and can confirm that this does work in this same version on other projects.

I am also running this in PhpStorm's built in test UI and running Drupal 9.2

Jimmyb_1991
  • 346
  • 5
  • 12
  • Does this answer your question? [How do you use PHPUnit to test a function if that function is supposed to kill PHP?](https://stackoverflow.com/questions/1347794/how-do-you-use-phpunit-to-test-a-function-if-that-function-is-supposed-to-kill-p) – SteeveDroz Sep 27 '21 at 05:59

1 Answers1

0

First off, if you want to avoid this problem, use var_dump and print_r instead of dd.

The message Test was run in child process and ended unexpectedly is due to the test process dying, as expected from the dd function (dump & die).

I also highly suspect that you are using PHPUnit process isolation.

As to why the variable is not printed, then I do not have any idea. Maybe a code snippet to reproduce the error would be helpful.

For information: I am using PHPUnit 10.3.2 and writing unit tests for a Laravel API in version 10.19.0.

Anas Tiour
  • 1,344
  • 3
  • 17
  • 33