startTest() public method

Informs the result that a test will be started.
public startTest ( PHPUnit_Framework_Test $test )
$test PHPUnit_Framework_Test
 public function run(PHPUnit_Framework_TestResult $result = null)
 {
     $result->startTest($this);
     $this->testCase->runBare();
     $this->testCase->runBare();
     $result->endTest($this, 0);
 }
Ejemplo n.º 2
0
 public function run(\PHPUnit_Framework_TestResult $result = null)
 {
     if (!$result) {
         $result = new \PHPUnit_Framework_TestResult();
     }
     $reader = new \Fulfil\Test\SpecTest\Reader();
     $tests = $reader->read($testFile);
     foreach ($tests as $test) {
         foreach ($test->data as $case) {
             \PHP_Timer::start();
             $result->startTest($this);
             try {
                 $ctx = new \Fulfil\Context();
                 $test->test->apply($case->in, $ctx);
                 $flat = $ctx->flatten();
             } catch (\Exception $ex) {
                 // yum
             }
             $time = \PHP_Timer::stop();
             try {
                 \PHPUnit_Framework_Assert::assertEquals($case->valid, $flat->valid);
             } catch (\PHPUnit_Framework_AssertionFailedError $e) {
                 $result->addFailure($this, $e, $time);
             }
             $result->endTest($this, $time);
         }
     }
     return $result;
 }
Ejemplo n.º 3
0
 public function run(\PHPUnit_Framework_TestResult $result = null)
 {
     if (!$result) {
         $result = new \PHPUnit_Framework_TestResult();
     }
     $opt = null;
     \PHP_Timer::start();
     $result->startTest($this);
     try {
         $opt = \Docopt::handle($this->doc, array('argv' => $this->argv, 'exit' => false));
     } catch (\Exception $ex) {
         // gulp
     }
     $found = null;
     if ($opt) {
         if (!$opt->success) {
             $found = array('user-error');
         } elseif (empty($opt->args)) {
             $found = array();
         } else {
             $found = $opt->args;
         }
     }
     $time = \PHP_Timer::stop();
     try {
         \PHPUnit_Framework_Assert::assertEquals($this->expect, $found);
     } catch (\PHPUnit_Framework_AssertionFailedError $e) {
         $result->addFailure($this, $e, $time);
     }
     $result->endTest($this, $time);
     return $result;
 }
Ejemplo n.º 4
0
 /**
  * Processes the standard output and standard error for the test results.
  *
  * @return void|array
  */
 public function processResults()
 {
     if ($this->_result === null) {
         return;
     }
     /* Needs to start the test here because the result itself may be shared across processes, and it
           keeps track of the current test
        */
     $this->_result->startTest($this->_test);
     $this->getPhpUnitUtils()->processChildResult($this->_test, $this->_result, $this->_stdout, $this->_stderr);
 }
Ejemplo n.º 5
0
 /**
  * Runs a test and collects its result in a TestResult instance.
  *
  * @param  PHPUnit_Framework_TestResult $result
  * @return PHPUnit_Framework_TestResult
  */
 public function run(PHPUnit_Framework_TestResult $result = null)
 {
     $sections = $this->parse();
     $code = $this->render($sections['FILE']);
     if ($result === null) {
         $result = new PHPUnit_Framework_TestResult();
     }
     $php = PHPUnit_Util_PHP::factory();
     $skip = false;
     $time = 0;
     $settings = $this->settings;
     $result->startTest($this);
     if (isset($sections['INI'])) {
         $settings = array_merge($settings, $this->parseIniSection($sections['INI']));
     }
     if (isset($sections['SKIPIF'])) {
         $jobResult = $php->runJob($sections['SKIPIF'], $settings);
         if (!strncasecmp('skip', ltrim($jobResult['stdout']), 4)) {
             if (preg_match('/^\\s*skip\\s*(.+)\\s*/i', $jobResult['stdout'], $message)) {
                 $message = substr($message[1], 2);
             } else {
                 $message = '';
             }
             $result->addFailure($this, new PHPUnit_Framework_SkippedTestError($message), 0);
             $skip = true;
         }
     }
     if (!$skip) {
         PHP_Timer::start();
         $jobResult = $php->runJob($code, $settings);
         $time = PHP_Timer::stop();
         if (isset($sections['EXPECT'])) {
             $assertion = 'assertEquals';
             $expected = $sections['EXPECT'];
         } else {
             $assertion = 'assertStringMatchesFormat';
             $expected = $sections['EXPECTF'];
         }
         $output = preg_replace('/\\r\\n/', "\n", trim($jobResult['stdout']));
         $expected = preg_replace('/\\r\\n/', "\n", trim($expected));
         try {
             PHPUnit_Framework_Assert::$assertion($expected, $output);
         } catch (PHPUnit_Framework_AssertionFailedError $e) {
             $result->addFailure($this, $e, $time);
         } catch (Throwable $t) {
             $result->addError($this, $t, $time);
         } catch (Exception $e) {
             $result->addError($this, $e, $time);
         }
     }
     $result->endTest($this, $time);
     return $result;
 }
Ejemplo n.º 6
0
 /**
  * Runs a test and collects its result in a TestResult instance.
  *
  * @param  \PHPUnit_Framework_TestResult $result
  * @return \PHPUnit_Framework_TestResult
  */
 public function run(\PHPUnit_Framework_TestResult $result = null)
 {
     if ($result === null) {
         $result = new \PHPUnit_Framework_TestResult();
     }
     $zept = $this->zeptHydrator->zeptToDto($this->filename, $this->settings);
     $result->startTest($this);
     if ($zept->isSkip()) {
         $result->addFailure($this, new \PHPUnit_Framework_SkippedTestError($zept->getSkipMessage()), 0);
     } else {
         $result = $this->doRun($result, $zept);
     }
     return $result;
 }
Ejemplo n.º 7
0
 public function run(PHPUnit_Framework_TestResult $result = null)
 {
     PHPUnit_Framework_Assert::resetCount();
     if ($result === NULL) {
         $result = new PHPUnit_Framework_TestResult();
     }
     $this->suite->publishTestArticles();
     // Add articles needed by the tests.
     $backend = new ParserTestSuiteBackend();
     $result->startTest($this);
     // Support the transition to PHPUnit 3.5 where PHPUnit_Util_Timer is replaced with PHP_Timer
     if (class_exists('PHP_Timer')) {
         PHP_Timer::start();
     } else {
         PHPUnit_Util_Timer::start();
     }
     $r = false;
     try {
         # Run the test.
         # On failure, the subclassed backend will throw an exception with
         # the details.
         $pt = new PHPUnitParserTest();
         $r = $pt->runTest($this->test['test'], $this->test['input'], $this->test['result'], $this->test['options'], $this->test['config']);
     } catch (PHPUnit_Framework_AssertionFailedError $e) {
         // PHPUnit_Util_Timer -> PHP_Timer support (see above)
         if (class_exists('PHP_Timer')) {
             $result->addFailure($this, $e, PHP_Timer::stop());
         } else {
             $result->addFailure($this, $e, PHPUnit_Util_Timer::stop());
         }
     } catch (Exception $e) {
         // PHPUnit_Util_Timer -> PHP_Timer support (see above)
         if (class_exists('PHP_Timer')) {
             $result->addFailure($this, $e, PHP_Timer::stop());
         } else {
             $result->addFailure($this, $e, PHPUnit_Util_Timer::stop());
         }
     }
     // PHPUnit_Util_Timer -> PHP_Timer support (see above)
     if (class_exists('PHP_Timer')) {
         $result->endTest($this, PHP_Timer::stop());
     } else {
         $result->endTest($this, PHPUnit_Util_Timer::stop());
     }
     $backend->recorder->record($this->test['test'], $r);
     $this->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
     return $result;
 }
Ejemplo n.º 8
0
 /**
  * Runs a test and collects its result in a TestResult instance.
  * Executes before/after hooks coming from traits.
  *
  * @param  \PHPUnit_Framework_TestResult $result
  * @return \PHPUnit_Framework_TestResult
  */
 public final function run(\PHPUnit_Framework_TestResult $result = null)
 {
     $this->testResult = $result;
     $result->startTest($this);
     foreach ($this->hooks as $hook) {
         if (method_exists($this, $hook . 'Start')) {
             $this->{$hook . 'Start'}();
         }
     }
     $status = self::STATUS_PENDING;
     $time = 0;
     $e = null;
     if (!$this->ignored) {
         \PHP_Timer::start();
         try {
             $this->test();
             $status = self::STATUS_OK;
         } catch (\PHPUnit_Framework_AssertionFailedError $e) {
             $status = self::STATUS_FAIL;
         } catch (\PHPUnit_Framework_Exception $e) {
             $status = self::STATUS_ERROR;
         } catch (\Throwable $e) {
             $e = new \PHPUnit_Framework_ExceptionWrapper($e);
             $status = self::STATUS_ERROR;
         } catch (\Exception $e) {
             $e = new \PHPUnit_Framework_ExceptionWrapper($e);
             $status = self::STATUS_ERROR;
         }
         $time = \PHP_Timer::stop();
     }
     foreach (array_reverse($this->hooks) as $hook) {
         if (method_exists($this, $hook . 'End')) {
             $this->{$hook . 'End'}($status, $time, $e);
         }
     }
     $result->endTest($this, $time);
     return $result;
 }
Ejemplo n.º 9
0
 /**
  * Runs a single job (PHP code) using a separate PHP process.
  *
  * @param  string                       $job
  * @param  PHPUnit_Framework_TestCase   $test
  * @param  PHPUnit_Framework_TestResult $result
  * @return array|null
  * @throws PHPUnit_Framework_Exception
  */
 public function runJob($job, PHPUnit_Framework_Test $test = NULL, PHPUnit_Framework_TestResult $result = NULL)
 {
     $process = proc_open(PHP_BINARY, array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')), $pipes);
     if (!is_resource($process)) {
         throw new PHPUnit_Framework_Exception('Unable to create process for process isolation.');
     }
     if ($result !== NULL) {
         $result->startTest($test);
     }
     $this->process($pipes[0], $job);
     fclose($pipes[0]);
     $stdout = stream_get_contents($pipes[1]);
     fclose($pipes[1]);
     $stderr = stream_get_contents($pipes[2]);
     fclose($pipes[2]);
     proc_close($process);
     $this->cleanup();
     if ($result !== NULL) {
         $this->processChildResult($test, $result, $stdout, $stderr);
     } else {
         return array('stdout' => $stdout, 'stderr' => $stderr);
     }
 }
Ejemplo n.º 10
0
 /**
  * Runs a single test in a separate PHP process.
  *
  * @param string $job        	
  * @param PHPUnit_Framework_Test $test        	
  * @param PHPUnit_Framework_TestResult $result        	
  * @throws PHPUnit_Framework_Exception
  */
 public function runTestJob($job, PHPUnit_Framework_Test $test, PHPUnit_Framework_TestResult $result)
 {
     $result->startTest($test);
     $_result = $this->runJob($job);
     $this->processChildResult($test, $result, $_result['stdout'], $_result['stderr']);
 }
 /**
  * Runs a test and collects its result in a TestResult instance.
  *
  * @param  PHPUnit_Framework_TestResult $result
  * @param  array $options Array with ini settings for the php instance run,
  *                        key being the name if the setting, value the ini value.
  * @return PHPUnit_Framework_TestResult
  * @access public
  */
 public function run(PHPUnit_Framework_TestResult $result = NULL, $options = array())
 {
     if (!class_exists('PEAR_RunTest', FALSE)) {
         throw new RuntimeException('Class PEAR_RunTest not found.');
     }
     if ($result === NULL) {
         $result = new PHPUnit_Framework_TestResult();
     }
     if (!is_array($options)) {
         throw new InvalidArgumentException();
     }
     $options = array_merge($options, $this->options);
     $coverage = $result->getCollectCodeCoverageInformation();
     if ($coverage) {
         $options = array('coverage' => TRUE);
     } else {
         $options = array();
     }
     $runner = new PEAR_RunTest(new PHPUnit_Extensions_PhptTestCase_Logger(), $options);
     if ($coverage) {
         $runner->xdebug_loaded = TRUE;
     } else {
         $runner->xdebug_loaded = FALSE;
     }
     $result->startTest($this);
     PHPUnit_Util_Timer::start();
     $buffer = $runner->run($this->filename, $options);
     $time = PHPUnit_Util_Timer::stop();
     $base = basename($this->filename);
     $path = dirname($this->filename);
     $coverageFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.xdebug', $base);
     $diffFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.diff', $base);
     $expFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.exp', $base);
     $logFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.log', $base);
     $outFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.out', $base);
     $phpFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.php', $base);
     if (is_object($buffer) && $buffer instanceof PEAR_Error) {
         $result->addError($this, new RuntimeException($buffer->getMessage()), $time);
     } else {
         if ($buffer == 'SKIPPED') {
             $result->addFailure($this, new PHPUnit_Framework_SkippedTestError(), 0);
         } else {
             if ($buffer != 'PASSED') {
                 $result->addFailure($this, PHPUnit_Framework_ComparisonFailure::diffEqual(file_get_contents($expFile), file_get_contents($outFile), FALSE, $this->getName()), $time);
             }
         }
     }
     foreach (array($diffFile, $expFile, $logFile, $phpFile, $outFile) as $file) {
         if (file_exists($file)) {
             unlink($file);
         }
     }
     if ($coverage) {
         eval('$coverageData = ' . file_get_contents($coverageFile) . ';');
         unset($coverageData[$phpFile]);
         $codeCoverageInformation = array('test' => $this, 'files' => $coverageData);
         $result->appendCodeCoverageInformation($this, $codeCoverageInformation);
         unlink($coverageFile);
     }
     $result->endTest($this, $time);
     return $result;
 }
 public function run(PHPUnit_Framework_TestResult $result = NULL)
 {
     if ($result === NULL) {
         $result = new PHPUnit_Framework_TestResult();
         $result->startTest($this);
         $counter = 0;
         foreach ($this->queries as $query_data) {
             $query = 'EXPLAIN ' . $query_data['query'];
             $parameters = $query_data['parameters'];
             $parameters_print = '';
             try {
                 if (!empty($parameters)) {
                     $res = Dal::query($query, $parameters);
                     $parameters_print = 'PARAMETERS:' . "\n";
                     foreach ($parameters as $param) {
                         $parameters_print .= '- ' . $param . "\n";
                     }
                 } else {
                     $res = Dal::query($query);
                 }
             } catch (PAException $e) {
                 try {
                     PHPUnit_Framework_Assert::assertEquals($e->getCode(), DB_QUERY_FAILED);
                 } catch (PHPUnit_Framework_AssertionFailedError $e) {
                     $result->addFailure($this, $e);
                 } catch (Exception $e) {
                     $result->addError($this, $e);
                 }
             }
             $tables = array();
             print "{{{ ==================================================================\n";
             $query_row = wordwrap($explain . "QUERY: \"{$query}\"", 70);
             print $query_row . "\n";
             if (!empty($parameters_print)) {
                 print "----------------------------------------------------------------------\n";
                 print $parameters_print;
             }
             while ($row = $res->fetchRow(DB_FETCHMODE_OBJECT)) {
                 print "----------------------------------------------------------------------\n";
                 print 'ID: ' . $row->id . "\n";
                 print 'SELECT TYPE: ' . $row->select_type . "\n";
                 print 'TABLE: ' . $row->table . "\n";
                 if (!empty($row->table)) {
                     $tables[] = $row->table;
                 }
                 print 'TYPE: ' . $row->type . "\n";
                 print 'POSSIBLE KEYS: ' . $row->possible_keys . "\n";
                 print 'KEY: ' . $row->key . "\n";
                 print 'KEY LENGTH: ' . $row->key_len . "\n";
                 print 'REFERENCE: ' . $row->ref . "\n";
                 print 'ROWS: ' . $row->rows . "\n";
                 print 'EXTRA: ' . $row->Extra . "\n";
                 $counter++;
             }
             // Now show all the tables used in the query.
             foreach ($tables as $table) {
                 print "----------------------------------------------------------------------\n";
                 try {
                     $create_table = Dal::query_one("SHOW CREATE TABLE {$table}");
                 } catch (PAException $e) {
                     if ($e->getCode() != DB_QUERY_FAILED) {
                         throw $e;
                     }
                     $bits = preg_split("/(\\s+|,)/", $query);
                     $pos = array_search($table, $bits);
                     if ($pos === NULL) {
                         throw new PAException(GENERAL_SOME_ERROR, "Failed to find real name for table {$table} in query {$sql}");
                     }
                     $table = strtolower($bits[$pos - 1]) == 'as' ? $bits[$pos - 2] : $bits[$pos - 1];
                     $create_table = Dal::query_one("SHOW CREATE TABLE {$table}");
                 }
                 echo $create_table[1] . "\n";
             }
             print "================================================================== }}}\n";
         }
         $result->endTest($this);
         return $result;
     }
 }
Ejemplo n.º 13
0
 /**
  * Runs a test and collects its result in a TestResult instance.
  *
  * @param PHPUnit_Framework_TestResult $result
  *
  * @return PHPUnit_Framework_TestResult
  */
 public function run(PHPUnit_Framework_TestResult $result = null)
 {
     $sections = $this->parse();
     $code = $this->render($sections['FILE']);
     if ($result === null) {
         $result = new PHPUnit_Framework_TestResult();
     }
     $skip = false;
     $xfail = false;
     $time = 0;
     $settings = $this->settings;
     $result->startTest($this);
     if (isset($sections['INI'])) {
         $settings = array_merge($settings, $this->parseIniSection($sections['INI']));
     }
     if (isset($sections['ENV'])) {
         $env = $this->parseEnvSection($sections['ENV']);
         $this->phpUtil->setEnv($env);
     }
     // Redirects STDERR to STDOUT
     $this->phpUtil->setUseStderrRedirection(true);
     if ($result->enforcesTimeLimit()) {
         $this->phpUtil->setTimeout($result->getTimeoutForLargeTests());
     }
     if (isset($sections['SKIPIF'])) {
         $jobResult = $this->phpUtil->runJob($sections['SKIPIF'], $settings);
         if (!strncasecmp('skip', ltrim($jobResult['stdout']), 4)) {
             if (preg_match('/^\\s*skip\\s*(.+)\\s*/i', $jobResult['stdout'], $message)) {
                 $message = substr($message[1], 2);
             } else {
                 $message = '';
             }
             $result->addFailure($this, new PHPUnit_Framework_SkippedTestError($message), 0);
             $skip = true;
         }
     }
     if (isset($sections['XFAIL'])) {
         $xfail = trim($sections['XFAIL']);
     }
     if (!$skip) {
         if (isset($sections['STDIN'])) {
             $this->phpUtil->setStdin($sections['STDIN']);
         }
         if (isset($sections['ARGS'])) {
             $this->phpUtil->setArgs($sections['ARGS']);
         }
         PHP_Timer::start();
         $jobResult = $this->phpUtil->runJob($code, $settings);
         $time = PHP_Timer::stop();
         try {
             $this->assertPhptExpectation($sections, $jobResult['stdout']);
         } catch (PHPUnit_Framework_AssertionFailedError $e) {
             if ($xfail !== false) {
                 $result->addFailure($this, new PHPUnit_Framework_IncompleteTestError($xfail, 0, $e), $time);
             } else {
                 $result->addFailure($this, $e, $time);
             }
         } catch (Throwable $t) {
             $result->addError($this, $t, $time);
         }
         if ($result->allCompletelyImplemented() && $xfail !== false) {
             $result->addFailure($this, new PHPUnit_Framework_IncompleteTestError('XFAIL section but test passes'), $time);
         }
         $this->phpUtil->setStdin('');
         $this->phpUtil->setArgs('');
         if (isset($sections['CLEAN'])) {
             $cleanCode = $this->render($sections['CLEAN']);
             $this->phpUtil->runJob($cleanCode, $this->settings);
         }
     }
     $result->endTest($this, $time);
     return $result;
 }
Ejemplo n.º 14
0
 public function run(PHPUnit_Framework_TestResult $result = NULL)
 {
     PHPUnit_Framework_Assert::resetCount();
     if ($result === NULL) {
         $result = new PHPUnit_Framework_TestResult();
     }
     $t = MediaWikiParserTestSuite::$iter->current();
     $k = MediaWikiParserTestSuite::$iter->key();
     if (!MediaWikiParserTestSuite::$iter->valid()) {
         return;
     }
     // The only way this should happen is if the parserTest.txt
     // file were modified while the script is running.
     if ($k != $this->number) {
         $i = $this->number;
         wfDie("I got confused!\n");
     }
     $result->startTest($this);
     PHPUnit_Util_Timer::start();
     $r = false;
     try {
         $r = MediaWikiParserTestSuite::$parser->runTest($t['test'], $t['input'], $t['result'], $t['options'], $t['config']);
         PHPUnit_Framework_Assert::assertTrue(true, $t['test']);
     } catch (PHPUnit_Framework_AssertionFailedError $e) {
         $result->addFailure($this, $e, PHPUnit_Util_Timer::stop());
     } catch (Exception $e) {
         $result->addError($this, $e, PHPUnit_Util_Timer::stop());
     }
     PHPUnit_Framework_Assert::assertTrue(true, $t['test']);
     $result->endTest($this, PHPUnit_Util_Timer::stop());
     MediaWikiParserTestSuite::$parser->recorder->record($t['test'], $r);
     MediaWikiParserTestSuite::$iter->next();
     $this->addToAssertionCount(PHPUnit_Framework_Assert::getCount());
     return $result;
 }
Ejemplo n.º 15
0
    /**
     * Runs a single job (PHP code) using a separate PHP process.
     *
     * @param  string                       $job
     * @param  PHPUnit_Framework_TestCase   $test
     * @param  PHPUnit_Framework_TestResult $result
     * @return array|null
     */
    public static function runJob($job, PHPUnit_Framework_Test $test = NULL, PHPUnit_Framework_TestResult $result = NULL)
    {
        $process = proc_open(
          self::getPhpBinary(), self::$descriptorSpec, $pipes
        );

        // Workaround for http://bugs.php.net/bug.php?id=52911
        if (DIRECTORY_SEPARATOR == '\\') {
            sleep(2);
        }

        if (is_resource($process)) {
            if ($result !== NULL) {
                $result->startTest($test);
            }

            fwrite($pipes[0], $job);
            fclose($pipes[0]);

            $stdout = stream_get_contents($pipes[1]);
            fclose($pipes[1]);

            $stderr = stream_get_contents($pipes[2]);
            fclose($pipes[2]);

            proc_close($process);

            if ($result !== NULL) {
                self::processChildResult($test, $result, $stdout, $stderr);
            } else {
                return array('stdout' => $stdout, 'stderr' => $stderr);
            }
        }
    }
Ejemplo n.º 16
0
 /**
  * Runs a test and collects its result in a TestResult instance.
  *
  * @param  PHPUnit_Framework_TestResult $result
  * @return PHPUnit_Framework_TestResult
  */
 public function run(PHPUnit_Framework_TestResult $result = null)
 {
     $sections = $this->parse();
     $code = $this->render($sections['FILE']);
     if ($result === null) {
         $result = new PHPUnit_Framework_TestResult();
     }
     $skip = false;
     $time = 0;
     $settings = $this->settings;
     $result->startTest($this);
     if (isset($sections['INI'])) {
         $settings = array_merge($settings, $this->parseIniSection($sections['INI']));
     }
     // Redirects STDERR to STDOUT
     $this->phpUtil->setUseStderrRedirection(true);
     if (isset($sections['SKIPIF'])) {
         $jobResult = $this->phpUtil->runJob($sections['SKIPIF'], $settings);
         if (!strncasecmp('skip', ltrim($jobResult['stdout']), 4)) {
             if (preg_match('/^\\s*skip\\s*(.+)\\s*/i', $jobResult['stdout'], $message)) {
                 $message = substr($message[1], 2);
             } else {
                 $message = '';
             }
             $result->addFailure($this, new PHPUnit_Framework_SkippedTestError($message), 0);
             $skip = true;
         }
     }
     if (!$skip) {
         PHP_Timer::start();
         $jobResult = $this->phpUtil->runJob($code, $settings);
         $time = PHP_Timer::stop();
         try {
             $this->assertPhptExpectation($sections, $jobResult['stdout']);
         } catch (PHPUnit_Framework_AssertionFailedError $e) {
             $result->addFailure($this, $e, $time);
         } catch (Throwable $t) {
             $result->addError($this, $t, $time);
         } catch (Exception $e) {
             $result->addError($this, $e, $time);
         }
         if (isset($sections['CLEAN'])) {
             $cleanCode = $this->render($sections['CLEAN']);
             $this->phpUtil->runJob($cleanCode, $this->settings);
         }
     }
     $result->endTest($this, $time);
     return $result;
 }
Ejemplo n.º 17
0
 /**
  * Runs a test and collects its result in a TestResult instance.
  *
  * @param  PHPUnit_Framework_TestResult $result
  * @param  array                        $options
  * @return PHPUnit_Framework_TestResult
  */
 public function run(PHPUnit_Framework_TestResult $result = NULL, array $options = array())
 {
     if (!class_exists('PEAR_RunTest', FALSE)) {
         throw new PHPUnit_Framework_Exception('Class PEAR_RunTest not found.');
     }
     if (isset($GLOBALS['_PEAR_destructor_object_list']) && is_array($GLOBALS['_PEAR_destructor_object_list']) && !empty($GLOBALS['_PEAR_destructor_object_list'])) {
         $pearDestructorObjectListCount = count($GLOBALS['_PEAR_destructor_object_list']);
     } else {
         $pearDestructorObjectListCount = 0;
     }
     if ($result === NULL) {
         $result = new PHPUnit_Framework_TestResult();
     }
     $coverage = $result->getCollectCodeCoverageInformation();
     $options = array_merge($options, $this->options);
     if (!isset($options['include_path'])) {
         $options['include_path'] = get_include_path();
     }
     if ($coverage) {
         $options['coverage'] = TRUE;
     } else {
         $options['coverage'] = FALSE;
     }
     $currentErrorReporting = error_reporting(E_ERROR | E_WARNING | E_PARSE);
     $runner = new PEAR_RunTest(new PHPUnit_Extensions_PhptTestCase_Logger(), $options);
     if ($coverage) {
         $runner->xdebug_loaded = TRUE;
     } else {
         $runner->xdebug_loaded = FALSE;
     }
     $result->startTest($this);
     PHP_Timer::start();
     $buffer = $runner->run($this->filename, $options);
     $time = PHP_Timer::stop();
     error_reporting($currentErrorReporting);
     $base = basename($this->filename);
     $path = dirname($this->filename);
     $coverageFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.xdebug', $base);
     $diffFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.diff', $base);
     $expFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.exp', $base);
     $logFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.log', $base);
     $outFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.out', $base);
     $phpFile = $path . DIRECTORY_SEPARATOR . str_replace('.phpt', '.php', $base);
     if (is_object($buffer) && $buffer instanceof PEAR_Error) {
         $result->addError($this, new PHPUnit_Framework_Exception($buffer->getMessage()), $time);
     } else {
         if ($buffer == 'SKIPPED') {
             $result->addFailure($this, new PHPUnit_Framework_SkippedTestError(), 0);
         } else {
             if ($buffer != 'PASSED') {
                 $expContent = file_get_contents($expFile);
                 $outContent = file_get_contents($outFile);
                 $result->addFailure($this, new PHPUnit_Framework_ComparisonFailure($expContent, $outContent, $expContent, $outContent), $time);
             }
         }
     }
     foreach (array($diffFile, $expFile, $logFile, $phpFile, $outFile) as $file) {
         if (file_exists($file)) {
             unlink($file);
         }
     }
     if ($coverage && file_exists($coverageFile)) {
         eval('$coverageData = ' . file_get_contents($coverageFile) . ';');
         unset($coverageData[$phpFile]);
         $result->getCodeCoverage()->append($coverageData, $this);
         unlink($coverageFile);
     }
     $result->endTest($this, $time);
     // Do not invoke PEAR's destructor mechanism for PHP 4
     // as it raises an E_STRICT.
     if ($pearDestructorObjectListCount == 0) {
         unset($GLOBALS['_PEAR_destructor_object_list']);
     } else {
         $count = count($GLOBALS['_PEAR_destructor_object_list']) - $pearDestructorObjectListCount;
         for ($i = 0; $i < $count; $i++) {
             array_pop($GLOBALS['_PEAR_destructor_object_list']);
         }
     }
     return $result;
 }
Ejemplo n.º 18
0
 /**
  * Runs a single job (PHP code) using a separate PHP process.
  *
  * @param  string                       $job
  * @param  PHPUnit_Framework_TestCase   $test
  * @param  PHPUnit_Framework_TestResult $result
  * @return array|null
  */
 public static function runJob($job, PHPUnit_Framework_Test $test = NULL, PHPUnit_Framework_TestResult $result = NULL)
 {
     $process = proc_open(self::getPhpBinary(), self::$descriptorSpec, $pipes);
     if (is_resource($process)) {
         if ($result !== NULL) {
             $result->startTest($test);
         }
         fwrite($pipes[0], $job);
         fclose($pipes[0]);
         $stdout = stream_get_contents($pipes[1]);
         fclose($pipes[1]);
         $stderr = stream_get_contents($pipes[2]);
         fclose($pipes[2]);
         proc_close($process);
         if ($result !== NULL) {
             self::processChildResult($test, $result, $stdout, $stderr);
         } else {
             return array('stdout' => $stdout, 'stderr' => $stderr);
         }
     }
 }