Testing

Setting up unit and functional tests in okapi

externals (requires okapi 1.1.7+)

ext/testing https://svn.liip.ch/repos/public/okapi/ext/testing/trunk/
inc/lib/simpletest https://simpletest.svn.sourceforge.net/svnroot/simpletest/simpletest/trunk/

rake

in the project root directory create a textfile "Rakefile" with the following content

import 'ext/testing/rake/Rakefile'

in the project root create the directory "tests" and inside that directory create a "unit" and "functional" directory

in project root call the rake shell command

machine:projectfolder user$ rake
(in projectfolder)
cd ext/testing && php test.php unit
Unit
OK
Test cases run: 0/0, Passes: 0, Failures: 0, Exceptions: 0
cd ext/testing && php test.php functional
Functional
OK
Test cases run: 0/0, Passes: 0, Failures: 0, Exceptions: 0

create a unit test (tests/unit/myfirsttest.php)

<?php

class test_myfirsttest extends api_testing_case_unit
{
    function test_assertTrue(){
        $this->assertTrue(true);
    }
}

create a functional tests (tests/functional/myFirstFunctionalTest.php)

<?php

class test_myFirstFuntionalTest extends api_testing_case_functional
{
    function test_assertTrue(){
        $this->get("/");
        $this->openInBrowser();
    }
} 

Additional information

  • Note that all tests are run on the CLI. This means that SESSION are not available for example and that depending on how PHP is setup a different php.ini will be used. In order to mock aspects or to handle differences between the normal and the testing setup, okapi is called with the environment set to "test". So for example this can be used to set the configuration to use a mock'ed auth container instead of the production one.
  • The default functional testing is tightly coupled to XML. You will have to at least overwrite the loadResponse() method as well as the openInBrowser() method if you are not operating on XML DOM.
  • Note that an Exception (Test cases run: 2/4, Passes: 50, Failures: 0, Exceptions: 1) indicates an unsuppressed warning/notice etc.

Labels:

Enter labels to add to this page:
Wait Image 
Looking for a label? Just start typing.