Unit Testing in PHP5 !

topic posted Wed, August 31, 2005 - 6:26 PM by  Unsubscribed
I have been working on an open source internet jukebox system for a while now. It was originally developed in the java/j2ee framework.
I have recently been considering rewriting the web portion of this project in PHP5.

The new object model of php5 provides true object oriented programming ability. I like this as I am used to developing in java. I like that i am able to easily apply my existing knowledge of java design patterns, and that this knowledge translates well to php5. I.e. I have been writing my own sort of mini collections and OO database wrapper apis.

Eventually this brought me to the question of how to test my code. Under java i had used JUnit. Was there something like this for php?

Enter PHPUnit:

The unit testing framework rocks.
It is based on JUnit and very similar to work with.

If you are a php developer and designing your current app with OO code, you should definitely check this out:

www.phpunit.de/en/index.php
posted by:
Unsubscribed
  • Re: Unit Testing in PHP5 !

    Thu, September 1, 2005 - 11:21 PM
    phpunit.sf.net

    It's smaller, but much better, IMO.
    • Unsu...
       

      Re: Unit Testing in PHP5 !

      Fri, September 2, 2005 - 11:35 AM
      Hmm.. looking at the documentation its more like junit than the other phpunit.
      I might have to switch to this one.
      • Unsu...
         

        Re: Unit Testing in PHP5 !

        Sat, September 3, 2005 - 1:07 PM
        This phpunit framework is NOT happy with php5.
        ( phpunit.sourceforge.net )

        It is written in php4 syntax, and geared towards php4, with a few lines of code half assedly geared towards php5.
        I dont think its been tested under php5 at all, as it redeclares the Exception class that is preexisting in php5.

        When you try to run a test - this causes things to crash and burn:

        Fatal error: Cannot redeclare class exception in /usr/local/lib/phpunit/phpunit.php on line 55

        I'm going back to the phpunit from pear :-)



        • Re: Unit Testing in PHP5 !

          Mon, July 16, 2007 - 6:13 AM
          I solved easy the problem changing the definition of Exception to Exception1 and then use it on line 266 of phpunit.php.

          Diffing the changes:

          55
          < class Exception {
          > class Exception1 {


          266
          < $this->fExceptions[] = new Exception(&$message, 'FAILURE');
          > $this->fExceptions[] = new Exception1(&$message, 'FAILURE');
  • Re: Unit Testing in PHP5 !

    Mon, July 16, 2007 - 9:44 PM
    I use symfony on most oop projects and its unit tests utilize lime. see excerpt from the symfony blog below. I use this jsut because its built in and im too lazy to replace it since it does what i need quite well. I dont know how well it works outside of sf, but i thought id mention it.

    You can grab it from the svn... svn.symfony-project.com/trunk/...or/lime

    <<
    New testing framework

    If you keep an eye on the timeline, you probably saw that the symfony unit tests have been completely reworked lately. This is because we switched from simpletest, which was fine but had side effects when functional tests were executed all at once, to our own testing framework, lime.

    Lime is more lighweight than PHPUnit or simpletest and has several advantages. First, it launches test files in a sandbox to avoid strange effects between each test file run (one of the reasons we were unable to fix the old symfony core tests). It also introduces a new sfBrowser, sfTestBrowser and more importantly sfDomCssSelectorBrowser that allow you to write functionnal tests with ease. It is not backward compatible but is a lot more powerful than the old system. Oh, and it holds in a single file, lime.php, without any dependence.
    >>

Recent topics in "PHP Developers"

Topic Author Replies Last Post
using dreamweavers PHP Jivatma 2 August 4, 2008
Another question about formatting date & time SMSapphire 6 June 7, 2008
phpews Satinder 0 June 4, 2008
how works with joomla ??? iShaun 1 May 22, 2008