Testing Kohana3 with PHPUnit

Unit testing is great, period. It allows you to test different parts of your application independently of the rest of the system.  Any changes that will cause problems elsewhere can be identified almost instantly (if you’re doing it right!).

Up until recently Kohana3 was using a home-grown module for unit testing – It was ok, but lacked some of the more advanced features of independent testing suites – however now the project has now adopted PHPUnit as its official test framework!  PHPUnit is one of the more popular testing suites for PHP, it has full support for FixturesMock ObjectsCode Coverage and a lot of other cool stuff.

The module only requires a few changes to the bootstrap in order to integrate Kohana with PHPUnit, and afterwards you can run tests from the cli, IDE or our custom web runner.  All available tests are loaded from Kohana’s cascading filesystem and can be filtered using PHPUnit’s –group switch.

Go and git it while it’s hot!

This entry was posted in Programming and tagged , , , , . Bookmark the permalink.
  • Rafi B.

    Thanks for the information Matt. Can you point me to some examples with Kohana?

  • Rafi B.

    Thanks for the information Matt. Can you point me to some examples with Kohana?

  • Matt

    Your best bet would be to have a look at the stuff in the kohana/core testing branch, there are quite a few tests in there.

  • Matt

    Your best bet would be to have a look at the stuff in the kohana/core testing branch, there are quite a few tests in there.

  • Rafi B.

    Thanks. BTW, the required archive module that’s linked in the unittest module is broken: http://github.com/BMatt/kohana-archive

  • Rafi B.

    Thanks. BTW, the required archive module that’s linked in the unittest module is broken: http://github.com/BMatt/kohana-archive

  • Matt

    It’s not required unless you want to download archives of code coverage, and in 99% of cases, you won’t.

  • Matt

    It’s not required unless you want to download archives of code coverage, and in 99% of cases, you won’t.

  • d3sh

    After activating the module, when i try to open my aplication in browser i get an error: ErrorException [ 1024 ]: Please no longer include “PHPUnit/Framework.php”.

    what am i dong wrong ?

  • http://sigswitch.com/ BRMatt

    Which version of phpunit are you using?

  • d3sh

    PHPUnit 3.5. Installed it using PEAR installer.
    Kohana 3.0.8
    PHP 5.3.3

  • http://sigswitch.com/ BRMatt

    The tests were written to be compatible with PHPUnit 3.4, I’ll have a look into making them compatible with 3.5 but in the mean time you could try using the latest version of 3.4.

  • d3sh

    tnx :)