Code coverage for PHP - why not?

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!


Comments:

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

Is there any roadmap for PHPUNIT plugin futures ???

Posted by coccyx on February 24, 2009 at 09:58 AM CET #

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.

Posted by Jozef on February 24, 2009 at 11:15 AM CET #

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

Posted by Tomas Mysik on February 24, 2009 at 01:17 PM CET #

To Jozef:
I updated the issue you mentioned, I think it should be fixed for Milestone 3.
Thanks for positive feedback.

Posted by Tomas Mysik on February 24, 2009 at 01:19 PM CET #

great work! thanks

Posted by gawan on February 24, 2009 at 02:09 PM CET #

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

Posted by coccyx on February 24, 2009 at 04:15 PM CET #

To gawan:
Thanks a lot!

Posted by Tomas Mysik on February 24, 2009 at 06:53 PM CET #

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

Posted by Tomas Mysik on February 24, 2009 at 06:56 PM CET #

Hello,

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

Any help?

Thanks,
Stefan

Posted by Stefan on February 25, 2009 at 01:12 AM CET #

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?

Posted by Tomas Mysik on February 25, 2009 at 01:27 AM CET #

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?

Posted by radek on February 25, 2009 at 02:58 AM CET #

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

Posted by Stephen on February 25, 2009 at 03:30 AM CET #

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

Posted by Stephen on February 25, 2009 at 03:32 AM CET #

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

Posted by Stephen on February 25, 2009 at 03:33 AM CET #

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

Posted by Jozef on February 25, 2009 at 04:34 AM CET #

To Stephen:
Unfortunately, SimpleTest is not supported right now.

Posted by Tomas Mysik on February 25, 2009 at 04:18 PM CET #

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

Posted by patchinko on February 26, 2009 at 11:34 PM CET #

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.

Posted by Linux Tuner on February 27, 2009 at 12:05 AM CET #

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 ;).

Posted by Tomas Mysik on February 27, 2009 at 02:10 AM CET #

To Linux Tuner:
Not sure what you mean exactly, sorry.

Posted by Tomas Mysik on February 27, 2009 at 02:12 AM CET #

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

Posted by patchinko on February 27, 2009 at 02:42 AM CET #

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 :-).

Posted by Omar Ramos on February 27, 2009 at 03:26 PM CET #

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

Posted by Omar Ramos on February 27, 2009 at 03:28 PM CET #

Hello,

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

Posted by Michal on March 04, 2009 at 07:02 AM CET #

I'm also interested in.

Posted by Dirk on April 21, 2009 at 03:25 PM CEST #

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

Posted by yat kiralama on July 11, 2009 at 10:10 AM CEST #

Thanks..

Posted by aşk şiirleri on July 28, 2009 at 10:38 PM CEST #

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

Posted by göğüs estetiği on August 20, 2009 at 07:47 AM CEST #

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

Posted by medyum on August 20, 2009 at 09:50 AM CEST #

nice topic

Posted by ariston servisi on August 31, 2009 at 04:30 AM CEST #

php is hard :(

Posted by general electric sevisi on August 31, 2009 at 04:30 AM CEST #

sample is good

Posted by siemens servisi on August 31, 2009 at 04:32 AM CEST #

and i m hard working for php

Posted by web tasarımı on August 31, 2009 at 04:33 AM CEST #

Great post, thanks for sharing.

Posted by pharmacie prix discount on October 23, 2009 at 05:43 AM CEST #

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.

Posted by links of london on October 29, 2009 at 08:09 PM CET #

thanks for sharing.
I like PHP :) ...

Posted by web tasarım on November 03, 2009 at 04:18 AM CET #

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

Posted by araç sorgulama on December 29, 2009 at 04:14 AM CET #

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

Posted by Buz on August 23, 2010 at 03:10 AM CEST #

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

Posted by Pankaj Soni on February 03, 2011 at 12:37 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

This blogs is written by NetBeans developers who contribute to the PHP support mainly.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today