SimpleTest

SipleTest is a framework for PHP unit tests, checking the functionality of each function or sub unit. Mock-up data and mock-up interfaces provide means of standardized regression testing.

Usage

The SimpleTest test scripts of the ea-Geier are located in the test/simpletest test folder and are started by

http://SERVER/PATHTOEAGEIER/test/simpletest/index.php

Test Suite

The test/simpletest/index.php file acts also as test suite holding references to all SimpleTest test scripts located in the same folder.

New test cases are added by adding a new line to the test-suite:

$test->addTestFile('test/simpletest/test_dummy.php'); 

Test Case

A test case is a sub class inherited by a class holding the required test functionality. The actual tests are added as methods in the test case whose names by default start with the string “test” and when the test case is invoked all such methods are run in the order that PHP finds them.

require_once('MyFunction.php'); // include the file you want to test
class MyTestCase extends UnitTestCase { // generate the test case
  function MyTestCase() {
    $this->UnitTestCase('My Test');
  }
  function setUp() {
    // to something before each test 
  }
  function tearDown() {
    // to something after each test 
  }    
  function testMyFirstTest() {
    // the actual testing
  }
}

The setUp() method is run just before each and every test method. tearDown() is run just after each and every test method.

The actual testing/checking is done by assertions:

assertTrue($x) Fail if $x is false
assertFalse($x) Fail if $x is true
assertNull($x) Fail if $x is set
assertNotNull($x) Fail if $x not set
assertIsA($x, $t) Fail if $x is not the class or type $t
assertNotA($x, $t) Fail if $x is of the class or type $t
assertEqual($x, $y) Fail if $x == $y is false
assertNotEqual($x, $y) Fail if $x == $y is true
assertWithinMargin($x, $y, $m) Fail if abs($x – $y) < $m is false
assertOutsideMargin($x, $y, $m) Fail if abs($x – $y) < $m is true
assertIdentical($x, $y) Fail if $x == $y is false or a type mismatch
assertNotIdentical($x, $y) Fail if $x == $y is true and types match
assertReference($x, $y) Fail unless $x and $y are the same variable
assertClone($x, $y) Fail unless $x and $y are identical copies
assertPattern($p, $x) Fail unless the regex $p matches $x
assertNoPattern($p, $x) Fail if the regex $p matches $x
expectError($x) Swallows any upcoming matching error
assert($e) Fail on failed expectation object $e

See the Reference Guide for a complete list of commands.

Bundling

To increase security and because SimpleTest is used only for testing it will not be bundled with production releases.

As 3rd-party product it will also not be checked into the repository.

If you want to run the unit tests and the SimpleTest code is missing in your ea-Geier distribution, please download it from the SimpleTest homepage.

Unzip the code into the 3party/simpletest/ folder – e.g.:

3party/simpletest/simpletest_1.0.1beta/

and make sure the SIMPLE_TEST definition in the test suit is configured properly. To do this, open the the file code/config.php. Look for SIMPLE_TEST and change the value to the name of the folder you have just uploaded – e.g.:

define('SIMPLE_TEST', '3party/simpletest/simpletest_1.0.1beta/');