PHPUnit support added
Today I would like to inform you that we have added PHPUnit support to NetBeans. It is not finished yet (UI for test results is still missing) but I would like to show you how one can test his/her PHP sources in NetBeans today. If you are new to PHPUnit, be sure that you visit PHPUnit web site first to get all the required information.
First, be sure that PHPUnit is installed on your computer and PHPUnit script is known for NetBeans; to verify that, just open IDE Options (Tools > Options) and check whether the script has been found for you. If the script is not found, please let us know, preferably using our IssueZilla (component php, subcomponent project) so we can try to fix your case. The IDE Options should look like this:
Now it's time to create our first PHPUnit test - to do so, open any existing PHP project (or create a new one) and create a new PHP class (be sure that the name of the file is in the form of <the_name_of_PHP_class_defined_in_the_file>.php - for NetBeans, it's enough to invoke New > PHP Class...). Add some methods and right click the file in Projects view, select Tools > Create PHPUnit test... Please note that this action can be invoked for folders as well.
If it's the first time, IDE has to ask for a folder for tests:
Once this folder is set, it can be found in Project Properties dialog as well as in Projects view, of course.
After the tests are created, one can easily run them using Test action on project's node:
For now, only Output window is opened and the test results are displayed; but stay tuned, we plan to add UI for these results, similarly as for Ruby or Python support.
Of course, one is able to run or even debug only one particular test (labels are not final yet, Run/Debug are used for now, maybe we should change them to Run test/Debug test - what do you think?):
The last thing for today is that it is very easy to navigate between source (tested) class and test class - just right click anywhere in the editor and invoke Navigate action:

We hope that you will find NetBeans PHPUnit support useful!
PS: Currently we are discussing the relation between Test sources and Remote Web configuration of a PHP project - should tests be uploaded to a remote (S)FTP server? If yes, then where? What about if Tests are underneath Sources? And what if they are not? As you can see, there are quite many questions to solve. Any feedback is welcome, of course.

Is it posible to run unit tests defined in PHPUnit_Framework_TestSuite?
Posted by coccyx on January 19, 2009 at 08:23 PM CET #
Can you please provide more information or an example? I'm not sure what you mean. Thanks.
Posted by Tomas Mysik on January 19, 2009 at 09:29 PM CET #
Ok, I will try to describe it more detailed (sorry my english).
I am doing some integration tests, on my DAO classes (CRUD,...). But to test the database layer I need to drop all tables and create tables and fill them with basic data and this must be done before the phunit testing. And after database setup, I can run unit tests, but i need run them in special order and this is why the unit tests are defined in PHPUnit_Framework_TestSuite.
Description of class PHPUnit_Framework_TestSuite says:
"A TestSuite is a composite of Tests. It runs a collection of test cases."
PS: "Podla mena vyzeras ze si slovak/cech, tak dufam ze som si tu nelamal jazyk zbytocne" :)
Posted by coccyx on January 19, 2009 at 11:01 PM CET #
Dose it support runing single file test and single method test ?
This gui is not reused from the JUnit gui? It is so different.
By the way , I want to kown it support SimpleTest(http://www.simpletest.org/)?
Posted by hantsy on January 20, 2009 at 05:04 AM CET #
I think other features like Code Coverage/Unit test report(which provided in Ruby/PYthon support now) are expected by other PHP guys.
Posted by hantsy on January 20, 2009 at 05:06 AM CET #
Great job!
(More features and even better job.)
In my opinion:
If the tests are under sources then they should be uploaded as in that case they already have a place for them. If not, should there be a checkbox and an input box for choosing if and where to upload test classes?
Posted by Jussi on January 20, 2009 at 07:39 AM CET #
What should i do, to enable this, and other features (return types, implement all abstract methods and other)? I have NB 6.5 with PHP 1.2.2
Posted by ljarochowski on January 20, 2009 at 11:00 AM CET #
To coccyx:
I need to investigate more your use case - in such case I would say that such suite should be run using 'ordinary' PHP interpreter and not PHPUnit - I will try to look at it (of course, any suggestions are welcome).
Tomas
PS: Tak tak, jsem Cech ;)
Posted by Tomas Mysik on January 20, 2009 at 01:00 PM CET #
@ljarochowski: you must download the development nightly build zip from http://bits.netbeans.org/download/trunk/nightly/latest/
Posted by Jozef on January 20, 2009 at 01:01 PM CET #
To hantsy:
> Does it support runing single file test and single method test ?
Single file - yes (written in the blog already)
Single method - not yet
> This gui is not reused from the JUnit gui? It is so different.
In fact, no GUI right now; the one from Ruby/Python will be reused.
> By the way , I want to kown it support SimpleTest?
No plans for this support right now.
Tomas
Posted by Tomas Mysik on January 20, 2009 at 01:02 PM CET #
To hantsy:
> I think other features like Code Coverage/Unit test report(which provided in Ruby/PYthon support now) are expected by other PHP guys.
These are in the current TODO list.
Posted by Tomas Mysik on January 20, 2009 at 01:04 PM CET #
To Jussi:
> Great job!
Thanks a lot!
> In my opinion:
> If the tests are under sources then they should be uploaded as in that case they already have a place for them. If not, should there be a checkbox and an input box for choosing if and where to upload test classes?
The "problem" here is that if Tests are underneath Sources, they are _not_ visible in Projects view - wouldn't it be confusing if they will be uploaded together with Sources? Maybe not, I don't know.
Specify another upload directory for Tests is one possibility - but seems to me a bit complicated, and again, hard to say whether people will be happy with it.
Thanks a lot for your opinion,
Tomas
Posted by Tomas Mysik on January 20, 2009 at 01:09 PM CET #
To ljarochowski and Jozef:
Or one can use NB development builds from:
http://deadlock.netbeans.org/hudson/job/PHP-build/lastSuccessfulBuild/artifact/nbbuild/
Tomas
Posted by Tomas Mysik on January 20, 2009 at 01:11 PM CET #
Ok, I uploaded source file to see how looks inside.
[IMG]http://i39.tinypic.com/4t6ag3.png[/IMG]
I run unit tests from command line: phpunit AllTests.php
And you can see some results here:
[IMG]http://i42.tinypic.com/o597vk.png[/IMG]
Posted by coccyx on January 20, 2009 at 01:39 PM CET #
To coccyx:
Could you please create and issue for it in our IssueZilla? Describe your use case there, attach screenshots; let's discuss it there, to keep history etc.
(How do you run your suite? Using php or phpunit script?)
Thanks a lot,
Tomas
Posted by Tomas Mysik on January 20, 2009 at 02:38 PM CET #
I am running my tests with 'phpunit AllTests.php' and i can also use other parameters for code coverage, pmd, ...
You can also look at Zend Framework to see how PHPUnit_Framework_TestSuite is used.
I never worked with IssueZilla but I give it a try :)
Posted by coccyx on January 20, 2009 at 03:28 PM CET #
Hi,
Is there a plugin which I can install separately instead of downloading & installing the complete package again over my previous 6.5 installation?
btw Good Job on this. Netbeans FTW!!
Posted by Rahul on January 20, 2009 at 09:43 PM CET #
To Rahul:
It's not possible because PHP support depends on other IDE features that are only in trunk, not in NB 6.5 FCS - that's why you have to download the PHP build. If the ZIP file is too big (cca. 45MB) for you, you can use NetBeans installer, it can be found here:
http://bits.netbeans.org/download/trunk/nightly/latest/
(only about 23 MB)
Tomas
Posted by Tomas Mysik on January 21, 2009 at 10:19 AM CET #
I understand. I'll give the NB installer a shot.
Thanks for your time.
Posted by Rahul on January 21, 2009 at 12:09 PM CET #
oh and btw I use Java so I've installed the complete package (220 MB) thats my problem ;)
I'll give my php team the "nice & small" 23 Mb build.
Posted by Rahul on January 21, 2009 at 12:15 PM CET #
Thanks for your efforts!
BTW, it would be nice to highlight file:line as links in test run output if test produces fail/error.
The same way as "Running Tutorial Examples in NetBeans IDE" states: "If the build output concludes with the statement BUILD FAILED... Errors are reported in the Output window as hyperlinked text. You double-click such a hyperlink to navigate to the source of an error."
Posted by Olksy on January 21, 2009 at 02:39 PM CET #
To Olksy:
This should be possible from test results GUI. But I agree, it would be useful in Output window as well. We will try to look at it.
Thanks,
Tomas
Posted by Tomas Mysik on January 21, 2009 at 04:58 PM CET #
This is great news. But problem is, that I use Zend Framework like class organization. For example in folder ap/ui I have file Login.php which contain class with name ap_ui_Login. And Netbeans write me only "Test were not generated... ...DO they contain PHP classes? Are the names of the classes same as names of the files?" No :-( It's problem create test with the same file name and class name inside it?
Posted by Tomas Prochazka on January 22, 2009 at 06:42 AM CET #
To Tomas Prochazka:
Well, the problem here is that phpunit is run only with a file name as a parameter because PHP project doesn't know anything about the content of a file. And right now it's not possible to get these information. But please, report a bug and I will try to fix it (together with editor guys).
Thanks a lot,
Tomas
Posted by Tomas Mysik on January 22, 2009 at 01:31 PM CET #
Thanks a lot for this great addition!
(I think Run/Debug Test would be more meaningful)
Posted by Valentin Jacquemin on January 23, 2009 at 11:54 AM CET #
Hi,
I upgraded to the nightly build from 6.5 a couple of days ago to use this PHPUnit scaffolding and the inline var type docblock. They work very nicely. However, I can't seem to use the rename (Ctrl-R) feature that I used heavily in 6.5. Is there a way to enable it in the nightlies?
Posted by Mon Z. on January 27, 2009 at 04:06 PM CET #
My bad on that one. Ctrl-R is not disabled, it's just limited to local vars now and doesn't work on class members and method names. I don't think I can live without this feature, I hope it can be addressed in the near future
Posted by Mon Z. on January 27, 2009 at 04:22 PM CET #
Great new feature.
Netbeans didn't find the scripts for me, running Vista and WAMP. (issue submitted)
Posted by Jacob Christophersen on January 28, 2009 at 02:23 AM CET #
To Mon Z.:
This behavior is intentional (we are just trying to do it safely) but the final behavior is not decided yet. Please, file and issue (against PHP Editor) so it can be discussed directly in NetBeans IssueZilla. Thanks.
To Jacob Christophersen:
Thanks a lot for filing an issue, I will look at it soon.
Posted by Tomas Mysik on January 30, 2009 at 01:19 PM CET #
How do you setup xdebug and netbeans to debug your phpunit tests? I'm not having any luck, netbeans keeps waiting for a connection (netbeans-xdebug).
And thanks for adding this to netbeans, I've been wanting it for a while.
Posted by VagabondVince on June 23, 2009 at 12:27 PM CEST #
I filed an issue, that PHPUnit support doesn't work for projects that use either the __autoload() feature of PHP 5 or a centralized class-loader.
In both cases you will not be able to create new or even run existing Unit-Tests and will not be able to show code-coverage.
This is due to the fact, that PHPUnit's "bootstrap" command line argument is not supported. For now you can work around this problem by writing your own batch file and adding the argument there.
Posted by Thomas Meyer on June 25, 2009 at 06:08 PM CEST #
Looks like there is a problem with filenames with '_'.
Example:
C_MyClass.php
--------------
class C_MyClass(){...}
Then I am getting output:
PHPUnit 3.3.17 by Sebastian Bergmann.
File "C\MyClass.php" does not exist.
Posted by Melor on July 01, 2009 at 03:01 PM CEST #
great keep the good work on
Posted by web development in php on July 17, 2009 at 09:18 AM CEST #
i just cant make it work, it say that it didnt find any PHPUnit script
windows xp sp3
WampServer2.0i (Apache 2.2.11, MySQL 5.1.36, PHP 5.3.0)
NetBeans 6.7
the path for phpunit im trying to insert on php options at options = C:\wamp\bin\php\php5.3.0\PHPUnit\Framework.php
Any help is welcome =)
Thanks
Posted by Alexander on July 22, 2009 at 01:50 PM CEST #
ok i just found this http://www.netbeans.org/kb/docs/php/phpunit.html#installing-phpunit
and everything went better than expected, it works! thanks anyway :D
Posted by Alexander on July 22, 2009 at 02:22 PM CEST #
Thank you by Admin cok sagolun ya harıkasın
Posted by mirc on August 23, 2009 at 04:26 AM CEST #
single tests can be run by changing the tools - options - php - phpunit script setting from
/usr/bin/phpunit
TO
/usr/bin/phpunit --filter nameoftest
Posted by Niall dawson on September 17, 2009 at 12:36 PM CEST #
Hi there,
thanks for PHP in Netbeans! I love it.
I have a problem with writing tests for a class extending another class. NB will not create it with the message:
"Test were not generated for the following files:
CLASSNAME.php
Review the log in Output window"
There:
PHP Fatal error: Class 'CLASSNAME_OF_EXTENDED_CLASS' not found in /PATH/CLASSNAME.php on line 14
PHPUnit 3.4.0 by Sebastian Bergmann.
PHP Stack trace:
Fatal error: Class 'CLASSNAME_OF_EXTENDED_CLASS' not found in /SAME_PATH_AS_ABOVE/CLASSNAME.php on line 14
If I do creating a test from a class without extending another class there's no problem.
Any ideas what's going wrong? A PHP include_path issue?
Thanx for any replys
Andy (@awenkhh)
Posted by Andreas Wenk on September 18, 2009 at 05:05 PM CEST #
Support for SimpleTest would be awesome (since it's the test lib I'm using now, of course!).
It seems that both test libs (PHPUnit and SimpleTest) are widely used in the PHP world.
Anyway, thanks for NetBeans, it's an awesome tool I'm going to use more and more...
Posted by Rodolphe on September 29, 2009 at 10:13 AM CEST #
Hi. I have imported an existing project and I just can't seem to get my tests to run in batch. I can run them individually, but when I invoke Test on the main project no tests are actually executed. I setup the tests myself and they are probably not setup in the way that NetBeans expects. What does netbeans expects from the test setup?
My setup is as follows. I have a folder structure (like this www.grabup.com/uploads/4d5760389c16.png)
where each test contains a require_once that points to the Bootstrap.php file (www.grabup.com/uploads/9da18016f77a.png), which sets up the testing environment. An example test case is: www.grabup.com/uploads/dd912dc40ca1.png
Thanks,
Karl
Posted by Karl Purkhardt on October 06, 2009 at 02:27 PM 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 31, 2009 at 03:20 AM CET #
I filed an issue, that PHPUnit support doesn't work for projects that use either the __autoload() feature of PHP 5 or a centralized class-loader.
Posted by collect bag on November 14, 2009 at 06:51 AM CET #