[TYPO3-dev] T3unit skeleton

Elmar Hinz elmar.DOT.hinz at team.MINUS.red.DOT.net
Sat Apr 1 10:09:31 CEST 2006


This is a skeleton for testcases:

Features:

* runs within T3Unit
* runs from commonadline, called from different directories
* minimal editing to startup: 3 places marked with xxx
* XCLASSED: no errors in extManager

/el



<?php

// Set configuration first
$key = 'xxx';   // extension key
$class = 'tx_xxx_testcase'; // class name

// Fix part to set before class definition
error_reporting (E_ALL ^ E_NOTICE);
require_once ('PHPUnit2/Framework/TestCase.php');
require_once ('PHPUnit2/Framework/TestSuite.php');

/**
 * Test class for tx_lib_t3Loader
 */
class tx_xxx_testcase extends PHPUnit2_Framework_TestCase {

    /****************************************************************
     * main, setUP, tearDown
     ****************************************************************/

    /**
     * Sets up the fixture, for example, open a network connection.
     * This method is called before a test is executed.
     *
     * @access protected
     */
    protected function setUp() {
    }

    /**
     * Tears down the fixture, for example, close a network connection.
     * This method is called after a test is executed.
     *
     * @access protected
     */
    protected function tearDown() {
    }

    /**
     * Runs the test methods of this class.
     *
     * @access public
     * @static
     */
    public static function main() {
        global $class;
        require_once "PHPUnit2/TextUI/TestRunner.php";
        $suite  = new PHPUnit2_Framework_TestSuite($class);
        $result = PHPUnit2_TextUI_TestRunner::run($suite);
    }

}

// Fix part to set after class definition
if(!defined('PATH_site')) { // If running from command line

    // Setup environment
    $path = realpath($_SERVER['PWD'] .'/'. $_SERVER['SCRIPT_NAME']);
    if(!preg_match('|(.*)(typo3conf.*)(' . $key . '/test)|', $path, $matches)) {
        if(! preg_match('|(.*)(typo3/sysext.*)(' . $key . '/test)|', $path, $matches))
            exit(chr(10) . 'Unknown installation path' . chr(10). $path . chr(10));
    }
    define('PATH_site', $matches[1]);
    $GLOBALS['TYPO3_LOADED_EXT'][$key]['siteRelPath']= $matches[2] . $key . '/';
    define('PATH_t3lib', PATH_site . 't3lib/');
    require_once(PATH_t3lib . 'class.t3lib_div.php');
    require_once(PATH_t3lib . 'class.t3lib_extmgm.php');

    // define main method if neede
    if (!defined('PHPUnit2_MAIN_METHOD')) {
        define('PHPUnit2_MAIN_METHOD', $class . '::main');
    }

    // Call main()
    if (PHPUnit2_MAIN_METHOD == $class . '::main') {
        tx_lib_t3Loader_testcase::main();
    }
}

if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/' . $key . '/tests/class.' $class . '.php']) {
    include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/' . $key . '/tests/class.' . $class . '.php']);
}

?>




More information about the TYPO3-dev mailing list