Автор: Sebastian Bergmann (sebastian@phpunit.de)
Наследование: implements Countable
Пример #1
0
 /**
  * Parse the test suite result
  *
  * @param \PHPUnit_Framework_TestResult $result
  * @return array<string,double|integer|array>
  */
 private function parseTestSuite($result)
 {
     $passed = 0;
     $error = 0;
     $failed = 0;
     $notImplemented = 0;
     $skipped = 0;
     $tests = [];
     foreach ($result->passed() as $key => $value) {
         $tests[] = $this->parseTest('passed', $key);
         $passed++;
     }
     foreach ($result->failures() as $obj) {
         $tests[] = $this->parseTest('failed', $obj);
         $failed++;
     }
     foreach ($result->skipped() as $obj) {
         $tests[] = $this->parseTest('skipped', $obj);
         $skipped++;
     }
     foreach ($result->notImplemented() as $obj) {
         $tests[] = $this->parseTest('notImplemented', $obj);
         $notImplemented++;
     }
     foreach ($result->errors() as $obj) {
         $tests[] = $this->parseTest('error', $obj);
         $error++;
     }
     usort($tests, function ($a, $b) {
         return strnatcmp($a['class'], $b['class']);
     });
     return ['time' => $result->time(), 'total' => count($tests), 'passed' => $passed, 'error' => $error, 'failed' => $failed, 'notImplemented' => $notImplemented, 'skipped' => $skipped, 'tests' => $tests];
 }
Пример #2
0
 /**
  * @param  PHPUnit_Framework_TestResult $result
  */
 public function process(PHPUnit_Framework_TestResult $result, $minLines = 5, $minMatches = 70)
 {
     $codeCoverage = $result->getCodeCoverageInformation();
     $summary = PHPUnit_Util_CodeCoverage::getSummary($codeCoverage);
     $files = array_keys($summary);
     $metrics = new PHPUnit_Util_Metrics_Project($files, $summary, TRUE, $minLines, $minMatches);
     $document = new DOMDocument('1.0', 'UTF-8');
     $document->formatOutput = TRUE;
     $cpd = $document->createElement('pmd-cpd');
     $cpd->setAttribute('version', 'PHPUnit ' . PHPUnit_Runner_Version::id());
     $document->appendChild($cpd);
     foreach ($metrics->getDuplicates() as $duplicate) {
         $xmlDuplication = $cpd->appendChild($document->createElement('duplication'));
         $xmlDuplication->setAttribute('lines', $duplicate['numLines']);
         $xmlDuplication->setAttribute('tokens', $duplicate['numTokens']);
         $xmlFile = $xmlDuplication->appendChild($document->createElement('file'));
         $xmlFile->setAttribute('path', $duplicate['fileA']->getPath());
         $xmlFile->setAttribute('line', $duplicate['firstLineA']);
         $xmlFile = $xmlDuplication->appendChild($document->createElement('file'));
         $xmlFile->setAttribute('path', $duplicate['fileB']->getPath());
         $xmlFile->setAttribute('line', $duplicate['firstLineB']);
         $xmlDuplication->appendChild($document->createElement('codefragment', PHPUnit_Util_XML::prepareString(join('', array_slice($duplicate['fileA']->getLines(), $duplicate['firstLineA'] - 1, $duplicate['numLines'])))));
     }
     $this->write($document->saveXML());
     $this->flush();
 }
 /**
  * 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)
 {
     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();
 }
 public function run(PHPUnit_Framework_TestResult $result = null)
 {
     $result->startTest($this);
     $this->testCase->runBare();
     $this->testCase->runBare();
     $result->endTest($this, 0);
 }
Пример #5
0
 public function bindToResult(\PHPUnit_Framework_TestResult $result)
 {
     if ($this->result !== $result) {
         $this->result = $result;
         $result->addListener($this);
     }
 }
Пример #6
0
/**
 * Create the test result and splice on our code coverage reports.
 *
 * @return PHPUnit_Framework_TestResult
 */
	protected function createTestResult() {
		$result = new PHPUnit_Framework_TestResult;
		if (isset($this->_params['codeCoverage'])) {
			$result->collectCodeCoverageInformation(true);
		}
		return $result;
    }
 public function executeRun()
 {
     set_time_limit(0);
     $buffer = tempnam(sys_get_temp_dir(), 'phpunit');
     $listener = new PHPUnit_Util_Log_JSON($buffer);
     $testResult = new PHPUnit_Framework_TestResult();
     $testResult->addListener($listener);
     $path = str_replace('-', '/', $this->getRequestParameter('test'));
     $loader = new sfPhpunitProjectTestLoader($path);
     $loader->load();
     $loader->suite()->run($testResult);
     $result = '[' . str_replace('}{', '},{', file_get_contents($buffer)) . ']';
     $tests = array();
     foreach (json_decode($result) as $test) {
         if ('suiteStart' == $test->event) {
             continue;
         }
         if (!isset($tests[$test->suite])) {
             $tests[$test->suite]['methods'] = array();
             $tests[$test->suite]['status'] = 'pass';
         }
         $tests[$test->suite]['methods'][] = $test;
         if ('pass' != $test->status) {
             $tests[$test->suite]['status'] = 'fail';
         }
     }
     $this->result = $testResult;
     $this->tests = $tests;
     $this->path = $path;
 }
Пример #8
0
 /**
  * @param  \PHPUnit_Framework_TestResult $result
  */
 public function printResult(\PHPUnit_Framework_TestResult $result)
 {
     if (!$this->silent) {
         $this->printHeader($result->time());
         if ($result->errorCount() > 0) {
             $this->printErrors($result);
         }
         if ($result->failureCount() > 0) {
             if ($result->errorCount() > 0) {
                 print "\n--\n\n";
             }
             $this->printFailures($result);
         }
         if ($result->notImplementedCount() > 0) {
             if ($result->failureCount() > 0) {
                 print "\n--\n\n";
             }
             $this->printIncompletes($result);
         }
         if ($result->skippedCount() > 0) {
             if ($result->notImplementedCount() > 0) {
                 print "\n--\n\n";
             }
             $this->printSkipped($result);
         }
     }
     $this->printFooter($result);
 }
Пример #9
0
 public function testAccessTestsAreSkippedWhenNoAclIsGiven()
 {
     $suite = new PHPUnit_Framework_TestSuite();
     $suite->addTestSuite('AccessNavigationTestWithNoAcl');
     $suite->run($result = new PHPUnit_Framework_TestResult());
     $this->assertEquals(1, $result->skippedCount());
 }
Пример #10
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;
 }
Пример #11
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;
 }
Пример #12
0
 /**
  * Launches a test module for web inspection of results
  * @param string $module
  * @return boolean
  */
 function WebLauncher($module)
 {
     jf::$ErrorHandler->UnsetErrorHandler();
     $this->LoadFramework();
     self::$TestSuite = new \PHPUnit_Framework_TestSuite();
     self::$TestFiles[] = $this->ModuleFile($module);
     self::$TestSuite->addTestFile(self::$TestFiles[0]);
     $result = new \PHPUnit_Framework_TestResult();
     $listener = new TestListener();
     $result->addListener($listener);
     $Profiler = new Profiler();
     if (function_exists("xdebug_start_code_coverage")) {
         xdebug_start_code_coverage();
     }
     self::$TestSuite->run($result);
     if (function_exists("xdebug_start_code_coverage")) {
         $Coverage = xdebug_get_code_coverage();
     } else {
         $Coverage = null;
     }
     $Profiler->Stop();
     $listener->Finish();
     $this->OutputResult($result, $Profiler, $Coverage);
     return true;
 }
Пример #13
0
 public function testAclIsTested()
 {
     $suite = new PHPUnit_Framework_TestSuite();
     $suite->addTestSuite('FooAclTest');
     $suite->run($result = new PHPUnit_Framework_TestResult());
     $this->assertTrue($result->wasSuccessful(), 'Test should be run successfully');
     $this->assertEquals(2, $result->count());
 }
Пример #14
0
 public function doEnhancedRun(\PHPUnit_Framework_Test $suite, \PHPUnit_Framework_TestResult $result, array $arguments = array())
 {
     $this->handleConfiguration($arguments);
     if (is_integer($arguments['repeat'])) {
         $suite = new \PHPUnit_Extensions_RepeatedTest($suite, $arguments['repeat'], $arguments['filter'], $arguments['groups'], $arguments['excludeGroups'], $arguments['processIsolation']);
     }
     if (!$arguments['convertErrorsToExceptions']) {
         $result->convertErrorsToExceptions(FALSE);
     }
     if (!$arguments['convertNoticesToExceptions']) {
         \PHPUnit_Framework_Error_Notice::$enabled = FALSE;
     }
     if (!$arguments['convertWarningsToExceptions']) {
         \PHPUnit_Framework_Error_Warning::$enabled = FALSE;
     }
     if ($arguments['stopOnError']) {
         $result->stopOnError(TRUE);
     }
     if ($arguments['stopOnFailure']) {
         $result->stopOnFailure(TRUE);
     }
     if ($arguments['stopOnIncomplete']) {
         $result->stopOnIncomplete(TRUE);
     }
     if ($arguments['stopOnSkipped']) {
         $result->stopOnSkipped(TRUE);
     }
     if ($this->printer === NULL) {
         if (isset($arguments['printer']) && $arguments['printer'] instanceof \PHPUnit_Util_Printer) {
             $this->printer = $arguments['printer'];
         } else {
             $this->printer = new \Codeception\PHPUnit\ResultPrinter\UI(NULL, $arguments['verbose'], $arguments['colors'], $arguments['debug']);
         }
     }
     if (isset($arguments['report'])) {
         if ($arguments['report']) {
             $this->printer = new \Codeception\PHPUnit\ResultPrinter\Report();
         }
     }
     if (isset($arguments['html'])) {
         if ($arguments['html']) {
             $arguments['listeners'][] = new \Codeception\PHPUnit\ResultPrinter\HTML($arguments['html']);
         }
     }
     $arguments['listeners'][] = $this->printer;
     // clean up listeners between suites
     foreach ($arguments['listeners'] as $listener) {
         $result->removeListener($listener);
         $result->addListener($listener);
     }
     if ($arguments['strict']) {
         $result->strictMode(TRUE);
     }
     $suite->run($result, $arguments['filter'], $arguments['groups'], $arguments['excludeGroups'], $arguments['processIsolation']);
     unset($suite);
     $result->flushListeners();
     return $result;
 }
 /**
  * @covers PHPUnit_Framework_TestResult
  */
 public function testEndEventsAreCounted()
 {
     $this->result = new PHPUnit_Framework_TestResult();
     $listener = new BaseTestListenerSample();
     $this->result->addListener($listener);
     $test = new Success();
     $test->run($this->result);
     $this->assertEquals(1, $listener->endCount);
 }
Пример #16
0
 /**
  * @param  PHPUnit_Framework_TestResult  $result
  * @access protected
  */
 protected function printFooter(PHPUnit_Framework_TestResult $result)
 {
     if ($result->wasSuccessful() && $result->allCompletlyImplemented() && $result->noneSkipped()) {
         $this->write("\n" . ($result = sprintf("OK (%d test%s, %d assertion%s)", count($result), count($result) == 1 ? '' : 's', $this->numAssertions, $this->numAssertions == 1 ? '' : 's')) . str_repeat(' ', 80 - strlen($result)) . "\n");
     } elseif ((!$result->allCompletlyImplemented() || !$result->noneSkipped()) && $result->wasSuccessful()) {
         $this->write("\nOk, but incomplete or skipped tests!                                            \n" . sprintf("Tests: %d, Assertions: %d%s%s.\n", count($result), $this->numAssertions, $this->getCountString($result->notImplementedCount(), 'Incomplete'), $this->getCountString($result->skippedCount(), 'Skipped')));
     } else {
         $this->write(sprintf("\nFailures                                                                        \n" . "Tests: %d, Assertions: %s%s%s%s.\n", count($result), $this->numAssertions, $this->getCountString($result->failureCount(), 'Failures'), $this->getCountString($result->errorCount(), 'Errors'), $this->getCountString($result->notImplementedCount(), 'Incomplete'), $this->getCountString($result->skippedCount(), 'Skipped')));
     }
 }
Пример #17
0
 /**
  * Creates a new Code Coverage information tree.
  *
  * @param  PHPUnit_Framework_TestResult            $result
  * @param  PHPUnit_Util_Report_Test_Node_TestSuite $testSuite
  * @return PHPUnit_Util_Report_Coverage_Node_Directory
  * @access public
  * @static
  */
 public static function create(PHPUnit_Framework_TestResult $result, PHPUnit_Util_Report_Test_Node_TestSuite $testSuite)
 {
     $codeCoverageInformation = $result->getCodeCoverageInformation();
     $files = PHPUnit_Util_CodeCoverage::getSummary($codeCoverageInformation);
     $commonPath = self::reducePaths($files);
     $items = self::buildDirectoryStructure($files);
     $root = new PHPUnit_Util_Report_Coverage_Node_Directory($commonPath);
     self::addItems($root, $items, $testSuite, $files);
     return $root;
 }
Пример #18
0
 protected function run_tests($tests, &$listener)
 {
     $suite = new PHPUnit_Framework_TestSuite('default');
     foreach ($tests as $case) {
         $suite->addTestSuite($case);
     }
     #return PHPUnit::run($suite);
     $result = new PHPUnit_Framework_TestResult();
     $result->addListener($listener);
     return $suite->run($result);
 }
Пример #19
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;
     }
 }
Пример #20
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;
 }
Пример #21
0
 protected function assertTestsAreSuccessful(PHPUnit_Framework_TestResult $result)
 {
     if ($result->wasSuccessful()) {
         return;
     }
     $msg = "Test should pass, instead there are {$result->errorCount()} errors:\n";
     /** @var $error PHPUnit_Framework_TestFailure */
     foreach ($result->errors() as $error) {
         $msg .= $error->exceptionMessage();
     }
     $this->fail($msg);
 }
 /**
  * Renders the report.
  *
  * @param  PHPUnit_Framework_TestResult $result
  * @param  string                       $target
  * @param  string                       $charset
  * @param  boolean                      $yui
  * @param  boolean                      $highlight
  * @param  integer                      $lowUpperBound
  * @param  integer                      $highLowerBound
  * @access public
  * @static
  */
 public static function render(PHPUnit_Framework_TestResult $result, $target, $charset = 'ISO-8859-1', $yui = TRUE, $highlight = FALSE, $lowUpperBound = 35, $highLowerBound = 70)
 {
     self::$templatePath = sprintf('%s%sReport%sTemplate%s', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR);
     $codeCoverageInformation = $result->getCodeCoverageInformation();
     $files = PHPUnit_Util_CodeCoverage::getSummary($codeCoverageInformation);
     $commonPath = self::reducePaths($files);
     $items = self::buildDirectoryStructure($files);
     $root = new PHPUnit_Util_Report_Node_Directory($commonPath, NULL);
     self::addItems($root, $items, $files, $yui, $highlight);
     self::copyFiles($target);
     $root->render($target, $result->topTestSuite()->getName(), $charset, $highlight, $lowUpperBound, $highLowerBound);
 }
 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();
 }
Пример #24
0
 /**
  * Runs a test suite.
  *
  * @param           PHPUnit_Framework_Test $suite
  * @param  optional boolean                $wait
  * @return PHPUnit_Framework_TestResult
  * @access public
  */
 public function doRun(PHPUnit_Framework_Test $suite, $wait = false)
 {
     printf("PHPUnit %s by Sebastian Bergmann.\n\n", PHPUnit_Framework_Version);
     $result = new PHPUnit_Framework_TestResult();
     $result->addListener($this->fPrinter);
     $timer = new Benchmark_Timer();
     $timer->start();
     $suite->run($result);
     $timer->stop();
     $this->pause($wait);
     $this->fPrinter->printResult($result, $timer->timeElapsed());
     return $result;
 }
Пример #25
0
    /**
     * Main function - runs the tests and outputs HTML code
     *
     * @return void
     * @author Robert Lemke <*****@*****.**>
     * @author Karsten Dambekalns <*****@*****.**>
     * @internal Preliminary solution - there surely will be nicer ways to implement a test runner
     */
    public function run()
    {
        $this->renderPageHeader();
        $this->renderTestForm();
        if (!empty($this->packageKey)) {
            $testcaseFileNamesAndPaths = $this->getTestcaseFilenames();
            if (count($testcaseFileNamesAndPaths) > 0) {
                $this->renderInfoAndProgressbar();
                $this->requireTestCaseFiles($testcaseFileNamesAndPaths);
                $testListener = new \F3\Testing\TestListener();
                $testListener->baseUri = $this->request->getBaseUri();
                $testResult = new \PHPUnit_Framework_TestResult();
                $testResult->addListener($testListener);
                $testResult->collectCodeCoverageInformation($this->collectCodeCoverage);
                $startTime = microtime(TRUE);
                foreach (get_declared_classes() as $className) {
                    if (substr($className, -4, 4) == 'Test') {
                        $class = new \ReflectionClass($className);
                        if ($class->isSubclassOf('PHPUnit_Framework_TestCase') && substr($className, 0, 8) !== 'PHPUnit_') {
                            $testSuite = new \PHPUnit_Framework_TestSuite($class);
                            $testSuite->run($testResult);
                        }
                    }
                }
                $endTime = microtime(TRUE);
                // Display test statistics:
                if ($testResult->wasSuccessful()) {
                    echo '<script type="text/javascript">document.getElementById("progress-bar").style.backgroundColor = "green";document.getElementById("progress-bar").style.backgroundImage = "none";</script>
						<h1 class="success">SUCCESS</h1>
						' . $testResult->count() . ' tests, ' . $testResult->failureCount() . ' failures, ' . $testResult->errorCount() . ' errors.
						</h1>';
                } else {
                    echo '
						<script>document.getElementById("progress-bar").style.backgroundColor = "red";document.getElementById("progress-bar").style.backgroundImage = "none";</script>
						<h1 class="failure">FAILURE</h1>
						' . $testResult->count() . ' tests, ' . $testResult->failureCount() . ' failures, ' . $testResult->errorCount() . ' errors.
					';
                }
                echo '<p>Peak memory usage was: ~' . floor(memory_get_peak_usage() / 1024 / 1024) . ' MByte.<br />';
                echo 'Test run took ' . round($endTime - $startTime, 4) . ' seconds.</p>';
                if ($this->collectCodeCoverage === TRUE) {
                    \F3\FLOW3\Utility\Files::emptyDirectoryRecursively($this->coverageOutputPath);
                    \PHPUnit_Util_Report::render($testResult, $this->coverageOutputPath);
                    echo '<a href="_Resources/CodeCoverageReport/index.html">See code coverage report...</a>';
                }
            } else {
                echo '<p>No testcase found. Did you specify the intended pattern?</p>';
            }
        }
        $this->renderPageFooter();
    }
Пример #26
0
 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;
 }
Пример #27
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() == 0) {
         echo "\nOK\n";
     } else {
         echo "FAILURES!!!\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->getCodeCoverageInformation();
         echo $this->paintCoverage($coverage);
     }
 }
 public function testThatAfterSuiteRespectsRemoteFalseSetting()
 {
     $reflection = new ReflectionClass('Codeception\\Subscriber\\RemoteCodeCoverage');
     $settingsProperty = $reflection->getProperty('settings');
     $settingsProperty->setAccessible(true);
     /** @var $codeCoverageMock \Codeception\Subscriber\RemoteCodeCoverage|PHPUnit_Framework_MockObject_MockObject */
     $codeCoverageMock = $this->getMockBuilder('Codeception\\Subscriber\\RemoteCodeCoverage')->disableOriginalConstructor()->setMethods(array('getRemoteConnectionModule'))->getMock();
     $settingsProperty->setValue($codeCoverageMock, array('enabled' => true, 'remote' => false));
     /** @var $testSuite PHPUnit_Framework_TestSuite|PHPUnit_Framework_MockObject_MockObject */
     $testSuite = $this->getMock('PHPUnit_Framework_TestSuite', array(), array(), '', false);
     $testResult = new PHPUnit_Framework_TestResult();
     $testResult->setCodeCoverage(new \PHP_CodeCoverage());
     $suiteEvent = new Suite($testSuite, $testResult);
     $codeCoverageMock->beforeSuite($suiteEvent);
 }
 /**
  * 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);
 }
Пример #30
0
 private function _run_tests($classes, $classname = '')
 {
     $suite = new PHPUnit_Framework_TestSuite();
     // Turn off BackUpGlobal until https://github.com/sebastianbergmann/phpunit/issues/451 is fixed
     $suite->setBackupGlobals(false);
     foreach ($classes as $testcase) {
         if (!$classname or strtolower($testcase) === strtolower($classname)) {
             $suite->addTestSuite($testcase);
         }
     }
     $result = new PHPUnit_Framework_TestResult();
     require_once 'PHPUnit/TextUI/ResultPrinter.php';
     $this->printer = new WPUnitCommandResultsPrinter();
     $result->addListener($this->printer);
     return array($suite->run($result), $this->printer);
 }