CodeView

PHPUnit test harness for Komodo

KoDebugRun.php

<?php
 
    /**
     * @author  Michael Heim
     * @link    http://www.zeilenwechsel.de/
     * @version 1.2.0
     * @license http://www.zeilenwechsel.de/it/code/browse/komodo-phpunit-harness/prod/license.txt
     */
 
    /**
     * Manages a debug run.
     */
    class KoDebugRun extends DebugRun {
 
        public function __construct () {
 
            $this->init()
                 ->set_testrunner( 'drive_testrunner.php' );
 
        }
 
        /**
         * @return KoDebugRun
         */
        protected function set_working_dir () {
 
            // XML config file scenario: No need to change the working dir to the dir
            // used for the config file.
            // 
            // Komodo adds the dir information to the argv array, and that must be
            // sufficient for the Komodo test harness.
 
            chdir( dirname( $_SERVER['SCRIPT_FILENAME'] ) );
            return $this;
 
        }
 
        /**
         * Sets up $_SERVER[ 'argv' ] and $_SERVER[ 'argc' ] with the content of the command line
         * corresponding to a given set of arguments.
         * 
         * @param  array       $arg_array     the argument set the $_SERVER vars are generated for. 
         * @return KoDebugRun
         */
        public function create_server_vars( array $arg_array ) {
 
            parent::create_server_vars( $arg_array );
 
            if ( isset( $this->dummytest_filepath ) ) {
 
                $testdir = dirname( $this->dummytest_filepath );
 
            } else {
 
                $testdir = $this->dummytest_xml_dir;
 
            }
 
            array_splice( $_SERVER[ 'argv' ], 1, 0, $testdir );
 
            $_SERVER[ 'argc' ] = count( $_SERVER[ 'argv' ] );
 
            return $this;
 
        }
 
        /**
         * Creates the class and starts the debug run.
         *
         * See go() for details.
         *
         * @param  string $dummy_test  a file path to a test file, or a dir path for an XML configuration
         * @param  array  $switches
         *
         * @return string  the output of the debug run
         */
        public static function exec ( $dummy_test, array $switches ) {
 
            $debug_run = new self();
            return $debug_run->go( $dummy_test, $switches );
 
        }
 
    }
 
?>