A test class includes methods that target logic provided by controllers, models, etc., and applies assertions to verify that the logic works as intended. Perforce Chronicle was built with an extensive test suite that uses PHPUnit.
To add PHPUnit tests for your own module, create a tests
folder under
your module's folder and include the following files:
phpunit.xml
file located in the tests
folder. Here is an example for the Foo
module:
<phpunit bootstrap="../../../../../tests/phpunit/TestBootstrap.php"> <testsuites> <testsuite name="Foo Module"> <directory>.</directory> </testsuite> </testsuites> </phpunit>
Foo
module's index
controller:
<?php /** * Description of tests for Foo_IndexController * * @copyright copyright info * @license license info * @version version info */ class Foo_Test_IndexControllerTest extends ModuleControllerTest { /** * Runs before each test method */ public function setUp() { } /** * Runs after each test method */ public function tearDown() { } /** * Test indexAction */ public function testIndex() { $this->utility->impersonate('administrator'); $this->dispatch('/foo'); $this->assertModule('foo'); $this->assertController('index'); $this->assertAction('index'); } }
To run all tests, open a terminal, change directories to the
directory and issue the
phpunit command.
CMSDIR
/tests/phpunit