inCli() публичный статический Метод

Static check for running in the comand line.
public static inCli ( ) : boolean
Результат boolean True if CLI.
Пример #1
0
 public function run()
 {
     $test = new GroupTest("Piwik - running '{$this->testGroupType}' tests...");
     $intro = '';
     if (!$this->databaseRequired) {
         $intro .= $this->getTestDatabaseInfoMessage();
     }
     $intro .= self::$testsHelpLinks . "<hr/>";
     $intro .= $this->introAppend;
     $toInclude = array();
     foreach ($this->dirsToGlob as $dir) {
         $toInclude = array_merge($toInclude, Piwik::globr(PIWIK_INCLUDE_PATH . $dir, '*.test.php'));
     }
     // if present, make sure Database.test.php is first
     $idx = array_search(PIWIK_INCLUDE_PATH . '/tests/core/Database.test.php', $toInclude);
     if ($idx !== FALSE) {
         unset($toInclude[$idx]);
         array_unshift($toInclude, PIWIK_INCLUDE_PATH . '/tests/core/Database.test.php');
     }
     foreach ($toInclude as $file) {
         $test->addFile($file);
     }
     $result = $test->run(new HtmlTimerReporter($intro));
     if (SimpleReporter::inCli()) {
         exit($result ? 0 : 1);
     }
 }
Пример #2
0
 /**
  *    Paints the title only.
  *    @param string $test_name        Name class of test.
  *    @access public
  */
 function paintHeader($test_name)
 {
     if (!SimpleReporter::inCli()) {
         header('Content-type: text/plain');
     }
     print "{$test_name}\n";
     flush();
 }
Пример #3
0
/**
 *    Exit handler to run all recent test cases and exit system if in CLI
 */
function simpletest_autorun() {
	chdir($GLOBALS['SIMPLETEST_AUTORUNNER_INITIAL_PATH']);
    if (tests_have_run()) {
        return;
    }
    $result = run_local_tests();
    if (SimpleReporter::inCli()) {
        exit($result ? 0 : 1);
    }
}
Пример #4
0
/**
 *    Exit handler to run all recent test cases and exit system if in CLI
 */
function simpletest_autorun()
{
    if (tests_have_run()) {
        return;
    }
    $result = run_local_tests();
    if (SimpleReporter::inCli()) {
        exit($result ? 0 : 1);
    }
}
Пример #5
0
 /**
  *  Assembles the appopriate reporter for the environment.
  */
 function DefaultReporter()
 {
     if (SimpleReporter::inCli()) {
         global $argv;
         $parser = new SimpleCommandLineParser($argv);
         $interfaces = $parser->isXml() ? array('XmlReporter') : array('TextReporter');
         $reporter =& new SelectiveReporter(SimpleTest::preferred($interfaces), $parser->getTestCase(), $parser->getTest());
     } else {
         $reporter =& new SelectiveReporter(SimpleTest::preferred('HtmlReporter'), @$_GET['c'], @$_GET['t']);
     }
     $this->SimpleReporterDecorator($reporter);
 }
Пример #6
0
/**
 *    Exit handler to run all recent test cases if no test has
 *    so far been run. Uses the DefaultReporter which can have
 *    it's output controlled with SimpleTest::prefer().
 */
function simpletest_autorun()
{
    if (tests_have_run()) {
        return;
    }
    $candidates = array_intersect(capture_new_classes(), classes_defined_in_initial_file());
    $loader = new SimpleFileLoader();
    $suite = $loader->createSuiteFromClasses(basename(initial_file()), $loader->selectRunnableTests($candidates));
    $result = $suite->run(new DefaultReporter());
    if (SimpleReporter::inCli()) {
        exit($result ? 0 : 1);
    }
}
Пример #7
0
/**
 *    Exit handler to run all recent test cases if no test has
 *    so far been run. Uses the DefaultReporter which can have
 *    it's output controlled with SimpleTest::prefer().
 */
function simpletest_autorun()
{
    try {
        if (tests_have_run()) {
            return;
        }
        $candidates = array_intersect(capture_new_classes(), classes_defined_in_initial_file());
        $loader = new SimpleFileLoader();
        $suite = $loader->createSuiteFromClasses(basename(initial_file()), $loader->selectRunnableTests($candidates));
        $result = $suite->run(new DefaultReporter());
    } catch (Exception $e) {
        // This is here, because under normal circumstances shutdown
        // functions don't have a stack frame, leading to obscure errors.
        echo $e->__toString();
        $result = false;
    }
    if (SimpleReporter::inCli()) {
        exit($result ? 0 : 1);
    }
}
Пример #8
0
 /**
  *  Assembles the appropriate reporter for the environment.
  */
 function __construct()
 {
     if (SimpleReporter::inCli()) {
         $parser = new SimpleCommandLineParser($_SERVER['argv']);
         $interfaces = $parser->isXml() ? array('XmlReporter') : array('TextReporter');
         if ($parser->help()) {
             // I'm not sure if we should do the echo'ing here -- ezyang
             echo $parser->getHelpText();
             exit(1);
         }
         $reporter = new SelectiveReporter(SimpleTest::preferred($interfaces), $parser->getTestCase(), $parser->getTest());
         if ($parser->noSkips()) {
             $reporter = new NoSkipsReporter($reporter);
         }
     } else {
         $reporter = new SelectiveReporter(SimpleTest::preferred('HtmlReporter'), @$_GET['c'], @$_GET['t']);
         if (@$_GET['skips'] == 'no' || @$_GET['show-skips'] == 'no') {
             $reporter = new NoSkipsReporter($reporter);
         }
     }
     parent::__construct($reporter);
 }
 /**
  * Run a single test case with the given name, using the provided output format.
  * @param string $testName
  * @param string $format (xml, text or html)
  * @return int
  */
 public function runTestCase($testName, $format = Sweety_Runner::REPORT_TEXT)
 {
     foreach ($this->_testLocators as $locator) {
         if ($locator->includeTest($testName)) {
             break;
         }
     }
     $testClass = new ReflectionClass($testName);
     if ($testClass->getConstructor()) {
         //We don't want test output to be cached
         if (!SimpleReporter::inCli()) {
             header("Cache-Control: no-cache, must-revalidate");
             header("Pragma: no-cache");
             header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
         }
         switch ($format) {
             case Sweety_Runner::REPORT_HTML:
                 $reporter = new HtmlReporter();
                 break;
             case Sweety_Runner::REPORT_XML:
                 if (!SimpleReporter::inCli()) {
                     header("Content-Type: text/xml");
                     //Sigh! SimpleTest (skip() issues).
                 }
                 $reporter = new XmlReporter();
                 break;
             case Sweety_Runner::REPORT_TEXT:
             default:
                 $reporter = new TextReporter();
                 break;
         }
         $test = $testClass->newInstance();
         return $test->run($reporter) ? 0 : 1;
     }
     return 1;
 }
Пример #10
0
 /**
  * Assembles the appropriate reporter for the environment.
  */
 public function __construct()
 {
     if (SimpleReporter::inCli()) {
         $parser = new SimpleCommandLineParser($_SERVER['argv']);
         $this->doCodeCoverage = $parser->doCodeCoverage();
         $this->excludes = $parser->getExcludes();
         if ($parser->isXml()) {
             $interfaces = array('XmlReporter');
         } else {
             if ($parser->isJUnit()) {
                 $interfaces = array('JUnitXmlReporter');
             } else {
                 $interfaces = array('TextReporter');
             }
         }
         if ($parser->help()) {
             echo $parser->getHelpText();
             exit(1);
         }
         $reporter = new SelectiveReporter(SimpleTest::preferred($interfaces), $parser->getTestCase(), $parser->getTest());
         if ($parser->noSkips()) {
             $reporter = new NoSkipsReporter($reporter);
         }
     } else {
         $reporter = new SelectiveReporter(SimpleTest::preferred('HtmlReporter'), @$_GET['c'], @$_GET['t']);
         if (@$_GET['skips'] === 'no' || @$_GET['show-skips'] === 'no') {
             $reporter = new NoSkipsReporter($reporter);
         }
     }
     parent::__construct($reporter);
 }
Пример #11
0
 /**
  *  Assembles the appopriate reporter for the environment.
  */
 function __construct()
 {
     if (SimpleReporter::inCli()) {
         global $argv;
         $parser = new SimpleCommandLineParser($argv);
         $interfaces = $parser->isXml() ? array('XmlReporter') : array('TextReporter');
         $reporter =& new SelectiveReporter(SimpleTest::preferred($interfaces), $parser->getTestCase(), $parser->getTest());
         if ($parser->noSkips()) {
             $reporter =& new NoSkipsReporter($reporter);
         }
     } else {
         $reporter =& new SelectiveReporter(SimpleTest::preferred('HtmlReporter'), @$_GET['c'], @$_GET['t']);
         if (@$_GET['skips'] == 'no' || @$_GET['show-skips'] == 'no') {
             $reporter =& new NoSkipsReporter($reporter);
         }
     }
     parent::__construct($reporter);
 }
Пример #12
0
 /**
  * Paints the test document header.
  *
  * @param string $test_name     First test top level to start.
  *
  * @abstract
  */
 public function paintHeader($test_name)
 {
     if (!SimpleReporter::inCli()) {
         header('Content-type: text/xml');
     }
     print '<?xml version="1.0"';
     if ($this->namespace) {
         print ' xmlns:' . $this->namespace . '="www.lastcraft.com/SimpleTest/Beta3/Report"';
     }
     print "?>\n";
     print '<' . $this->namespace . "run>\n";
 }
Пример #13
0
 /**
  * Sets the text/plain header if the test is not a CLI test.
  *
  * @return void
  */
 function paintDocumentStart()
 {
     if (!SimpleReporter::inCli()) {
         header('Content-type: text/plain');
     }
 }
Пример #14
0
 /**
  * @return SimpleReporter
  */
 function _createDefaultReporter()
 {
     if (SimpleReporter::inCli()) {
         $reporter = new TextReporter();
     } else {
         $reporter = new TracHtmlReporter();
     }
     return $reporter;
 }
Пример #15
0
 /**
  *    Paints the test document header.
  *    @param string $test_name     First test top level
  *                                 to start.
  *    @access public
  *    @abstract
  */
 function paintHeader($test_name)
 {
     if (!SimpleReporter::inCli()) {
         header('Content-type: text/xml');
     }
     print "<?xml version=\"1.0\"";
     if ($this->_namespace) {
         print " xmlns:" . $this->_namespace . "=\"www.lastcraft.com/SimpleTest/Beta3/Report\"";
     }
     print "?>\n";
     print "<" . $this->_namespace . "run>\n";
 }
Пример #16
0
{
    function UnitTests()
    {
        $this->GroupTest("Unit tests");
        $this->addTestFile("errors_test.php");
        $this->addTestFile("options_test.php");
        $this->addTestFile("dumper_test.php");
        $this->addTestFile("expectation_test.php");
        $this->addTestFile("simple_mock_test.php");
        $this->addTestFile("adapter_test.php");
        $this->addTestFile("socket_test.php");
        $this->addTestFile("query_string_test.php");
        $this->addTestFile("http_test.php");
        $this->addTestFile("user_agent_test.php");
        $this->addTestFile("browser_test.php");
        $this->addTestFile("parser_test.php");
        $this->addTestFile("tag_test.php");
        $this->addTestFile("page_test.php");
        $this->addTestFile("frames_test.php");
        $this->addTestFile("shell_tester_test.php");
        $this->addTestFile("xml_test.php");
    }
}
if (!defined("TEST_RUNNING")) {
    define("TEST_RUNNING", true);
    $test =& new UnitTests();
    if (SimpleReporter::inCli()) {
        exit($test->run(new TextReporter()) ? 0 : 1);
    }
    $test->run(new HtmlReporter());
}
Пример #17
0
 /**
  *  Assembles the appropriate reporter for the environment.
  */
 function __construct($arguments = null)
 {
     $in_cli = SimpleReporter::inCli();
     if ($in_cli) {
         $parser = new SimpleCommandLineParser(is_array($arguments) ? $arguments : $_SERVER['argv']);
     } else {
         $parser = new WebCommandLineParser(is_array($arguments) ? $arguments : array_merge(array(), isset($_GET) && is_array($_GET) ? $_GET : array(), isset($_POST) && is_array($_POST) ? $_POST : array()));
     }
     $interfaces = $parser->isXml() ? array('XmlReporter') : ($in_cli ? array('TextReporter') : array('HtmlReporter'));
     $interfaces = $parser->isXml() ? array('XmlReporter') : ($in_cli ? array('TextReporter') : array('HtmlReporter'));
     if ($parser->help()) {
         // I'm not sure if we should do the echo'ing here -- ezyang
         echo $parser->getHelpText();
         exit(1);
     }
     // make sure we set the 'default server URI' for all tests now s it's a once-only write operation and we gotta be the first to win:
     /* void */
     $parser->getServerUrl();
     $reporter = new SelectiveReporter(SimpleTest::preferred($interfaces), $parser->getTestCase(), $parser->getTest());
     if ($parser->noSkips()) {
         $reporter = new NoSkipsReporter($reporter);
     }
     if (!$parser->showPasses()) {
         $reporter = new NoPassesReporter($reporter);
     }
     $reporter = new ListTestReporter($reporter);
     parent::__construct($reporter);
     $this->makeDry($parser->isDryRun());
     $this->makeList($parser->isListRun());
     $this->includeBreadCrumb($parser->showBreadCrumb());
     $this->includeStackTrace($parser->showStackTrace());
 }