3

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?

2 Answers2

4

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.
LazyOne
  • 516
1

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.

Source: https://confluence.jetbrains.com/display/PhpStorm/Running+PHPUnit+tests+over+SSH+on+a+remote+server+with+PhpStorm