[TYPO3-dev] T3unit skeleton

Elmar Hinz elmar.DOT.hinz at team.MINUS.red.DOT.net
Mon Apr 3 09:19:33 CEST 2006


UPDATE 2:

This is a skeleton for testcases:

Features:

* runs within T3Unit
* runs from commonadline, called from different directories
* minimal editing to startup: 5 places marked with xxx
* XCLASSED: no errors in extManager
* copyright notice
* will ever run with t3unit

Changelog:

        * Inherit t3unit_testcase:
          class tx_ter_soap_testcase extends tx_t3unit_testcase {
        * Constructor:
        public function __construct ($name) {
                parent::__construct ($name);
        }
        * line 99: eval($class . '::main();');

/el




<?php

/***************************************************************
 *  Copyright notice
 *
 *  (c) 2006 xxx
 *  Contact: xxx
 *  All rights reserved
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 ***************************************************************/


// 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 tx_t3unit_testcase  {

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

    /**
     * Constructor
     *
     * @par  string       name
     */
     public function __construct ($name) {
          parent::__construct ($name);
     }

    /**
     * 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') {
        eval($class . '::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