New in 4.0: Code Coverage for PHPUnit


We continue developing integration with tools essential for each developer who cares about the quality of his code. This time we want to introduce you Code Coverage for PHPUnit. What is Code Coverage for PHPUnit? It shows you how much of your code is covered with tests and marks covered and uncovered lines visually right in the editor.

Code coverage metrics in 'Project View'

Covered and uncovered line marks in the editor

Let’s try to get your first code coverage measurement in PhpStorm!

  1. Enable Xdebug or Zend Debugger extension in your PHP interpreter configuration (see Xdebug installation guide and Zend Debugger installation guide).
  2. Choose an existing ‘PHPUnit’ run configuration or create a new one.
  3. Launch the run configuration using the new ‘Coverage’ button.

‘Coverage’ button in ‘Run’ menu

That is all!

Download PhpStorm & WebStorm 4.0 EAP and don’t forget to provide feedback in the issue tracker 😉

Develop with pleasure!

Comments below can no longer be edited.

23 Responses to New in 4.0: Code Coverage for PHPUnit

  1. Patrick says:

    February 21, 2012

    Great feature! I’ll upgrade to 4.0 these days

    All features sounds really great 🙂

  2. Andriy Bazanov says:

    February 21, 2012

    Very good — thanks Nikolay. Too bad it does not work on Windows (at least for me) — WI-9418 .

    Few questions:
    1) How to remove those (XX% lines covered) if I do not want to see them any more (without re-opening project). There should be some “switch” available (I think IDEA has it, although unsure on this one).
    2) Is there possibility to display such (XX% lines covered) for source files only, and not for the test files itself? Right now *all* files/folders have that text, despite the fact that my “tests” folder is marked as Test Source Root. Maybe it is worth bringing “Source Root” mark from IDEA (blue folder icon, so only files in this folder and subfolders will have that coverage text)?
    3) Is there possibility to have whole line highlighted not just gutter? At least temporarily? Much easier to see those tested/untested lines.

    • Alexey Gopachenko says:

      February 21, 2012

      Good points. File all as feature requests for 4.0 🙂
      And the one below as a problem 🙂

      • Andriy Bazanov says:

        February 22, 2012

        1) I have found such action (actually 2) using Help | Find Action:
        – 1.1) Hide coverage information (has no shortcut) and is from 1.3 panel
        – 1.2) Show Code Coverage Data (Ctrl+Alt+F6). It is NOT listed anywhere in main menu, so I had to use “Include non-menu actions” option, which most people simply forgetting to use. In any case — I think this action should be available in main menu somewhere. I think about submitting a ticket about this…
        – 1.3) By clicking on Coverage marker in editor gutter — it shows some small poup window, which has that action from 1.1 (although by default it is hidden, as popup is too narrow, and only fits 3 out of 4 buttons). Ticket is coming…

        2) Originally I’ve tested it using only built-in Coverage report. because such coverage.xml file is not generated properly ( WI-9418 ) it displayed that “XX% lines covered” test for all folders. Later, at home, I have discovered that I can generate proper coverage.xml with phpunit itself and provide that file to PhpStorm via “Show Code Coverage Data” screen — now my tests files do not have that coverage text next to them. This point is now obsolete (as far as I’m concerned) as once that aforementioned issue will be resolved, it should be good (at least that’s what I’m expecting).

        3) WI-9907

        • nnmatveev says:

          February 22, 2012

          Thanks for constructive feedback! 1.1 and 1.2 – fixed. See ‘Tools’ menu in the next EAP. 1.3 – assigned to the responsible developer (not me).

  3. Andriy Bazanov says:

    February 21, 2012

    If my PHPUnit xml config defines custom clover coverage file and PHPUnit test is run with Coverage button, then my coverage.xml is not generated. I think you should make this moment clear as I think there will be questions “where is MY coverage.xml” in the future (I do not think you can safely rely on using my own coverage.xml as it may be deleted at any time, while your one will still be available (because of where it is stored)).

    • nnmatveev says:

      February 22, 2012

      Our Xdebug code coverage based on PHPUnit functionality – we just pass ‘–coverage-clover’ option through command line (with path to our internal output file). If you have this option in your configuration file it will be overridden. We can’t do anything with that.

      • Andriy Bazanov says:

        February 22, 2012

        I understand that, that’s why I suggested to make this moment clear in documentation (or somewhere else), otherwise you may hear these “where is *MY* coverage.xml file” type of questions.

        • nnmatveev says:

          February 22, 2012

          I see your point, but you won’t need to have your clover.xml file since PhpStorm 4.0.

  4. Andriy Bazanov says:

    February 22, 2012

    Have few more questions (will ask one at a time).
    View | Tool windows | Coverage — is that the same as Coverage popup when clicking on coverage marker in editor gutter .. or something else? I’m asking because it is seems to be disabled all the time.

    • nnmatveev says:

      February 22, 2012

      Fixed. Thanks;)

  5. Edgar Martinez says:

    February 25, 2012

    Bee waiting for this for a while since xdebug doesn’t play well with zend on windows and PHPUnit needed it for code coverage. Going to test it out. Thanks for the new feature

  6. Edgar Martinez says:

    February 26, 2012

    OK I so I actually tested this out but it isnt showing any lines as covered even though they are being run and tests are passing. Everything shows as uncovered and the gutter is red for all the methods. Is there an clover.xml I am supposed to point it to or a PHPUnit report I am supposed to generate in the configuration file I am using Windows

    • nnmatveev says:

      February 26, 2012

      What extension do you use – Xdebug or Zend Debugger?

  7. Sebastiaan Stok says:

    February 28, 2012


    One little suggestion, PHPUnit supports creating an HTML coverage report including the Change Risk Analysis and Predictions.

    It would be great to also see this the result 🙂

    Keep up the good work.

  8. Rene says:

    February 28, 2012

    When PHPUnit terminates because of memory exhaustion PHPStorm would not report it but instead simply omit all coverage info. No coverage data is being shown then. FYI

    • Sergey Kovalev says:

      May 29, 2012

      As the very quick solution, try to comment out verification of uncovered files in code coverage. It works for big projects like magento and symfony.

      line #170

      * Returns the collected code coverage data.
      * @return array
      * @since Method available since Release 1.1.0
      public function getData()
      if ($this->processUncoveredFilesFromWhitelist) {

      // We need to apply the blacklist filter a second time
      // when no whitelist is used.
      if (!$this->filter->hasWhitelist()) {
      return $this->data;

  9. aimfeld says:

    April 25, 2012

    Does not work for me (Windows 7, PHPStorm 4.0.1, Zend_Debugger). I can debug my tests perfectly but the coverage results show all code lines as uncovered (red bars on the left of the editor). The debugger stops on breakpoints set on these lines, though.

    The code coverage window opens and shows my folders after running code coverage. The title of the window says “Coverage Summary: null” and the “Statistics %” column is empty.

    Is it even supposed to work with Zend_Debugger or do I need Xdebug? Xdebug is listed as a requirement here:

    Any suggestions?

  10. Josef van Niekerk says:

    April 28, 2012

    Please refer to this StackOverflow question.

    I have no idea how to get code coverage to show up in my Symfony2 project. Any ideas?

    • nnmatveev says:

      May 2, 2012

      Please answer to CrazyCoder on the StackOverflow

  11. PhpStorm - Dương Quốc Việt Blog says:

    July 18, 2012

    […] Read more in our blog » […]