Fandom

Wikia Developers Wiki

Nirvana/Unit Testing

< Nirvana

889pages on
this wiki
Add New Page
Talk0 Share

Unit Testing Helper

The class WikiaBaseTest extends PHPUnit_Framework_TestCase. It has three main helper functions: mockApp(), mockGlobalVariable() and mockGlobalFunction(). If your test class extends WikiaBaseTest, you can use them.

mockApp()

This helper sets up the test class $app variable to be a mocked object which allows you to use the remaining functions. It is not necessary to call this unless you want to use the other helper functions. By default the $app variable in the Wikia test class is a REAL WikiaApp object. After calling this helper, $app becomes a MOCK WikiaApp object and any global functions and variables can be mocked. If you need to use it for some reason, there is an $appOrig which preserves the unmocked WikiaApp object and is normally restored in tearDown().

mockGlobalVariable(name, retval)

If you need to mock the value of a global variable, use this. For example:

$this->mockGlobalVariable( 'wgExternalSharedDB', '' );

mockGlobalFunction(name, retval, numcalls, inputparams)

If you need to mock a global function (anything called through the $wg->Function helper, use this.

$this->mockGlobalFunction( 'GetDB', $dbMock );  // mock wfGetDB call
 
$this->mockGlobalFunction( 'Msg', "test msg");  // mock wfMsg call

mockClass()

This doesn't directly add much functionality but if you call this helper, the Framework will unset these class overrides during tearDown.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.