Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am working in the following setup:

There is a development VM running, where I can access the codebase and use it as project location in PhpStorm. Everything (nginx, database, phpunit, ...) is running on that VM. I have a network drive connected to that VM, but am limited to access the checkout directory.

I configured PHPUnit to create a coverage.xml that I can access from my host.

Now, I want to use that data to show me the code coverage in PHPStorm, but it looks like there is no way to use an externally generated coverage file for this. I am running the unit tests remotely on the VM, not using the IDE features (because I can't find a way to run the tests remotely).

Is there any tweak or option that I did not recognize?

share|improve this question

migrated from Mar 13 '13 at 18:06

This question came from our site for professional and enthusiast programmers.

The only idea that comes to mind is to take a look how PHPstorm invokes phpunit (it always creates some PHP file which then is executed), maybe you can modify the template and then inject the data from the remote system. AFAIK Phpstorm does not have the concept that Phpunit is not executed on the code in the IDE; Phpstorm does not have the concept that Phpunit is executed on code in some other system. – hakre Mar 13 '13 at 10:20
up vote 4 down vote accepted

Yes, you can use any coverage.xml inside IDE as long as it has correct file names (even if it was generated somewhere else). But it has to be done manually and is not very convenient to use on frequent basis.

The idea is:

  1. Run your PHPUnit tests on remote machine and generate coverage.xml.
  2. Process it using any suitable tool to replace remote paths by local path (e.g. some custom Phing target; simple find+replace in your text editor or whatever). That's, of course, if remote paths differ from local. Otherwise just skip it.
  3. Tell IDE to use this file to display coverage details via Tools | Show Code Coverage Data -- attach required file there.
    Please note: most likely (have not used this myself for a long time, so possibly it has been changed since then) you will have to remove and then add again such file every time you get new coverage.xml (that's the biggest annoyance) -- IDE caches content of such file. Check this ticket for some details.
share|improve this answer
Thanks a lot, I tried this in PHPStorm 5 and it did not work. I'll try in PHPStorm 6 – nico gawenda Mar 13 '13 at 15:42
I've used this when this functionality was just introduced in PhpStorm (v4 or 5) and built-in coverage was not working properly (due to a specific bug with file locations). The only difference to what I did before is the file paths. – LazyOne Mar 13 '13 at 15:59
I just tried: if I run phpunit outside of IDE (from command line) and generate coverage.xml file there, I can then attach it to IDE using the 3rd step with no issues. Possibly it works for you (if you have correct paths) .. but default coverage colors are too faded/light and you just cannot see them? (by default only small area in editor gutter is highlighted) – LazyOne Mar 13 '13 at 16:02
Bam. Works. No idea what went wrong the first try, excellent, thanks a lot! – nico gawenda Mar 14 '13 at 8:42

Update: At least as of PHPStorm 2016.1 or possibly before (e.g. Version 9 or 10) you can automatically get PHPUnit code coverage by using PHPUnit over SSH Server. You have to first add a Remote PHP Interpreter using the steps in the official guide. Then, simply choose this as your default Project PHP Interpreter. When you run a test you can click "Run 'MyTest' with Coverage" and it automatically copies and loads the coverage file over SSH.


share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .