addListener() 공개 메소드

Registers a TestListener.
public addListener ( PHPUnit_Framework_TestListener $listener )
$listener PHPUnit_Framework_TestListener
 /**
  * @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);
 }
예제 #2
0
 public function bindToResult(\PHPUnit_Framework_TestResult $result)
 {
     if ($this->result !== $result) {
         $this->result = $result;
         $result->addListener($this);
     }
 }
 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;
 }
예제 #4
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;
 }
예제 #5
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;
 }
예제 #6
0
파일: runner.php 프로젝트: laiello/ko3
 /**
  * Constructor
  *
  * @param PHPUnit_Framework_TestSuite $suite    The suite to test
  * @param PHPUnit_Framework_TestResult $result  Optional result object to use
  */
 function __construct(PHPUnit_Framework_TestSuite $suite, PHPUnit_Framework_TestResult $result = NULL)
 {
     if ($result === NULL) {
         $result = new PHPUnit_Framework_TestResult();
     }
     $result->addListener($this);
     $this->suite = $suite;
     $this->result = $result;
 }
예제 #7
0
 /**
  * Run a test
  */
 public function run(PHPUnit_Framework_TestSuite $suite)
 {
     $res = new PHPUnit_Framework_TestResult();
     if ($this->codecoverage) {
         $res->collectCodeCoverageInformation(TRUE);
     }
     $res->addListener($this);
     foreach ($this->formatters as $formatter) {
         $res->addListener($formatter);
     }
     /* Set PHPUnit error handler */
     if ($this->useCustomErrorHandler) {
         $oldErrorHandler = set_error_handler(array('PHPUnitTestRunner', 'handleError'), E_ALL | E_STRICT);
     }
     $suite->run($res, false, $this->groups, $this->excludeGroups);
     foreach ($this->formatters as $formatter) {
         $formatter->processResult($res);
     }
     /* Restore Phing error handler */
     if ($this->useCustomErrorHandler) {
         restore_error_handler();
     }
     if ($this->codecoverage) {
         $coverageInformation = $res->getCodeCoverageInformation();
         PHPUnit_Util_CodeCoverage::clearSummary();
         $summary = PHPUnit_Util_CodeCoverage::getSummary($coverageInformation);
         CoverageMerger::merge($this->project, $summary);
     }
     if ($res->errorCount() != 0) {
         $this->retCode = self::ERRORS;
     } else {
         if ($res->failureCount() != 0) {
             $this->retCode = self::FAILURES;
         } else {
             if ($res->notImplementedCount() != 0) {
                 $this->retCode = self::INCOMPLETES;
             } else {
                 if ($res->skippedCount() != 0) {
                     $this->retCode = self::SKIPPED;
                 }
             }
         }
     }
 }
예제 #8
0
파일: Runner.php 프로젝트: rmccue/Gorilla
 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);
 }
예제 #9
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;
 }
예제 #10
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();
    }
예제 #11
0
 /**
  * Run a test
  */
 function run($test)
 {
     $res = new PHPUnit_Framework_TestResult();
     if ($this->codecoverage) {
         $res->collectCodeCoverageInformation(TRUE);
     }
     $res->addListener($this);
     foreach ($this->formatters as $formatter) {
         $res->addListener($formatter);
     }
     /* Set PHPUnit error handler */
     $oldErrorHandler = set_error_handler(array('PHPUnitTestRunner', 'handleError'), E_ALL | E_STRICT);
     $test->run($res, false, $this->groups, $this->excludeGroups);
     /* Restore Phing error handler */
     restore_error_handler();
     if ($this->codecoverage) {
         $coverageInformation = $res->getCodeCoverageInformation();
         foreach ($coverageInformation as $coverage_info) {
             CoverageMerger::merge($this->project, array($coverage_info['files']));
         }
     }
     if ($res->errorCount() != 0) {
         $this->retCode = self::ERRORS;
     } else {
         if ($res->failureCount() != 0) {
             $this->retCode = self::FAILURES;
         } else {
             if ($res->notImplementedCount() != 0) {
                 $this->retCode = self::INCOMPLETES;
             } else {
                 if ($res->skippedCount() != 0) {
                     $this->retCode = self::SKIPPED;
                 }
             }
         }
     }
 }
예제 #12
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);
 }
 /**
  * Create the test result and splice on our code coverage reports.
  *
  * @return PHPUnit_Framework_TestResult
  */
 protected function createTestResult()
 {
     $result = new PHPUnit_Framework_TestResult();
     $FixtureInjector = new FixtureInjector($this->_getFixtureManager(array()));
     $result->addListener($FixtureInjector);
     if (!empty($this->_params['codeCoverage'])) {
         if (method_exists($result, 'collectCodeCoverageInformation')) {
             $result->collectCodeCoverageInformation(true);
         }
         if (method_exists($result, 'setCodeCoverage')) {
             $Filter = new PHP_CodeCoverage_Filter();
             $Filter->addFileToBlacklist('systemlib.php');
             $result->setCodeCoverage(new PHP_CodeCoverage(null, $Filter));
         }
     }
     return $result;
 }
예제 #14
0
 public function run($name = null)
 {
     $tests = array();
     if (!isset($name)) {
         $tests = $this->testCases;
     } elseif (is_array($name)) {
         // run specified tests
     } elseif (is_string($name)) {
         // run test
         $tests[] = $name;
     }
     foreach ($tests as $name => $mixed) {
         if (is_numeric($name)) {
             $name = $mixed;
         }
         $name = strtolower($name);
         $path = $this->testCases[$name];
         require_once $path;
     }
     $testClasses = array();
     foreach (get_declared_classes() as $class) {
         if (stristr($class, 'Test') !== false && strpos($class, 'PHPUnit_') === false) {
             $testClasses[] = $class;
         }
     }
     $suite = new PHPUnit_Framework_TestSuite();
     foreach ($testClasses as $class) {
         if ($this->suite) {
             if (strcasecmp($this->suite, $class) == 0) {
                 $suite->addTestSuite($class);
             }
         } else {
             $suite->addTestSuite($class);
         }
     }
     $result = new PHPUnit_Framework_TestResult();
     require_once 'PHPUnit/Util/Log/JSON.php';
     $result->addListener(new PHPUnit_Util_Log_JSON());
     $this->suite = $suite;
     ob_start();
     $suite->run($result);
     $results = ob_get_contents();
     ob_end_clean();
     return $results;
 }
 /**
  * Run a test
  */
 public function run(PHPUnit_Framework_TestSuite $suite)
 {
     $res = new PHPUnit_Framework_TestResult();
     if ($this->codecoverage) {
         $whitelist = CoverageMerger::getWhiteList($this->project);
         $this->codecoverage->filter()->addFilesToWhiteList($whitelist);
         $res->setCodeCoverage($this->codecoverage);
     }
     $res->addListener($this);
     foreach ($this->formatters as $formatter) {
         $res->addListener($formatter);
     }
     /* Set PHPUnit error handler */
     if ($this->useCustomErrorHandler) {
         $oldErrorHandler = set_error_handler(array($this, 'handleError'), E_ALL | E_STRICT);
     }
     $suite->run($res, false, $this->groups, $this->excludeGroups, $this->processIsolation);
     foreach ($this->formatters as $formatter) {
         $formatter->processResult($res);
     }
     /* Restore Phing error handler */
     if ($this->useCustomErrorHandler) {
         restore_error_handler();
     }
     if ($this->codecoverage) {
         CoverageMerger::merge($this->project, $this->codecoverage->getData());
     }
     if ($res->errorCount() != 0) {
         $this->retCode = self::ERRORS;
     } else {
         if ($res->failureCount() != 0) {
             $this->retCode = self::FAILURES;
         } else {
             if ($res->notImplementedCount() != 0) {
                 $this->retCode = self::INCOMPLETES;
             } else {
                 if ($res->skippedCount() != 0) {
                     $this->retCode = self::SKIPPED;
                 }
             }
         }
     }
 }
예제 #16
0
파일: run.php 프로젝트: jo-m/ecamp3
 private static function runTest(PHPUnit_Framework_TestSuite $test, $arguments)
 {
     $test->setName('eCamp UnitTests');
     global $doConvertErrorToExceptions;
     $doConvertErrorToExceptions = true;
     // Create a xml listener object
     $listener = new PHPUnit_Util_Log_JUnit();
     // Create TestResult object and pass the xml listener to it
     $testResult = new PHPUnit_Framework_TestResult();
     $testResult->addListener($listener);
     $arguments['printer'] = new SilentTestListener();
     $runner = new PHPUnit_TextUI_TestRunner();
     $runner->doRun($test, $arguments);
     // Run the TestSuite
     $result = $test->run($testResult);
     // Get the results from the listener
     $xml_result = $listener->getXML();
     return $xml_result;
     $doConvertErrorToExceptions = false;
 }
예제 #17
0
 /**
  * @param \PHPUnit_Framework_TestResult $result
  * @param array $arguments
  * @return array
  */
 protected function applyReporters(\PHPUnit_Framework_TestResult $result, array $arguments)
 {
     foreach ($this->defaultListeners as $listener => $value) {
         if (!isset($arguments[$listener])) {
             $arguments[$listener] = $value;
         }
     }
     if ($arguments['html']) {
         self::$persistentListeners[] = new HTML($this->log_dir . 'report.html');
     }
     if ($arguments['xml']) {
         self::$persistentListeners[] = new JUnit($this->log_dir . 'report.xml', false);
     }
     if ($arguments['tap']) {
         self::$persistentListeners[] = new \PHPUnit_Util_Log_TAP($this->log_dir . 'report.tap.log');
     }
     if ($arguments['json']) {
         self::$persistentListeners[] = new \PHPUnit_Util_Log_JSON($this->log_dir . 'report.json');
     }
     foreach (self::$persistentListeners as $listener) {
         $result->addListener($listener);
     }
 }
 /**
  * Initializes and runs the tests
  *
  * @param string $packageKey Package to test
  * @param string $testcaseClassName Testcase to run (all if not given)
  * @param string $outputPath Path to put the output XML files to
  * @return void
  * @author Sebastian Kurfürst <*****@*****.**>
  * @author Karsten Dambekalns <*****@*****.**>
  * @internal Preliminary solution - there surely will be nicer ways to implement a test runner
  */
 public function run()
 {
     $testResult = new \PHPUnit_Framework_TestResult();
     $testResult->addListener(new \PHPUnit_Util_Log_JUnit($this->testOutputPath . '/logfile.xml'));
     $testResult->collectCodeCoverageInformation($this->collectCodeCoverage);
     $testcaseFileNamesAndPaths = $this->getTestcaseFilenames();
     if (count($testcaseFileNamesAndPaths) > 0) {
         $this->requireTestCaseFiles($testcaseFileNamesAndPaths);
         $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);
         $testResult->flushListeners();
         // Display test statistics:
         if ($testResult->wasSuccessful()) {
             echo 'SUCCESS' . PHP_EOL . $testResult->count() . ' tests, ' . $testResult->failureCount() . ' failures, ' . $testResult->errorCount() . ' errors.' . PHP_EOL;
         } else {
             echo 'FAILURE' . PHP_EOL . $testResult->count() . ' tests, ' . $testResult->failureCount() . ' failures, ' . $testResult->errorCount() . ' errors.' . PHP_EOL;
         }
         echo 'Peak memory usage was: ~' . floor(memory_get_peak_usage() / 1024 / 1024) . ' MByte.' . PHP_EOL;
         echo 'Test run took ' . round($endTime - $startTime, 4) . ' seconds.' . PHP_EOL;
         if ($this->collectCodeCoverage === TRUE) {
             $report = new \PHPUnit_Util_Log_CodeCoverage_XML_Clover($this->coverageOutputPath . '/clover.xml');
             $report->process($testResult);
         }
     } else {
         echo 'No testcase found. Did you specify the intended pattern?' . PHP_EOL;
     }
 }
예제 #19
0
 /**
  * @param array $classList
  * @param boolean $coverage
  */
 function runTests($classList, $coverage = false)
 {
     $startTime = microtime(true);
     // XDEBUG seem to cause problems with test execution :-(
     if (function_exists('xdebug_disable')) {
         xdebug_disable();
     }
     ini_set('max_execution_time', 0);
     $this->setUp();
     // Optionally skip certain tests
     $skipTests = array();
     if ($this->request->getVar('SkipTests')) {
         $skipTests = explode(',', $this->request->getVar('SkipTests'));
     }
     $classList = array_diff($classList, $skipTests);
     // run tests before outputting anything to the client
     $suite = new PHPUnit_Framework_TestSuite();
     natcasesort($classList);
     foreach ($classList as $className) {
         // Ensure that the autoloader pulls in the test class, as PHPUnit won't know how to do this.
         class_exists($className);
         $suite->addTest(new SapphireTestSuite($className));
     }
     // Remove the error handler so that PHPUnit can add its own
     restore_error_handler();
     /*, array("reportDirectory" => "/Users/sminnee/phpunit-report")*/
     if (Director::is_cli()) {
         $reporter = new CliTestReporter();
     } else {
         $reporter = new SapphireTestReporter();
     }
     self::$default_reporter->writeHeader("Sapphire Test Runner");
     if (count($classList) > 1) {
         self::$default_reporter->writeInfo("All Tests", "Running test cases: ", implode(", ", $classList));
     } else {
         self::$default_reporter->writeInfo($classList[0], "");
     }
     $results = new PHPUnit_Framework_TestResult();
     $results->addListener($reporter);
     if ($coverage === true) {
         foreach (self::$coverage_filter_dirs as $dir) {
             PHPUnit_Util_Filter::addDirectoryToFilter(BASE_PATH . '/' . $dir);
         }
         $results->collectCodeCoverageInformation(true);
         $suite->run($results);
         if (!file_exists(ASSETS_PATH . '/coverage-report')) {
             mkdir(ASSETS_PATH . '/coverage-report');
         }
         PHPUnit_Util_Report::render($results, ASSETS_PATH . '/coverage-report/');
         $coverageApp = ASSETS_PATH . '/coverage-report/' . preg_replace('/[^A-Za-z0-9]/', '_', preg_replace('/(\\/$)|(^\\/)/', '', Director::baseFolder())) . '.html';
         $coverageTemplates = ASSETS_PATH . '/coverage-report/' . preg_replace('/[^A-Za-z0-9]/', '_', preg_replace('/(\\/$)|(^\\/)/', '', realpath(TEMP_FOLDER))) . '.html';
         echo "<p>Coverage reports available here:<ul>\n\t\t\t\t<li><a href=\"{$coverageApp}\">Coverage report of the application</a></li>\n\t\t\t\t<li><a href=\"{$coverageTemplates}\">Coverage report of the templates</a></li>\n\t\t\t</ul>";
     } else {
         $suite->run($results);
     }
     if (!Director::is_cli()) {
         echo '<div class="trace">';
     }
     $reporter->writeResults();
     $endTime = microtime(true);
     if (Director::is_cli()) {
         echo "\n\nTotal time: " . round($endTime - $startTime, 3) . " seconds\n";
     } else {
         echo "<p>Total time: " . round($endTime - $startTime, 3) . " seconds</p>\n";
     }
     if (!Director::is_cli()) {
         echo '</div>';
     }
     // Put the error handlers back
     Debug::loadErrorHandlers();
     if (!Director::is_cli()) {
         self::$default_reporter->writeFooter();
     }
     $this->tearDown();
     // Todo: we should figure out how to pass this data back through Director more cleanly
     if (Director::is_cli() && $results->failureCount() + $results->errorCount() > 0) {
         exit(2);
     }
 }
예제 #20
0
파일: Runner.php 프로젝트: pfz/codeception
 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']);
     }
     $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 (empty(self::$persistentListeners)) {
         foreach ($this->defaultListeners as $listener => $value) {
             if (!isset($arguments[$listener])) {
                 $arguments[$listener] = $value;
             }
         }
         if ($arguments['html']) {
             self::$persistentListeners[] = new \Codeception\PHPUnit\ResultPrinter\HTML(\Codeception\Configuration::logDir() . 'report.html');
         }
         if ($arguments['xml']) {
             self::$persistentListeners[] = new \Codeception\PHPUnit\Log\JUnit(\Codeception\Configuration::logDir() . 'report.xml', false);
         }
         if ($arguments['tap']) {
             self::$persistentListeners[] = new \PHPUnit_Util_Log_TAP(\Codeception\Configuration::logDir() . 'report.tap.log');
         }
         if ($arguments['json']) {
             self::$persistentListeners[] = new \PHPUnit_Util_Log_JSON(\Codeception\Configuration::logDir() . 'report.json');
         }
         foreach (self::$persistentListeners as $listener) {
             $result->addListener($listener);
         }
     }
     $arguments['listeners'][] = $this->printer;
     // clean up listeners between suites
     foreach ($arguments['listeners'] as $listener) {
         $result->addListener($listener);
     }
     if ($arguments['strict']) {
         $result->strictMode(TRUE);
     }
     $suite->run($result, $arguments['filter'], $arguments['groups'], $arguments['excludeGroups'], $arguments['processIsolation']);
     unset($suite);
     foreach ($arguments['listeners'] as $listener) {
         $result->removeListener($listener);
     }
     return $result;
 }
예제 #21
0
 /**
  * Attaches to the given test result, if not yet attached.
  *
  * @param PHPUnit_Framework_Test $result the result to attach to.
  */
 public function attach(PHPUnit_Framework_TestResult $result)
 {
     if (!$this->attached && $this->filename) {
         $this->attached = true;
         $result->addListener($this);
     }
 }
예제 #22
0
 * install you're using to run these tests.
 *
 * Note: if you encounter errors and/or failures when
 * running tests, you should try fixing errors first. They're
 * usually easier to tackle and might resolve failures.
 */
require_once 'lib/cli-load.php';
require_once 'PHPUnit/Autoload.php';
require_once 'PHPUnit/Util/ErrorHandler.php';
// All tests
$tests = array();
// Printer object will eventually print results
$printer = new PHPUnit_TextUI_ResultPrinter(NULL, true, !stristr(PHP_OS, 'WIN'));
// Results object tracks results for all tests
$result = new PHPUnit_Framework_TestResult();
$result->addListener($printer);
// Test core MTV functions
require_once 'test_core.php';
$tests['MTVCoreTest'] = new PHPUnit_Framework_TestSuite('MTVCoreTest');
// Test MTV's http lib
require_once 'test_http.php';
$tests['MTVHttpTest'] = new PHPUnit_Framework_TestSuite('MTVHttpTest');
// Test Model model
require_once 'test_model.php';
$tests['MTVModelTest'] = new PHPUnit_Framework_TestSuite('MTVModelTest');
// Test Collection model
require_once 'test_collection.php';
$tests['MTVCollectionTest'] = new PHPUnit_Framework_TestSuite('MTVCollectionTest');
// TODO:
// Test Post model
// Stub
예제 #23
0
function runTests($tree, $branches)
{
    $pid = pcntl_fork();
    if ($pid != 0) {
        pcntl_waitpid($pid, $status);
        $failures = file_get_contents(PROJECT_PATH . '/tmp/.autotest');
        return intval($failures);
    }
    /*
     * Prepare the database...
     */
    require _path(CORE_PATH, 'database.php');
    $db = Zend_Db_Table_Abstract::getDefaultAdapter();
    foreach (QFrame_Db_Table::getTables() as $table) {
        $db->getConnection()->exec("TRUNCATE TABLE {$table}");
    }
    if (is_array($branches)) {
        $tests = array();
        $suite_name = implode(' && ', $branches);
        foreach ($branches as $branch) {
            $tests = array_merge($tests, collectBranchTests($tree, $branch));
        }
        $tests = array_unique($tests);
        if (count($tests) <= 0) {
            return;
        }
    } elseif ($branches == 'all') {
        $suite_name = 'all';
        $tests = collectAllTests($tree);
    }
    $suite = new PHPUnit_Framework_TestSuite($suite_name);
    foreach ($tests as $test) {
        require_once TEST_PATH . '/unit/' . $test;
        $class_name = preg_replace('/\\.php$/', '', $test);
        $suite_name = preg_replace('/^' . preg_quote(PROJECT_PATH . '/', '/') . '|\\.php$/', '', 'IGNORE');
        $suite->addTestSuite(new PHPUnit_Framework_TestSuite('Test_Unit_' . $class_name, $suite_name));
    }
    $result = new PHPUnit_Framework_TestResult();
    $result->addListener(new QFrame_Test_Listener());
    $suite->run($result);
    file_put_contents(PROJECT_PATH . '/tmp/.autotest', count($result->failures()));
    exit;
}
예제 #24
0
 /**
  * override TestResult
  */
 protected function createTestResult()
 {
     $result = new PHPUnit_Framework_TestResult();
     if (YTestOptions::$progress || YTestOptions::$immediateFeedback) {
         if (YTestOptions::$immediateFeedback) {
             echo "z_tests_runner: immediate feedback on failure/error enabled\n";
         } else {
             if (YTestOptions::$progress) {
                 echo "z_tests_runner: progress info enabled\n";
             }
         }
         $result->addListener(new YTestProgressTestListener());
     }
     if (YTestOptions::$perfs) {
         echo "z_tests_runner: performance info enabled\n";
         $result->addListener(new YTestPerfListener());
     }
     if (YTestOptions::$leaks) {
         echo "z_tests_runner: leaks enabled\n";
         $result->addListener(new YTestListener());
     }
     return $result;
 }
예제 #25
0
   /**
    *  Runs supplied tests through PHPUnit.
    *
    *  @param array $tests        The directories/filenames containing the tests to be run through PHPUnit.
    *  @access public
    *  @return array
    */
    public function run($tests) {
        $suite = new PHPUnit_Framework_TestSuite();

        $tests = $this->_parse_tests($tests); 
        $original_classes = get_declared_classes();
        $test_filenames = array();
        foreach ( $tests as $test ) {
            require $test;
            $test_filenames[] = basename($test, '.php');
        }
        $new_classes = get_declared_classes();
        $tests = array_diff($new_classes, $original_classes);
        foreach ( $tests as $test ) {
            if ( in_array($this->_classname_only($test), $test_filenames) ) {
                $suite->addTestSuite($test);
            }
        }

        $result = new PHPUnit_Framework_TestResult;
        $result->addListener(new PHPUnit_Util_Log_JSON);
        
        // We need to temporarily turn off html_errors to ensure correct parsing of test debug output
	$html_errors = ini_get("html_errors");

        ob_start();
        ini_set("html_errors", 0);
        $suite->run($result);
        $results = ob_get_contents();
        ini_set("html_errors", $html_errors);
        ob_end_clean();
        
        return $this->_compile_suites($results);
    }
예제 #26
0
 protected function runTests($seleniumTestSuites = array())
 {
     $result = new PHPUnit_Framework_TestResult();
     $result->addListener(new SeleniumTestListener($this->selenium->getLogger()));
     if ($this->selenium->getJUnitLogFile()) {
         $jUnitListener = new PHPUnit_Util_Log_JUnit($this->selenium->getJUnitLogFile(), true);
         $result->addListener($jUnitListener);
     }
     foreach ($seleniumTestSuites as $testSuiteName => $testSuiteFile) {
         require $testSuiteFile;
         $suite = new $testSuiteName();
         $suite->setName($testSuiteName);
         $suite->addTests();
         try {
             $suite->run($result);
         } catch (Testing_Selenium_Exception $e) {
             $suite->tearDown();
             throw new MWException($e->getMessage());
         }
     }
     if ($this->selenium->getJUnitLogFile()) {
         $jUnitListener->flush();
     }
 }
예제 #27
0
 protected function registerPHPUnitListeners()
 {
     $listener = new PHPUnit\Listener($this->dispatcher);
     $this->result->addListener($listener);
 }
예제 #28
0
파일: Test.php 프로젝트: rafeca/Spec-PHP
 /**
  * Runs this module
  *
  * @throws \Exception
  */
 public function run()
 {
     // Create a suite to add spec files
     $suite = new Spec\TestSuite();
     // For every argument given check what files it matches
     foreach ($this->result->args['files'] as $file) {
         if (is_file($file)) {
             $suite->addTestFile($file);
         } else {
             if (is_dir($file)) {
                 $this->searchForSpecs($suite, $file);
             } else {
                 $glob = basename($file);
                 $file = dirname($file);
                 $this->searchForSpecs($suite, $file, $glob);
             }
         }
     }
     // Check if we just want to list the available groups
     if (!empty($this->result->options['list_groups'])) {
         print "Available test group(s):\n";
         $groups = $suite->getGroups();
         sort($groups);
         foreach ($groups as $group) {
             print " - {$group}\n";
         }
         exit(0);
     }
     // Create a printer instance
     if ($this->result->options['story']) {
         $this->result->options['format'] = 'story';
     }
     // @todo Allow custom class names
     switch (strtolower($this->result->options['format'])) {
         case 'd':
         case 'dots':
             $formatter = '\\DrSlump\\Spec\\Cli\\ResultPrinter\\Dots';
             break;
         case 's':
         case 'story':
             $formatter = '\\DrSlump\\Spec\\Cli\\ResultPrinter\\Story';
             break;
         default:
             throw new \RuntimeException('Unknown format option');
     }
     $printer = new $formatter(NULL, (bool) $this->result->options['verbose'], (bool) $this->result->options['color'], (bool) $this->result->options['debug']);
     // Create a PHPUnit result manager
     $result = new \PHPUnit_Framework_TestResult();
     // Append our custom printer as a listener
     $result->addListener($printer);
     // Register beeping listener
     if ($this->result->options['beep']) {
         $result->addListener(new Spec\Cli\BeepListener());
     }
     // Configure filter
     $filter = false;
     if (!empty($this->result->options['filter'])) {
         // Escape delimiters in regular expression.
         $filter = '/(' . implode(')|(', $this->result->options['filter']) . ')/i';
     }
     // Configure groups
     $groups = array();
     if (!empty($this->result->options['groups'])) {
         foreach ($this->result->options['groups'] as $opt) {
             $groups = array_merge($groups, explode(',', $opt));
         }
         $groups = array_map('trim', $groups);
         $groups = array_filter($groups);
         $groups = array_unique($groups);
     }
     // Configure excluded groups
     $excluded = array();
     if (!empty($this->result->options['exclude_groups'])) {
         foreach ($this->result->options['exclude_groups'] as $opt) {
             $excluded = array_merge($excluded, explode(',', $opt));
         }
         $excluded = array_map('trim', $excluded);
         $excluded = array_filter($excluded);
         $excluded = array_unique($excluded);
     }
     try {
         // Run the suite
         $suite->run($result, $filter, $groups, $excluded, false);
     } catch (\Exception $e) {
         // Recursive function to flag all tests in a suite as failed
         $fail = function ($suite) use(&$result, &$fail, &$e) {
             foreach ($suite->tests() as $test) {
                 if ($test instanceof \PHPUnit_Framework_TestSuite) {
                     $fail($test);
                     continue;
                 }
                 // Only flag as failed the ones that haven't been run yet
                 if (NULL === $test->getStatus()) {
                     $result->addError($test, $e, 0);
                 }
             }
         };
         // Check starting at the current suite since it's the one that have failed
         $fail(Spec::suite());
     }
     unset($suite);
     $result->flushListeners();
     $printer->printResult($result);
 }
 /**
  * Run a test
  *
  * @param PHPUnit_Framework_TestSuite $suite
  */
 public function run(PHPUnit_Framework_TestSuite $suite)
 {
     $res = new PHPUnit_Framework_TestResult();
     if ($this->codecoverage) {
         $whitelist = CoverageMerger::getWhiteList($this->project);
         $this->codecoverage->filter()->addFilesToWhiteList($whitelist);
         $res->setCodeCoverage($this->codecoverage);
     }
     $res->addListener($this);
     foreach ($this->formatters as $formatter) {
         $res->addListener($formatter);
     }
     /* Set PHPUnit error handler */
     if ($this->useCustomErrorHandler) {
         $oldErrorHandler = set_error_handler(array($this, 'handleError'), E_ALL | E_STRICT);
     }
     $version = PHPUnit_Runner_Version::id();
     if (version_compare($version, '4.0.0') >= 0) {
         $this->injectFilters($suite);
         $suite->run($res);
     } else {
         $suite->run($res, false, $this->groups, $this->excludeGroups, $this->processIsolation);
     }
     foreach ($this->formatters as $formatter) {
         $formatter->processResult($res);
     }
     /* Restore Phing error handler */
     if ($this->useCustomErrorHandler) {
         restore_error_handler();
     }
     if ($this->codecoverage) {
         CoverageMerger::merge($this->project, $this->codecoverage->getData());
     }
     $this->checkResult($res);
 }
예제 #30
0
 /**
  * Runs supplied tests through PHPUnit.
  *
  * @param array $tests    The directories/filenames containing the tests
  *                        to be run through PHPUnit.
  * @access public
  * @return string
  */
 public function run_tests($tests)
 {
     $suite = new \PHPUnit_Framework_TestSuite();
     $tests = $this->_parse_tests($tests);
     $original_classes = get_declared_classes();
     foreach ($tests as $test) {
         require $test;
     }
     $new_classes = get_declared_classes();
     $tests = array_diff($new_classes, $original_classes);
     $parent_class = 'PHPUnit_Framework_TestCase';
     foreach ($tests as $test) {
         $classname = $this->_classname_only($test);
         if ($classname == $parent_class || !is_subclass_of($classname, $parent_class)) {
             continue;
         }
         $suite->addTestSuite($test);
     }
     $result = new \PHPUnit_Framework_TestResult();
     $result->addListener(new \PHPUnit_Util_Log_JSON());
     // We need to temporarily turn off html_errors to ensure correct
     // parsing of test debug output
     $html_errors = ini_get('html_errors');
     ini_set('html_errors', 0);
     ob_start();
     $suite->run($result);
     $results = ob_get_contents();
     ob_end_clean();
     ini_set('html_errors', $html_errors);
     return $results;
 }