Support

Forums

Contact Me

Using PHPUnit to test-develop Joomla extensions in PhpStorm

Since I did not find any clear how to on the internet how to run test cases for 3rd party extensions that use Joomla CMS, here is my version of it.

Prerequisites

Having PHPUnit properly install, if you use XAMPP you may want to read this post.

 

How to use PHPUnit in Joomla

At the root of your Joomla installation directory, make a checkout of https://github.com/joomla/joomla-cms/tree/master/tests/unit

You’ll need at least the following file

  • ${joomla_root}\tests\unit\bootstrap.php
  • ${joomla_root}\tests\unit\config.php
  • ${joomla_root}\tests\unit\JoomlaDatabaseTestCase.php
  • ${joomla_root}\tests\unit\JoomlaTestCase.php
  • ${joomla_root}\tests\unit\phpunit.xml
  • ${joomla_root}\tests\unit\readme.txt

config.php is a custom or a copy of your configuration.php

For your convenience, I provide a zip file (joomla_phpunit_testing.zip), unpack in your Joomla root and you’re done.

Note when using PHPUnit 3.6 , Joomla should not need to include/require anything PHPUnit related since (at least) PHPUnit 3.6. This create errors otherwise.

In PHPStorm

Set Up PHPUnit

Go to Settings, using CTRL+ALT+S, under PHPUnit, select the option “Use Bootstrap file” and use as value ${joomla_root}\tests\unit\bootstrap.php

Set Up PHPUnit Skeleton Generator

Go to Settings, using CTRL+ALT+S, under “Skeleton Generator”

  • Enter for “Path to phpunit-skelgen” the value is  ${xampp_root}\php, for example C:\xampp\php
  • Enter for “use bootstrap file” the value ${joomla_root}\tests\unit\phpunit.xml

Your first Joomla test case

Create a test case from any of your Joomla classes, by hitting CTRL+SHIFT+T, this will let you select the method you want to test and generate a runnable albeit incomplete test classes.

It is only the beginning of testing your Joomla extensions, there is a lot now to learn

  • Mocking objects in Joomla, Stubbing of Joomla classes
  • Invoking protected method using TestReflection::invoke
  • How to create integration tests using the database
  • How to test the user interface using PHPSelenium
  • and more…

These links may interest you

 

You might also like:
Add2Home 1.7.1 for J3.0 Released
46 days ago
Add2Home 1.7.1 for J3.0 Released
This small plugin for Joomla! add a message inviting iPhone/iPad users to add the web application
cedSmugmug 2.6.2  for joomla J2.5 and J3.0 released
48 days ago
cedSmugmug 2.6.2 for joomla J2.5 and J3.0 released
CedSmugmug  has been updated to version 2.6.2 and correct one bugs and contains some nice fea
cedphotofeed 2.6.2 for joomla J2.5 and J3.0 released
48 days ago
cedphotofeed 2.6.2 for joomla J2.5 and J3.0 released
This extension for Joomla  2.5 and Joomla 3.0 allow you to inline a set of images from your f
cedPhotofeed 2.6.1 for J2.5 Released
55 days ago
cedPhotofeed 2.6.1 for J2.5 Released
This extension for Joomla! 2.5 allow you to inline a set of images from your favorite online galle
Schema Validation for Joomla 2.5 Extensions
62 days ago
Schema Validation for Joomla 2.5 Extensions
I’ve created from scratch, all Joomla extensions XSD. Without them, Joomla accept any entry in
cedTag 2.6.2 for J2.5 released for Joomla 2.5
75 days ago
cedTag 2.6.2 for J2.5 released for Joomla 2.5
cedTag provide a useful way to group related posts together and to quickly tell readers what a pos
blog comments powered by Disqus

Donations

Thank You for supporting my work