4

I have a requirement that I need to run the tests through commandline as well as through a graphical debugger. The graphical debugger should run the code on Apache.

I tried SimpleTest and it works well as in both the cases but PHPUnit only works on commandline. I am using NuSphere PhpED to debug and I am not able to make phpunit to run.

When I run Simpletest from editor it runs as php command but PHPUnit will have to run through $phpunit command. I am not able to understand how will that work.

There is a php debugger module on Apache using which I can step through the code with simpletest. Is there any debugger module for PHPUnit?

My server is Linux but my editor is on windows. Is it possible to run tests like this?

Is it also possible to run PHPUnit without installing through PEAR and just like Simpletest - where we just copied the folder and included the autorun file.

I am new to both these tools and I need to decide which one to use and integrate with Hudson/Maven.

Please guide me as I am new to these.

Thanks Sumit

Sumitk
  • 1,485
  • 6
  • 19
  • 31
  • Some more arguments in favour of @Davids solid answer [What unit testing in php to start](http://stackoverflow.com/questions/4624093/what-unit-testing-in-php-to-start/4625909#4625909) – edorian Jun 13 '11 at 02:15

1 Answers1

4

We migrated from SimpleTest to PHPUnit a little over a year ago and have been very happy. SimpleTest is abandoned while PHPUnit is actively developed with regular releases and a plan for the future. We run PHPUnit on Ubuntu and Windows machines both from the command line and in NetBeans IDE even though our application is a CMS running behind Apache.

For continuous integration, check out Templates for Jenkins Jobs for PHP Projects. It has integration of PHPUnit for testing as well as PHPMD, PHPCPD, PHP Depend, PHPLOC, and PHP CodeSniffer.

I can't completely answer your original question regarding running PHPUnit in a web debugger. You could install PHPUnit using PEAR and check out the script that runs it. It's all PHP except for the initial shell script, but with a little work you could write a similar script in PHP that sets up your environment and calls an appropriate TestRunner.

Shog9
  • 156,901
  • 35
  • 231
  • 235
David Harkness
  • 35,992
  • 10
  • 112
  • 134
  • Hi David, Thanks for your reply. So when you use NetBeans IDE for debugging using phpunit, are you able to step through the code which actually runs on your Apache server? I did saw some discussions on using NetBeans and was wondering if I should switch to that as currently I am using NuSphere PhpED. Also do we need to have any building tool like Maven to run for Jenkins? Thanks for you link. It was really useful. – Sumitk Jun 13 '11 at 02:05
  • @Sumitk, you need a build tool. Shell script, ant, maven, phing. Your choice :) --- You can use netbeans to debug an apache process when using xDebug. (I don't know about NuSphere). And to add some more shameless self promotion: [Setting up jenkins for php projects](http://edorian.posterous.com/setting-up-jenkins-for-php-projects). You can also hop in the php SO chat if you want some input that doesn't fit in a SO question) – edorian Jun 13 '11 at 02:22
  • @David, Thanks for the link. I have one question though: If I run my unit tests through NetBeans IDE on Apache, does it work like running `$ phpunit testFile.php` on the server? I am configuring my env for NetBeans so was wondering. I will try it out and let you know if I run into any problem. Thnks again!! – Sumitk Jun 13 '11 at 05:20
  • @Sumitk - NetBeans runs the tests and our application locally through Apache, meaning we have MySQL, Apache, PHP, PHPUnit, Xdebug, and NetBeans all installed and running locally. It runs just like it runs when deployed on the server. The unit tests don't run through Apache normally as they test classes in isolation. We do use PHPUnit with Selenium to do integration/system tests on the staging server. We don't debug these--merely watch the output for failures. – David Harkness Jun 13 '11 at 21:58
  • @David - I have my Apache configured on CentOS and I have other machines for coding which are Windows. So we do all our coding on Windows based tools (PhpED) and deploy on another machine running Apache on CentOS. I still am confused if I would be able to debug using phpunit on windows while the code is run on Apache. – Sumitk Jun 14 '11 at 07:16
  • @Sumitk - I haven't done remote debugging like that, but in theory it should work. I rarely ever debug during unit testing. The goal is to write clear assertions so you can see what broke during the automated run. However, with some tweaking of an `index.php` for PHPUnit, you should be able to get what you want. – David Harkness Jun 14 '11 at 07:24
  • @David - I tied running through your tutorial but was not able to run the whole thing. Could you please help. My steps were as follows: 1. I installed git & created the project with all the files. Should it be phpunit.xml.dist or phpunit.dist.xml ? 2. I then did `git commit -m"Inital dump"` 3. I already had the jenkins plugins & php tools installed. I then copied the build.xml & phpunit.dist.xml from **http://jenkins-php.org/** 4. I then committed the file & got the clone of **php-template**. Now after restarting Jenkins I am not able to create a new job. Its saying "no such job" – Sumitk Jun 16 '11 at 00:37
  • @Sumitk - It's not my tutorial, but I'll try to help. The file should be `phpunit.xml.dist`. Did you place the template folder inside Jenkins's `jobs` folder? – David Harkness Jun 16 '11 at 02:00
  • @David - Thanks a lot! Yes I did place the php-template inside /var/lib/jenkins/jobs folder. Now when I am trying to create a New Job through Jenkins web interface and give `php-template` in the field **Copy Existing Job**, I get an error saying **No Such Job**. I also created a new project inside the job folder and did the same steps as mentioned but still it gave the same No Such Job error. Do I need to modify the comfig.xml in some particular way? I also copied the config.xml from the template folder inside my project and edited the project name & url. It still doesn't work. – Sumitk Jun 16 '11 at 18:08
  • You don't need to modify `config.xml`, but you *do* need to tell Jenkins to reload its configuration or restart the service. – David Harkness Jun 16 '11 at 22:24
  • @David - The problem was I used root to get the template. Now: `[htmlpublisher] Archiving at BUILD level /var/lib/jenkins/jobs/first-project/workspace/build/coverage to /var/lib/jenkins/jobs/first-project/builds/2011-06-17_11-20-34/htmlreports/Code_Coverage ERROR: Directory '/var/lib/jenkins/jobs/first-project/workspace/build/coverage' exists but failed copying to '/var/lib/jenkins/jobs/first-project/builds/2011-06-17_11-20-34/htmlreports/Code_Coverage'. ERROR: This is especially strange since your build otherwise succeeded. Build step 'Publish HTML reports' changed build result to FAILURE` – Sumitk Jun 17 '11 at 18:35
  • @Sumitk - Ah, you need to making everything in the `jenkins` folder owned by the `jenkins` user. `cd /var/lib/jenkins/jobs ; sudo chown -R jenkins` – David Harkness Jun 17 '11 at 22:10
  • @David - I already did that but still the same error. I think every time it tries to create a folder inside build, it is not able to create. I checked the permission but still the same issue. Every folder & files in jobs folder belongs to Jenkins. – Sumitk Jun 18 '11 at 00:33
  • @Sumitk - I'm out of ideas. :( Get on PHPUnit's IRC channel as the two guys that built the template hang out there. The Jenkins mailing list is another good place to get help. – David Harkness Jun 18 '11 at 06:46