X

An Oracle blog about NetBeans for PHP

Code coverage for PHP - why not?

Guest Author

After a few days, we would like to inform you that code coverage for PHP has been added to the NetBeans IDE.

Thanks to PHPUnit (version 3.3 or newer required) we are able to provide code coverage for PHP files in a similar way as for Ruby or Python. And how it works? Well, follow these simple steps to see how "stable" your code is ;)

Note: In order to have the same functionality as shown here, be sure that you use the development version of NetBeans.

First of all, you have to enable code coverage for your project:

Enable code coverage for a PHP project

Then, just open the Code Coverage Report (from the same menu, item Show Report...):

Empty Code Coverage Report

As we can see, we don't have any results yet - it's correct, we haven't run our unit tests yet. Fortunately, we can run all the tests directly from the Report window, using Run All Tests button. The result could look like this:

Code Coverage Report with results

Finally, if you then open any of these "covered" files, you will immediately see which lines of your code are well tested and which ones need more attention:

PHP file with code coverage visualization

It would be great if you could test it and let us know if you find any error.

That's all for today, thanks for reading and we hope you enjoy this great new feature of PHP support in NetBeans!


Join the discussion

Comments ( 39 )
  • coccyx Tuesday, February 24, 2009

    Good work guys, I played a little bit with this future and it looks good ...

    Is there any roadmap for PHPUNIT plugin futures ???


  • Jozef Tuesday, February 24, 2009

    awesome, good job, thank you.

    PS in czech/slovak: Ku..a kluci, prosím vás, fixnete bug 152390, nech už môžem definitívne opustiť Eclipse PDT.


  • Tomas Mysik Tuesday, February 24, 2009

    To coccyx:

    What do you mean by "roadmap for PHPUNIT plugin futures" exactly? Is there anything you miss? Thanks.


  • Tomas Mysik Tuesday, February 24, 2009

    To Jozef:

    I updated the issue you mentioned, I think it should be fixed for Milestone 3.

    Thanks for positive feedback.


  • gawan Tuesday, February 24, 2009

    great work! thanks


  • coccyx Tuesday, February 24, 2009

    It would be nice to have history chart of passed / failed unit tests to see how the project is evolving in time.


  • Tomas Mysik Tuesday, February 24, 2009

    To gawan:

    Thanks a lot!


  • Tomas Mysik Tuesday, February 24, 2009

    To coccyx:

    This is not planned for now, sorry. If you think that NetBeans really should have such feature, feel free to file an enhancement in NB IssueZilla [1].

    Thanks for your feedback.

    [1] http://www.netbeans.org/community/issues.html


  • Stefan Wednesday, February 25, 2009

    Hello,

    I use the latest build, but I don't have the "Code Coverage" Menu option :-(

    Any help?

    Thanks,

    Stefan


  • Tomas Mysik Wednesday, February 25, 2009

    To Stefan:

    The only reason I can think of right now is the version of PHPUnit - you need at least version 3.3.0. Does it help?


  • radek Wednesday, February 25, 2009

    To Jozef (#152390):

    Is it true that you have this setup: NetBeans IDE on Windows, and apache on Solaris, Ubuntu, Mac? If so, then please be aware that #156220 was fixed and this could be source of your problem. Both issues are #156220 and #152390 are related. Please, could you test recent dev build (http://deadlock.netbeans.org/hudson/job/PHP-build/) and verify that the problem was fixed? Could you let me know if it works for you now?


  • Stephen Wednesday, February 25, 2009

    Do you have the same feature enabled for simple test unit tests (http://simpletest.org)?


  • Stephen Wednesday, February 25, 2009

    Do you have the same functionality for unit tests from simple test, simpletest.org?


  • Stephen Wednesday, February 25, 2009

    Any support for code coverage for tests using the simple test framework, its should be there in the next release


  • Jozef Wednesday, February 25, 2009

    @radek: i have sent you an email about bug #152390.


  • Tomas Mysik Wednesday, February 25, 2009

    To Stephen:

    Unfortunately, SimpleTest is not supported right now.


  • patchinko Thursday, February 26, 2009

    hi, i just finished reading this entry

    http://wiki.netbeans.org/SeleniumPluginPHP

    installed the last nightly build and just junit, and maven plugins are available from the Plugins, i'm doing something wrong?

    thx and congrats for the outstanding work you are doing


  • Linux Tuner Thursday, February 26, 2009

    The problem is that developers like you think that the font used on your machine is good enough to be published in a screenshot. I do not understand how you can actually WORK with such a scrambled and eyehurting system - yes, this HAS something to do with your code, because it shows that you are totally ignoring fundamental user interface questions and will never understand why people are complaining about this or that regarding usability. If you accept this screenshots, you are not good.


  • Tomas Mysik Friday, February 27, 2009

    To patchinko:

    And what's the problem...? BTW Selenium support is not finished yet, currently we are working on it. Please, wait a couple of days (we will blog about it, of course ;).


  • Tomas Mysik Friday, February 27, 2009

    To Linux Tuner:

    Not sure what you mean exactly, sorry.


  • patchinko Friday, February 27, 2009

    there's no problem at all, just can't wait :)


  • Omar Ramos Friday, February 27, 2009

    Would it be possible for the phpUnit and Code Coverage feature to support customized versions of phpUnit such as the one being developed for Joomla?

    If you visit this URL:

    http://docs.joomla.org/Unit_Testing

    And scroll to the very bottom and there is a FAQ that reads:

    Why can't I use "phpunit testname.php" to run my tests?

    The test facility has to do some work to be able to load the "Joomla!" framework and to be able to inject mock classes. It's difficult to do this from the PHPUnit test runner, so we built our own. Also, the Joomla test runner has specific options designed to make it easy to select specific tests. Over time we will add more functionality to the test runner so it has many of the capabilities of the phpunit command.

    This means that we cannot use the default phpUnit to create Unit Tests for Joomla and I'd like something like this to be integrated.

    More Joomla Support would be great too :-).


  • Omar Ramos Friday, February 27, 2009

    Oh, I also forgot to mention that if you guys are interested in adding more Joomla support into Netbeans (which would be awesome by the way!) a good place to find the core developers and ask questions would be:

    http://groups.google.com/group/joomla-dev-cms


  • Michal Wednesday, March 4, 2009

    Hello,

    Can i ask how's progress with symfony support? Is there still a chance that it will be ready for 6.7?


  • Dirk Tuesday, April 21, 2009

    I'm also interested in.


  • yat kiralama Saturday, July 11, 2009

    I'm also <a href="http://www.yatkiralamafiyatlari.com" title="yat kiralama">yat kiralama</a> interested in.


  • a&#351;k &#351;iirleri Tuesday, July 28, 2009

    Thanks..


  • g&ouml;&#287;&uuml;s esteti&#287;i Thursday, August 20, 2009

    It would be nice to have history chart of passed / failed unit tests to see how the project is evolving in time.


  • medyum Thursday, August 20, 2009

    The problem is that developers like you think that the font used on your machine is good enough to be published in a screenshot. I do not understand how you can actually WORK with such a scrambled and eyehurting system


  • ariston servisi Monday, August 31, 2009

    nice topic


  • general electric sevisi Monday, August 31, 2009

    php is hard :(


  • siemens servisi Monday, August 31, 2009

    sample is good


  • web tasar&#305;m&#305; Monday, August 31, 2009

    and i m hard working for php


  • pharmacie prix discount Friday, October 23, 2009

    Great post, thanks for sharing.


  • links of london Thursday, October 29, 2009

    It was a very nice idea! Just wanna say thank you for the information you have shared. Just continue writing this kind of post. I will be your loyal reader. Thanks again.


  • web tasar&#305;m Tuesday, November 3, 2009

    thanks for sharing.

    I like PHP :) ...


  • ara&ccedil; sorgulama Tuesday, December 29, 2009

    The problem is that developers like you think that the font used on your machine is good enough to be published in a screenshot. I do not understand how you can actually WORK with such a scrambled and eyehurting system


  • Buz Monday, August 23, 2010

    Possibility of sharing and social solidarity at a level just fine thank you.


  • Pankaj Soni Wednesday, February 2, 2011

    I am using netbeans 6.9 for PHP

    I am not able to see code coverage properly,

    code coverage doesnot work by showing code coverage 0.00%. I used the same example i.e. creating Calculator class then creating php unit tests. but no green and red color, i am getting for code coverage. always it is showing 0.00% progress and no color on code


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.