Fixing PhpStorm cannot find a local copy of Standard Input Code
Recently, I set up my PHP dev environment to allow me to step debug from unit tests that I run with make unit
The relevant parts of Makefile look like this:
# Set DEBUG=1 to enable Xdebug ifeq ($(origin DEBUG),undefined) XDEBUG := else XDEBUG := XDEBUG_SESSION=PHPSTORM endif unit: ## Run unit tests docker compose exec php bash -c "$(XDEBUG) vendor/bin/phpunit --testsuite=unit"
I can now set a break point and run the unit tests with Xdebug enabled with DEBUG=1 make unit.
I have an environment variable set in compose.yaml: PHP_IDE_CONFIG=serverName=project.com.localhost and I use to set up the mappings in PhpStorm’s settings. As we’re using Docker, I also have xdebug.client_host = host.docker.internal set up in my PHP ini settings.
I noticed that when I didn’t have a breakpoint set, PhpStorm would break with this error in Debug console for a particular test:
That’s a strange error message: “Cannot find a local copy of the file on server /var/www/html/Standard input code”! Clearly I don’t have a file called “Standard input code” and so it’s not surprising that PhpStorm can’t map to it.
Google to the rescue!
I eventually worked out that it’s related to having a test with the @runInSeparateProcess annotation. As a result, phpunit does some magic and Xdebug sends through a file that it has labeled as “Standard input code” – presumably as it was injected via stdin..
To fix this, I disabled these PhpStorm settings in PHP -> Debug:
- “Break at first line in PHP scripts” in the External connections section
- “Force break at first line when no path mapping specified” in the Xdebug section
In PhpStorm 2024, it looks like this:
Of course, you’ll have to manually set up path mappings in PHP -> Servers, but I do that anyway, so not really a problem for me, at least.
Problem solved!