Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I test my PHP code - what test frameworks can I use? [closed]

My main competence lies in Java (Android). I've been in the industry long enough to realize the benefits of proper testing and I would like to think that I have a somewhat mature idea of how to test production code and how to build up test architecture.

Recently I however tend to get more and more involved in PHP coding. The few PHP projects I've had as of now were more or less straight forward homepages for different charity events and alike where "manual test cases" were sufficient.

But I'm now planing a bigger PHP project for a paying customer (a complete, REST based web application with a heavy database backend, i.e. not a "Welcome to my homepage" project). I realize there is no way a set of manual test instructions listed in a text document will be enough. I need a proper automated test framework, much like the JUnit framework for Java, but for PHP.

Are there any living "industry standard" test frameworks for PHP code out there (preferably open source)? I've read briefly about the PHPUnit and SimpleTest frameworks. Are they recommendable according to you guys?

The project parameters are set: PHP is one of the requirements, hence you don't need to put energy in convincing me of better web platforms etc. (but I will gladly read any side notes and tips you may have, though, - for future projects :-)

like image 434
dbm Avatar asked Jun 25 '11 10:06

dbm


People also ask

What are unit tests PHP?

Unit testing is a software testing process in which code blocks are checked to see whether the produced result matches the expectations. The units are tested by writing a unique test case. The unit test is generally automatic but could be implemented manually.


2 Answers

Your two main options are PHPUnit and SimpleTest. You can see a comparison of them here: SimpleTest vs PHPunit

However, please note that that discussion is from 2008 and things have changed since then.

If you want to test the actual webpages, and save yourself some trouble clicking on links and submitting forms, check out Selenium: http://seleniumhq.org/

Also, if you're using an IDE like NetBeans or Eclipse, or are using a PHP framework like CakePHP or Zend, it would be well worth your while to see what testing frameworks your tools of choice support.

like image 116
Mark Northrop Avatar answered Oct 31 '22 20:10

Mark Northrop


PHPUnit seems to be the standard for unit testing.

http://www.phpunit.de/manual/current/en/

https://github.com/sebastianbergmann/phpunit/

I have use it for TDD and find it excellent and it ticks all the boxes for you if I understand your question correctly.

like image 32
vascowhite Avatar answered Oct 31 '22 20:10

vascowhite