phpunit functional test first base: 'server can't be found'

I have xdebug working for my local server running in Parallels. 

Now I want to start functional tests in phpunit. Running from the CLI in php 7.1.13 I find that the test fails at a certain point and I thought, "Hey, PHPStorm has breakpoints" but find that there's a whole lot more that needs to be done.

The error is "Cannot parse server name for external Xdebug connection"

I'm hoping to keep testing and debugging in the browser separate.

echo $XDEBUG_CONFIG => idekey=452

echo $PHP_IDE_CONFIG => serverName=localhost

/Users/sam/.phpbrew/php/php-7.1.13/bin/php -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host= -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host= -dxdebug.remote_connect_back=0 /Users/sam/apps/8habi/vendor/phpunit/phpunit/phpunit --configuration /Users/sam/apps/8habi/core/phpunit.xml Drupal\Tests\calendar_admin\Functional\CreateABuildTest /Users/sam/apps/8habi/modules/custom/calendar_admin/tests/src/Functional/CreateABuildTest.php --teamcity

My local php on the OSX cli has xdebug running

php -i | grep "xdebug"

Additional .ini files parsed => /Users/sam/.phpbrew/php/php-7.1.13/var/db/xdebug.ini


xdebug support => enabled

xdebug.auto_trace => Off => Off

xdebug.cli_color => 0 => 0

xdebug.collect_assignments => Off => Off

xdebug.collect_includes => On => On

xdebug.collect_params => 0 => 0

xdebug.collect_return => Off => Off

xdebug.collect_vars => Off => Off

xdebug.coverage_enable => On => On

xdebug.default_enable => On => On

xdebug.dump.COOKIE => no value => no value

xdebug.dump.ENV => no value => no value

xdebug.dump.FILES => no value => no value

xdebug.dump.GET => no value => no value

xdebug.dump.POST => no value => no value

xdebug.dump.REQUEST => no value => no value

xdebug.dump.SERVER => no value => no value

xdebug.dump.SESSION => no value => no value

xdebug.dump_globals => On => On

xdebug.dump_once => On => On

xdebug.dump_undefined => Off => Off

xdebug.extended_info => On => On

xdebug.file_link_format => no value => no value

xdebug.filename_format => no value => no value

xdebug.force_display_errors => Off => Off

xdebug.force_error_reporting => 0 => 0

xdebug.gc_stats_enable => Off => Off

xdebug.gc_stats_output_dir => /var/tmp/ => /var/tmp/

xdebug.gc_stats_output_name => gcstats.%p => gcstats.%p

xdebug.halt_level => 0 => 0

xdebug.idekey => no value => no value

xdebug.max_nesting_level => 256 => 256

xdebug.max_stack_frames => -1 => -1

xdebug.overload_var_dump => 2 => 2

xdebug.profiler_aggregate => Off => Off

xdebug.profiler_append => Off => Off

xdebug.profiler_enable => Off => Off

xdebug.profiler_enable_trigger => Off => Off

xdebug.profiler_enable_trigger_value => no value => no value

xdebug.profiler_output_dir => /var/tmp/ => /var/tmp/

xdebug.profiler_output_name => cachegrind.out.%p => cachegrind.out.%p

xdebug.remote_addr_header => no value => no value

xdebug.remote_autostart => Off => Off

xdebug.remote_connect_back => Off => Off

xdebug.remote_cookie_expire_time => 3600 => 3600

xdebug.remote_enable => On => On

xdebug.remote_handler => dbgp => dbgp

xdebug.remote_host => localhost => localhost

xdebug.remote_log => no value => no value

xdebug.remote_mode => req => req

xdebug.remote_port => 9000 => 9000

xdebug.remote_timeout => 200 => 200

xdebug.scream => Off => Off

xdebug.show_error_trace => Off => Off

xdebug.show_exception_trace => Off => Off

xdebug.show_local_vars => Off => Off

xdebug.show_mem_delta => Off => Off

xdebug.trace_enable_trigger => Off => Off

xdebug.trace_enable_trigger_value => no value => no value

xdebug.trace_format => 0 => 0

xdebug.trace_options => 0 => 0

xdebug.trace_output_dir => /var/tmp/ => /var/tmp/

xdebug.trace_output_name => trace.%c => trace.%c

xdebug.var_display_max_children => 128 => 128

xdebug.var_display_max_data => 512 => 512

xdebug.var_display_max_depth => 3 => 3

I set remote to on and to keep it separate, I'm using the php on local, not parallels host.

What do I need to be doing to get this to work?

Comment actions Permalink

>  I'm using the php on local, not parallels host.

> I have xdebug working for my local server running in Parallels. 


Quite confusing. Could you please clarify: are you using parallels or not?

Comment actions Permalink

Yes, the ubuntu/apache Parallels is how I use xdebug to set a breakpoint in the Drupal code to debug the application.

I use drush and the php command line on my local OSX. You'll see that PHP 7.1 is running xdebug on this local OSX.

Does phpstorm and xdebug require running Apache on my local OSX machine so that I can run phpunit tests?

Pointing my phpstorm PHP settings to the php binary in my local OSX machine appears to hijack my usage of php in the command line, particularly drush. 

Are we saying that I cannot run phpunit and xdebug unless I point phpstorm to the php binary on my Parallels/ubuntu server. While you are confused by my setup, I'm confused about how PHPStorm 2018 is supposed to work with phpunit, given that I am successful with a remote server. Thx, sam

Vladimir Luchansky
Comment actions Permalink

Taking into account the whole PHP ecosystem, we must remember that code is executed on a web server side with the help of a remote PHP interpreter.

Xdebug is a PHP extension that fetches the information from PHP interpreter and sends it to the IDE. Therefore if we have an application running at the remote web server that we want to debug and test, we need to work with its PHP interpreter.

Did you try to connect PhpStorm to the remote PHP interpreter and work with the app?

Comment actions Permalink

Thank you. Since your comment yesterday, I've attempted:

Working through each steps I attempted to run a test and it failed:

ssh:// -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9000 -dxdebug.remote_host= (where my local OSX is) /media/psf/Home/apps/8habi/vendor/phpunit/phpunit/phpunit --configuration /media/psf/Home/apps/8habi/core/phpunit.xml Drupal\\Tests\\calendar_admin\\Functional\\CreateABuildTest /Users/sam/apps/8habi/modules/custom/calendar_admin/tests/src/Functional/CreateABuildTest.php --teamcity
bash: line 0: cd: /Users/sam/apps/8habi/modules/custom/calendar_admin/tests/src/Functional: No such file or directory
Cannot open file "Drupal/Tests/calendar/admin/Functional/CreateABuildTest.php".

As you can see, the PHP | Test Frameworks | Remote PHP is set to interpret its context when it is logged into the Parallels/ubuntu machine. 

But running the test it cannot find the files. I was using the Confluence link above which indicated that the files on local were suitable. Regardless, when I edit the Run/Debug Configurations to a Directory as interpreted by the remote server I find this:

Note that the Configuration rejects the Directory path. 

I suspect that one of the settings needs to be set, but reading the docs I have no confidence how "Path Mappings" is supposed to work.

In previous (local PHP) attempts I've set Environment variables to

Because I have many PHP projects, I refuse to set my local OSX environment variable to one of many apache endpoints only have to change this EVERY time I switch between projects. Better to do it in PHPStorm 2018 in a configuration for that project only.

Help me understand how this is supposed to work, sam



Comment actions Permalink

We're still a bit lost here.

Please confirm that your initial intention is running and debugging PHPUnit tests locally, using a local PHP interpreter. Is this correct?
If so, you shouldn't use the remote interpreter as you seem to did in the last comment. Let's go back one step.

Does phpstorm and xdebug require running Apache on my local OSX machine so that I can run phpunit tests?

No, it does not. Using PHP in the CLI mode is quite enough for that.

The command you posted in the initial message looks quite legit apart from having too many Xdebug-related arguments.
Does simple running (with no debug) a PHPUnit test within PhpStorm work? Do you see expected results? If so,

The error is "Cannot parse server name for external Xdebug connection"

Could you please show a screenshot of where you see that message exactly? I have a feeling that it's probably related to the environment variables you've set, please try un-setting them.

Comment actions Permalink

Yes, there is something fighting me here. The thing is there are so many options and screens to determine, plus environment values.

I do not want to use my Parallels/server for phpunit tests and would prefer using my local PHP which is set up to allow me to do this. Thank you for confirming that I do not need to set up apache on my local to run phpunit tests, it sounded like I should based on error messages. So I removed the Remote PHP configuration. And went back through my setup as detailed in the original post.

Right-click on this one test with "Run" not debug, it's spinning and has been for a while.

The command you see here is: /Users/sam/.phpbrew/php/php-7.1.13/bin/php /Users/sam/apps/8habi/vendor/phpunit/phpunit/phpunit --configuration /Users/sam/apps/8habi/core/phpunit.xml --filter /$/ /Users/sam/apps/8habi/modules/custom/calendar_admin/tests/src/Functional/CreateABuildTest.php --teamcity

Clicking the alarm icon in the extreme left beside the "Instantiating Tests" brings up "Xebug incoming connection" which happens a lot. It's asking about every open project and clicking the correct project produces no positive changes.

In Settings > PHP > Xdebug these are deselected:

  • Break at first line in PHP Scripts
  • Force break at first line when no path mapping selected
  • Force break at first line when a script is outside the project

Is there a dump of this configuration that I could send so you could see more clearly what the issue might be?, thx, sam

Vladimir Luchansky
Comment actions Permalink

Tests are still failing while ran via CLI, correct? How do you execute PHPUnit in that case?

What about running that phpunit command from PhpStorm via CLI? What would be the result?

Comment actions Permalink

Thank you for keeping this open. Running the command still never starts, as if xdebug was waiting at a breakpoint. Shutting down PHPStorm, this command in the CLI runs the test and errors out at a point that I would like to debug. But it runs and instantiates the test:

bin/phpunit -c core/ --testsuite functional --group calendar_admin --filter CreateABuildTest

I have gotten my web server running xdebug in Parallels back running so that I can continue to debug my code.

Now back to get my start in testing I want to set a breakpoint into this failing test to see why it's failing. Turning on the "Start Listening for PHP debug connections" and running "Run > Run " on this single test the PHPStorm interface just spins forever.  As if xdebug is at a breakpoint that I cannot see.

Given that I'm happy with xdebug on my parallels server for normal code debugging, and if I'm correct in perceiving that the xdebug in my local PHP is not being picked up in running this test how do I point to my local PHP for debugging tests?

Or should I go back to try to use the parallels xdebug for debugging code and Tests as I failed in my attempt as documented above? thx, sam

Comment actions Permalink

Given that I'm happy with xdebug on my parallels server for normal code debugging, and if I'm correct in perceiving that the xdebug in my local PHP is not being picked up in running this test how do I point to my local PHP for debugging tests?

We need to understand what's happening when you are running the tests locally. Please enable Xdebug remote log for the local interpreter, try to run the test locally and share the log file with us.


Please sign in to leave a comment.