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
As Anas Tiour said, if you're using procces isolation, it may kill your "main" process when you use something like "die()" (it's present behing the scenes of dd()).
If you don't need processIsolation, remove it from your phpunit.xml or change it's value to false (false is the default btw)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With