UT: JError stub now available

1 view
Skip to first unread message

Paladin

unread,
Nov 6, 2009, 12:51:49 PM11/6/09
to Joomla! Framework Development
A documentation note for a new tree I'm adding to /unittest and
proposing we keep around. Because I've run into problem caused by
JError in testing, I've created a JError stub and parked it in
unittest/libraries/joomla/error.php for use by anyone else who has has
similar issues.

In order to properly test the code, I needed to cause an error, and
kept getting the test killed because it causes an infinite loop in
JError (I saw this happen several times during skeleton building, so I
expect it'll be needed in more places than just here, as we add
tests). You can see an example of how to use this stub to defeat that
infinite loop in the JSimpleXMLTest file.

Basically, this file is substituted for JError by requiring it before
loading the class file under test:

require_once JPATH_BASE. '/unittest/stubs/libraries/joomla/error/
error.php';
require_once JPATH_BASE. '/libraries/joomla/utilities/simplexml.php';

Since this particular problem was being caused by
JError::raiseWarning, that was the only method I stubbed out in the
JError stub; if/as we keep on using this stub, we'll stub out other
methods as needed, following the same approach.

The replacement stores the information sent to raiseWarning in a new
static variable for the stub -- $exception. Since the variable is
public, you can pull it into your test to check and see if the proper
error was triggered. A working example is in testLoadString, where I
check the error returned from loading a malformed xml string.
Reply all
Reply to author
Forward
0 new messages