addFailure() 공개 메소드

The passed in exception caused the failure.
public addFailure ( PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, float $time )
$test PHPUnit_Framework_Test
$e PHPUnit_Framework_AssertionFailedError
$time float
예제 #1
0
파일: Actor.php 프로젝트: codeception/base
 public function runStep(Step $step)
 {
     $result = null;
     $this->fire(Events::STEP_BEFORE, new StepEvent($this, $step));
     try {
         $result = $step->run($this->moduleContainer);
     } catch (ConditionalAssertionFailed $f) {
         $this->testResult->addFailure(clone $this, $f, $this->testResult->time());
     } catch (\Exception $e) {
         $this->fire(Events::STEP_AFTER, new StepEvent($this, $step));
         throw $e;
     }
     $this->fire(Events::STEP_AFTER, new StepEvent($this, $step));
     return $result;
 }
예제 #2
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;
 }
예제 #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;
 }
예제 #4
0
파일: Old.php 프로젝트: shabbyrobe/fulfil
 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;
 }
예제 #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;
 }
예제 #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;
 }
예제 #7
0
파일: PHP.php 프로젝트: qcodo/qcodo
 /**
  * Processes the TestResult object from an isolated process.
  *
  * @param PHPUnit_Framework_TestCase   $test
  * @param PHPUnit_Framework_TestResult $result
  * @param string                       $stdout
  * @param string                       $stderr
  * @since Method available since Release 3.5.0
  */
 protected function processChildResult(PHPUnit_Framework_Test $test, PHPUnit_Framework_TestResult $result, $stdout, $stderr)
 {
     if (!empty($stderr)) {
         $time = 0;
         $result->addError($test, new RuntimeException(trim($stderr)), $time);
     } else {
         $childResult = @unserialize($stdout);
         if ($childResult !== FALSE) {
             if (!empty($childResult['output'])) {
                 print $childResult['output'];
             }
             $test->setResult($childResult['testResult']);
             $test->addToAssertionCount($childResult['numAssertions']);
             $childResult = $childResult['result'];
             if ($result->getCollectCodeCoverageInformation()) {
                 $codeCoverageInformation = $childResult->getRawCodeCoverageInformation();
                 if (isset($codeCoverageInformation[0]) && is_array($codeCoverageInformation[0])) {
                     $result->getCodeCoverage()->append($codeCoverageInformation[0], $test);
                 }
             }
             $time = $childResult->time();
             $notImplemented = $childResult->notImplemented();
             $skipped = $childResult->skipped();
             $errors = $childResult->errors();
             $failures = $childResult->failures();
             if (!empty($notImplemented)) {
                 $result->addError($test, $notImplemented[0]->thrownException(), $time);
             } else {
                 if (!empty($skipped)) {
                     $result->addError($test, $skipped[0]->thrownException(), $time);
                 } else {
                     if (!empty($errors)) {
                         $result->addError($test, $errors[0]->thrownException(), $time);
                     } else {
                         if (!empty($failures)) {
                             $result->addFailure($test, $failures[0]->thrownException(), $time);
                         }
                     }
                 }
             }
         } else {
             $time = 0;
             $result->addError($test, new RuntimeException(trim($stdout)), $time);
         }
     }
     $result->endTest($test, $time);
 }
예제 #8
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;
 }
예제 #9
0
파일: PHP.php 프로젝트: samurailens/sop
 /**
  * Processes the TestResult object from an isolated process.
  *
  * @param PHPUnit_Framework_TestCase   $test
  * @param PHPUnit_Framework_TestResult $result
  * @param string                       $stdout
  * @param string                       $stderr
  * @since Method available since Release 3.5.0
  */
 protected function processChildResult(PHPUnit_Framework_Test $test, PHPUnit_Framework_TestResult $result, $stdout, $stderr)
 {
     $time = 0;
     if (!empty($stderr)) {
         $result->addError($test, new PHPUnit_Framework_Exception(trim($stderr)), $time);
     } else {
         set_error_handler(function ($errno, $errstr, $errfile, $errline) {
             throw new ErrorException($errstr, $errno, $errno, $errfile, $errline);
         });
         try {
             $childResult = unserialize($stdout);
             restore_error_handler();
         } catch (ErrorException $e) {
             restore_error_handler();
             $childResult = FALSE;
             $result->addError($test, new PHPUnit_Framework_Exception(trim($stdout), 0, $e), $time);
         }
         if ($childResult !== FALSE) {
             if (!empty($childResult['output'])) {
                 print $childResult['output'];
             }
             $test->setResult($childResult['testResult']);
             $test->addToAssertionCount($childResult['numAssertions']);
             $childResult = $childResult['result'];
             if ($result->getCollectCodeCoverageInformation()) {
                 $result->getCodeCoverage()->merge($childResult->getCodeCoverage());
             }
             $time = $childResult->time();
             $notImplemented = $childResult->notImplemented();
             $skipped = $childResult->skipped();
             $errors = $childResult->errors();
             $failures = $childResult->failures();
             if (!empty($notImplemented)) {
                 $result->addError($test, $this->getException($notImplemented[0]), $time);
             } else {
                 if (!empty($skipped)) {
                     $result->addError($test, $this->getException($skipped[0]), $time);
                 } else {
                     if (!empty($errors)) {
                         $result->addError($test, $this->getException($errors[0]), $time);
                     } else {
                         if (!empty($failures)) {
                             $result->addFailure($test, $this->getException($failures[0]), $time);
                         }
                     }
                 }
             }
         }
     }
     $result->endTest($test, $time);
 }
예제 #10
0
 /**
  * Processes the TestResult object from an isolated process.
  *
  * @param PHPUnit_Framework_Test $test        	
  * @param PHPUnit_Framework_TestResult $result        	
  * @param string $stdout        	
  * @param string $stderr        	
  * @since Method available since Release 3.5.0
  */
 private function processChildResult(PHPUnit_Framework_Test $test, PHPUnit_Framework_TestResult $result, $stdout, $stderr)
 {
     $time = 0;
     if (!empty($stderr)) {
         $result->addError($test, new PHPUnit_Framework_Exception(trim($stderr)), $time);
     } else {
         set_error_handler(function ($errno, $errstr, $errfile, $errline) {
             throw new ErrorException($errstr, $errno, $errno, $errfile, $errline);
         });
         try {
             if (strpos($stdout, "#!/usr/bin/env php\n") === 0) {
                 $stdout = substr($stdout, 19);
             }
             $childResult = unserialize(str_replace("#!/usr/bin/env php\n", '', $stdout));
             restore_error_handler();
         } catch (ErrorException $e) {
             restore_error_handler();
             $childResult = false;
             $result->addError($test, new PHPUnit_Framework_Exception(trim($stdout), 0, $e), $time);
         }
         if ($childResult !== false) {
             if (!empty($childResult['output'])) {
                 $output = $childResult['output'];
             }
             $test->setResult($childResult['testResult']);
             $test->addToAssertionCount($childResult['numAssertions']);
             $childResult = $childResult['result'];
             if ($result->getCollectCodeCoverageInformation()) {
                 $result->getCodeCoverage()->merge($childResult->getCodeCoverage());
             }
             $time = $childResult->time();
             $notImplemented = $childResult->notImplemented();
             $risky = $childResult->risky();
             $skipped = $childResult->skipped();
             $errors = $childResult->errors();
             $failures = $childResult->failures();
             if (!empty($notImplemented)) {
                 $result->addError($test, $this->getException($notImplemented[0]), $time);
             } elseif (!empty($risky)) {
                 $result->addError($test, $this->getException($risky[0]), $time);
             } elseif (!empty($skipped)) {
                 $result->addError($test, $this->getException($skipped[0]), $time);
             } elseif (!empty($errors)) {
                 $result->addError($test, $this->getException($errors[0]), $time);
             } elseif (!empty($failures)) {
                 $result->addFailure($test, $this->getException($failures[0]), $time);
             }
         }
     }
     $result->endTest($test, $time);
     if (!empty($output)) {
         print $output;
     }
 }
예제 #11
0
 function addFailure(&$test, &$t, $time = 0)
 {
     parent::addFailure($test, $t, $time);
     echo "F";
 }
 /**
  * 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;
 }
예제 #13
0
 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
 {
     if (!$this->_askForRetry($test, $e, $time)) {
         parent::addFailure($test, $e, $time);
     }
 }
 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;
     }
 }
예제 #15
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;
 }
예제 #16
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;
 }
예제 #17
0
 /**
  * Adds a failure to the list of failures.
  * The passed in exception caused the failure.
  *
  * @param \PHPUnit_Framework_Test                 $test
  * @param \PHPUnit_Framework_AssertionFailedError $e
  * @param float                                  $time
  */
 public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time)
 {
     parent::addFailure($test, new TestResultException($e), $time);
 }
예제 #18
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;
 }
    public function testAddFailureWithComparisonFailure()
    {
        /* @var \PHPUnit_Framework_TestCase $testCaseMock */
        $testCaseMock = $this->getMockForAbstractClass('\\PHPUnit_Framework_TestCase', array('testMethod'), 'TestCase');
        $test = $this->createTestMock('FailedTest');
        $expected = 'expected';
        $actual = 'actual';
        $expectedAsString = 'expectedAsString';
        $actualAsString = 'actualAsString';
        // PHPUnit versions <4.1 ComparisonFailure was part of phpunit
        if (class_exists('PHPUnit_Framework_ComparisonFailure')) {
            $comparisonFailure = new \PHPUnit_Framework_ComparisonFailure($expected, $actual, $expectedAsString, $actualAsString);
            // PHPUnit versions >=4.1 ComparisonFailure was moved to sebastianbergmann/comparator package
        } else {
            $comparisonFailure = new ComparisonFailure($expected, $actual, $expectedAsString, $actualAsString);
        }
        $exception = new \PHPUnit_Framework_ExpectationFailedException('ExpectationFailed', $comparisonFailure);
        $result = new \PHPUnit_Framework_TestResult();
        $result->addFailure($test, $exception, 2);
        $result->addFailure($test, $exception, 3);
        $testCaseMock->setTestResultObject($result);
        $time = 5;
        $this->listener->addFailure($testCaseMock, $exception, $time);
        $expectedOutputStart = <<<EOS
##teamcity[testFailed message='ExpectationFailed|n--- Expected|n+++ Actual|n@@ @@|n-expectedAsString|n+actualAsString' details=
EOS;
        $expectedOutputEnd = <<<EOS
 type='comparisonFailure' expected='expectedAsString' actual='actualAsString' name='testMethod' timestamp='2015-05-28T16:14:12.17+0700' flowId='24107']

EOS;
        $this->assertOutputStartsAndEndsWith($expectedOutputStart, $expectedOutputEnd);
    }