getCodeCoverage() 공개 메소드

Returns the code coverage object.
public getCodeCoverage ( ) : SebastianBergmann\CodeCoverage\CodeCoverage
리턴 SebastianBergmann\CodeCoverage\CodeCoverage
 public function endTestRun()
 {
     $coverage = $this->result->getCodeCoverage();
     if (!empty($coverage)) {
         $clover = new PHP_CodeCoverage_Report_Clover();
         $contents = $clover->process($coverage);
         if ($this->out) {
             $this->out->write($contents);
             $this->out->close();
         }
     }
     parent::endTestRun();
 }
예제 #2
0
 /**
  * Renders the summary of test passes and failures.
  *
  * @param PHPUnit_Framework_TestResult $result Result object
  *
  * @return void
  */
 public function paintFooter($result)
 {
     ob_end_flush();
     echo '</ul>';
     if ($result->failureCount() + $result->errorCount() > 0) {
         echo '<div class="alert-box alert radius">';
     } else {
         echo '<div class="alert-box success radius">';
     }
     echo $result->count() - $result->skippedCount() . ' of ';
     echo $result->count() . ' test methods complete: ';
     echo count($result->passed()) . ' passes, ';
     echo $result->failureCount() . ' fails, ';
     echo $this->numAssertions . ' assertions and ';
     echo $result->errorCount() . ' exceptions.';
     echo '</div>';
     echo '<p><strong>Time:</strong> ' . __('%0.5f seconds', $result->time()) . '</p>';
     echo '<p><strong>Peak Memory:</strong> ' . number_format(memory_get_peak_usage()) . ' bytes</p>';
     $this->_paintLinks();
     if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) {
         $coverage = $result->getCodeCoverage();
         if (method_exists($coverage, 'getSummary')) {
             $report = $coverage->getSummary();
             $this->paintCoverage($report);
         }
         if (method_exists($coverage, 'getData')) {
             $report = $coverage->getData();
             $this->paintCoverage($report);
         }
     }
     $this->paintDocumentEnd();
 }
 public function endTestRun()
 {
     $coverage = $this->result->getCodeCoverage();
     if (!empty($coverage)) {
         if (class_exists('PHP_CodeCoverage_Report_Crap4j')) {
             $crap = new PHP_CodeCoverage_Report_Crap4j();
         } elseif (class_exists('\\SebastianBergmann\\CodeCoverage\\Report\\Crap4j')) {
             $crapClass = '\\SebastianBergmann\\CodeCoverage\\Report\\Crap4j';
             $crap = new $crapClass();
         }
         $contents = $crap->process($coverage);
         if ($this->out) {
             $this->out->write($contents);
             $this->out->close();
         }
     }
     parent::endTestRun();
 }
예제 #4
0
 /**
  * Makes the processChildResult inherited method public.
  *
  * @param \PHPUnit_Framework_Test $test
  * @param \PHPUnit_Framework_TestResult $result
  * @param string $stdout
  * @param string $stderr
  * @return void
  */
 public 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'])) {
                 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();
             $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)) {
                 foreach ($errors as $error) {
                     $result->addError($test, $this->getException($error), $time);
                 }
             } elseif (!empty($failures)) {
                 foreach ($failures as $failure) {
                     $result->addFailure($test, $this->getException($failure), $time);
                 }
             }
         }
     }
     $result->endTest($test, $time);
 }
 public function endTestRun()
 {
     if (version_compare($this->version, '3.5.0') >= 0) {
         require_once 'PHP/CodeCoverage/Report/Clover.php';
         $coverage = $this->result->getCodeCoverage();
         $clover = new PHP_CodeCoverage_Report_Clover();
         $contents = $clover->process($coverage);
     } else {
         require_once 'PHPUnit/Util/Log/CodeCoverage/XML/Clover.php';
         $clover = new PHPUnit_Util_Log_CodeCoverage_XML_Clover(null);
         ob_start();
         $clover->process($this->result);
         $contents = ob_get_contents();
         ob_end_clean();
     }
     if ($this->out) {
         $this->out->write($contents);
         $this->out->close();
     }
     parent::endTestRun();
 }
예제 #6
0
 /**
  * Paints the end of the test with a summary of
  * the passes and failures.
  *
  * @param PHPUnit_Framework_TestResult $result Result object
  * @return void
  */
 public function paintFooter($result)
 {
     if ($result->failureCount() + $result->errorCount()) {
         echo "FAILURES!!!\n";
     } else {
         echo "\nOK\n";
     }
     echo "Test cases run: " . $result->count() . "/" . ($result->count() - $result->skippedCount()) . ', Passes: ' . $this->numAssertions . ', Failures: ' . $result->failureCount() . ', Exceptions: ' . $result->errorCount() . "\n";
     echo 'Time: ' . $result->time() . " seconds\n";
     echo 'Peak memory: ' . number_format(memory_get_peak_usage()) . " bytes\n";
     if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) {
         $coverage = $result->getCodeCoverage()->getSummary();
         echo $this->paintCoverage($coverage);
     }
 }
 /**
  * Runs the tests and collects their result in a TestResult.
  *
  * @param  PHPUnit_Framework_TestResult $result
  * @param  mixed                        $filter
  * @param  array                        $groups
  * @param  array                        $excludeGroups
  * @param  boolean                      $processIsolation
  * @return PHPUnit_Framework_TestResult
  * @throws InvalidArgumentException
  */
 public function run(PHPUnit_Framework_TestResult $result = NULL, $filter = FALSE, array $groups = array(), array $excludeGroups = array(), $processIsolation = FALSE)
 {
     // Get the code coverage filter from the suite's result object
     $coverage = $result->getCodeCoverage();
     if ($coverage) {
         $coverage_filter = $coverage->filter();
         // Apply the white and blacklisting
         foreach ($this->_filter_calls as $method => $args) {
             foreach ($args as $arg) {
                 $coverage_filter->{$method}($arg);
             }
         }
     }
     return parent::run($result, $filter, $groups, $excludeGroups, $processIsolation);
 }
예제 #8
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);
 }
예제 #9
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;
 }
예제 #10
0
 /**
  * Paints the end of the test with a summary of
  * the passes and failures.
  *
  * @param PHPUnit_Framework_TestResult $result Result object
  * @return void
  */
 public function paintFooter($result)
 {
     if (ob_get_contents()) {
         ob_end_flush();
     }
     $colour = $result->failureCount() + $result->errorCount() > 0 ? "red" : "green";
     echo "</ul>\n";
     echo "<div style=\"";
     echo "padding: 8px; margin: 1em 0; background-color: {$colour}; color: white;";
     echo "\">";
     echo $result->count() - $result->skippedCount() . "/" . $result->count();
     echo " test methods complete:\n";
     echo "<strong>" . count($result->passed()) . "</strong> passes, ";
     echo "<strong>" . $result->failureCount() . "</strong> fails, ";
     echo "<strong>" . $this->numAssertions . "</strong> assertions and ";
     echo "<strong>" . $result->errorCount() . "</strong> exceptions.";
     echo "</div>\n";
     echo '<div style="padding:0 0 5px;">';
     echo '<p><strong>Time:</strong> ' . $result->time() . ' seconds</p>';
     echo '<p><strong>Peak memory:</strong> ' . number_format(memory_get_peak_usage()) . ' bytes</p>';
     echo $this->_paintLinks();
     echo '</div>';
     if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) {
         $coverage = $result->getCodeCoverage();
         if (method_exists($coverage, 'getSummary')) {
             $report = $coverage->getSummary();
             echo $this->paintCoverage($report);
         }
         if (method_exists($coverage, 'getData')) {
             $report = $coverage->getData();
             echo $this->paintCoverage($report);
         }
     }
     $this->paintDocumentEnd();
 }
예제 #11
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);
 }