run() public method

Runs the tests and collects their result in a TestResult.
public run ( PHPUnit_Framework_TestResult $result = null ) : PHPUnit_Framework_TestResult
$result PHPUnit_Framework_TestResult
return PHPUnit_Framework_TestResult
Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 public function testAccessTestsAreSkippedWhenNoAclIsGiven()
 {
     $suite = new PHPUnit_Framework_TestSuite();
     $suite->addTestSuite('AccessNavigationTestWithNoAcl');
     $suite->run($result = new PHPUnit_Framework_TestResult());
     $this->assertEquals(1, $result->skippedCount());
 }
Ejemplo n.º 3
0
 /**
  * Runs the tests and collects their result in a TestResult.
  *
  * @param PHPUnit_Framework_TestResult $result A test result.
  * @param mixed                        $filter The filter passed to each test.
  *
  * @return PHPUnit_Framework_TestResult
  */
 public function run(PHPUnit_Framework_TestResult $result = null, $filter = false)
 {
     spl_autoload_register(array('PHP_CodeSniffer', 'autoload'));
     $result = parent::run($result, $filter);
     spl_autoload_unregister(array('PHP_CodeSniffer', 'autoload'));
     return $result;
 }
Ejemplo n.º 4
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());
 }
Ejemplo n.º 5
0
 public function testUnitTestLoadFixtures()
 {
     $db = Doctrine_Manager::connection();
     $db->exec('DROP TABLE IF EXISTS `foo`; CREATE TABLE `foo` (`a` VARCHAR, `b` VARCHAR);');
     $suite = new PHPUnit_Framework_TestSuite();
     $suite->addTestSuite('NotEmptyDoctrineDbTest');
     $suite->run($result = new PHPUnit_Framework_TestResult());
     $this->assertEquals(1, $result->count());
     $this->assertTestsAreSuccessful($result);
 }
Ejemplo n.º 6
0
 /**
  * Runs the test suite using the result specified in the constructor
  *
  * @param  array $groups       Optional array of groups to test
  * @param  bool  $collect_cc   Optional, Should code coverage be collected?
  * @return Kohana_PHPUnit      Instance of $this
  */
 public function run(array $groups = array(), $collect_cc = FALSE)
 {
     if ($collect_cc and !extension_loaded('xdebug')) {
         throw new Kohana_Exception('Code coverage cannot be collected because the xdebug extension is not loaded');
     }
     $this->result->collectCodeCoverageInformation((bool) $collect_cc);
     // Run the tests.
     $this->suite->run($this->result, FALSE, $groups);
     return $this;
 }
Ejemplo n.º 7
0
 public function testUnitTestLoadFixtures()
 {
     Zend_Db_Table_Abstract::setDefaultAdapter($db = new Zend_Db_Adapter_Pdo_Sqlite(array('dbname' => ":memory:")));
     $db->getConnection()->exec('DROP TABLE IF EXISTS `foo`; CREATE TABLE `foo` (`a` VARCHAR, `b` VARCHAR);');
     $suite = new PHPUnit_Framework_TestSuite();
     $suite->addTestSuite('NotEmptyZendDbTest');
     $suite->run($result = new PHPUnit_Framework_TestResult());
     $this->assertEquals(1, $result->count());
     $this->assertTestsAreSuccessful($result);
 }
Ejemplo n.º 8
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);
 }
 /**
  * {@inheritDoc}
  */
 public function run(PHPUnit_Framework_TestResult $result = null, $filter = false, array $groups = array(), array $excludeGroups = array(), $processIsolation = false)
 {
     parent::run($result, $filter, $groups, $excludeGroups, $processIsolation);
     $args = func_get_args();
     $factory = new File_Iterator_Factory();
     $iterator = $factory->getFileIterator($this->directories, $this->suffix, $this->prefix, $this->exclude_directories);
     foreach ($iterator as $item) {
         $this->createAndPerform($item->getRealPath(), 'run', $args);
     }
     foreach ($this->files as $file) {
         $this->createAndPerform($this->root_directory . '/' . $file, 'run', $args);
     }
 }
Ejemplo n.º 10
0
function main()
{
    function cleanup()
    {
        global $wpdb;
        // we need to ensure that we switch off this database
        $wpdb->select(null);
        // drop our test database
        // XXX: why cant we use $wpdb->query ?
        mysql_query(sprintf('DROP DATABASE `%s`', DISQUS_TEST_DATABASE)) or die(mysql_error());
    }
    global $wpdb;
    // $this->query(sprintf('DROP DATABASE IF EXISTS `%s`', DISQUS_TEST_DATABASE));
    // check existance of test db
    $exists = $wpdb->get_var($wpdb->prepare('SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = \'%s\'', DISQUS_TEST_DATABASE));
    if (!empty($exists)) {
        printf("Test database '%s' already exists. Continuing will drop this database and all data!\nContinue?  [y/n]\n", $exists);
        $handle = fopen("php://stdin", "r");
        $line = strtolower(trim(fgets($handle)));
        if ($line != 'yes' && $line != 'y') {
            echo "ABORTING!\n";
            exit;
        }
    }
    // setup database
    $wpdb->query(sprintf('CREATE DATABASE `%s`', DISQUS_TEST_DATABASE));
    $wpdb->select(DISQUS_TEST_DATABASE);
    // $fp = fopen('initial.sql', 'r');
    // $buffer = '';
    // while (($line = fgets($fp)) !== false) {
    //     $buffer .= trim($line);
    //     if (strpos($line, ';')) {
    //         if (!empty($buffer)) {
    //             $this->query($buffer);
    //         }
    //         $buffer = '';
    //     }
    // }
    //
    try {
        $suite = new PHPUnit_Framework_TestSuite('DisqusPluginTest');
        $result = $suite->run();
        require_once 'PHPUnit/TextUI/ResultPrinter.php';
        $printer = new PHPUnit_TextUI_ResultPrinter();
        $printer->printResult($result);
        cleanup();
    } catch (Exception $ex) {
        cleanup();
        throw $ex;
    }
}
Ejemplo n.º 11
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();
    }
 /**
  * Runs the tests and collects their result in a TestResult.
  *
  * @param PHPUnit_Framework_TestResult $result A test result.
  * @param mixed                        $filter The filter passed to each test.
  *
  * @return PHPUnit_Framework_TestResult
  */
 public function run(PHPUnit_Framework_TestResult $result = null, $filter = false)
 {
     $GLOBALS['PHP_CODESNIFFER_SNIFF_CODES'] = array();
     $GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES'] = array();
     spl_autoload_register(array('PHP_CodeSniffer', 'autoload'));
     $result = parent::run($result, $filter);
     spl_autoload_unregister(array('PHP_CodeSniffer', 'autoload'));
     $codes = count($GLOBALS['PHP_CODESNIFFER_SNIFF_CODES']);
     $fixes = count($GLOBALS['PHP_CODESNIFFER_FIXABLE_CODES']);
     $percent = round($fixes / $codes * 100, 2);
     echo PHP_EOL . PHP_EOL;
     echo "Tests generated {$codes} unique error codes; {$fixes} were fixable ({$percent}%)";
     return $result;
 }
 /**
  * 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);
 }
Ejemplo n.º 14
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);
 }
Ejemplo n.º 15
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;
 }
 /**
  * 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;
     }
 }
Ejemplo n.º 17
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);
    }
Ejemplo n.º 18
0
 /**
  * Overridden to form the default values for 'group' and 'excludeGroup' arguments.
  * Forms these lists based on incoming $groups, $excludeGroups, list of enabled modules and flag of including
  * non-module groups.
  *
  * @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)
 {
     // Keep original intent of a client, because list of groups can decrease after patterns processing
     $isIncludeGroups = !empty($groups);
     // Expand group patterns to real group names
     $groups = $this->_processPatterns($groups);
     $excludeGroups = $this->_processPatterns($excludeGroups);
     $groups = array_diff($groups, $excludeGroups);
     // Retrieve relevant and irrelevant groups
     $relevantGroups = $this->_getRelevantGroups();
     $irrelevantGroups = array_diff($this->getGroups(), $relevantGroups);
     // Modify $groups filter
     if ($isIncludeGroups) {
         $groups = array_diff($groups, $irrelevantGroups);
         if (empty($groups)) {
             // Empty groups means 'Run All', but there we want 'Run None'. So exclude tests via $excludeGroups.
             $excludeGroups = $this->getGroups();
         }
     } else {
         $groups = $relevantGroups;
     }
     // Exclude irrelevant groups. Otherwise tests, that depend both on enabled and disabled modules, will be run.
     $excludeGroups = array_merge($excludeGroups, $irrelevantGroups);
     $excludeGroups = array_unique($excludeGroups);
     return parent::run($result, $filter, $groups, $excludeGroups, $processIsolation);
 }
Ejemplo n.º 19
0
 /**
  * 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;
                 }
             }
         }
     }
 }
Ejemplo n.º 20
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) {
         $coverage = $res->getCodeCoverage();
         $summary = $coverage->getSummary();
         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;
                 }
             }
         }
     }
 }
Ejemplo n.º 21
0
 /**
  * @param  PHPUnit_Framework_Test $suite
  * @param  array                  $arguments
  * @return PHPUnit_Framework_TestResult
  */
 public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array())
 {
     $this->handleConfiguration($arguments);
     if (isset($arguments['bootstrap'])) {
         $GLOBALS['__PHPUNIT_BOOTSTRAP'] = $arguments['bootstrap'];
     }
     if ($arguments['backupGlobals'] === FALSE) {
         $suite->setBackupGlobals(FALSE);
     }
     if ($arguments['backupStaticAttributes'] === TRUE) {
         $suite->setBackupStaticAttributes(TRUE);
     }
     if (is_integer($arguments['repeat'])) {
         $test = new PHPUnit_Extensions_RepeatedTest($suite, $arguments['repeat'], $arguments['filter'], $arguments['groups'], $arguments['excludeGroups'], $arguments['processIsolation']);
         $suite = new PHPUnit_Framework_TestSuite();
         $suite->addTest($test);
     }
     $result = $this->createTestResult();
     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 PHPUnit_TextUI_ResultPrinter(NULL, $arguments['verbose'], $arguments['colors'], $arguments['debug']);
         }
     }
     if (!$this->printer instanceof PHPUnit_Util_Log_TAP) {
         $this->printer->write(PHPUnit_Runner_Version::getVersionString() . "\n\n");
         self::$versionStringPrinted = TRUE;
         if (isset($arguments['configuration'])) {
             $this->printer->write(sprintf("Configuration read from %s\n\n", $arguments['configuration']->getFilename()));
         }
     }
     foreach ($arguments['listeners'] as $listener) {
         $result->addListener($listener);
     }
     $result->addListener($this->printer);
     if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
         $result->addListener(new PHPUnit_Util_DeprecatedFeature_Logger());
     }
     if (isset($arguments['testdoxHTMLFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_HTML($arguments['testdoxHTMLFile']));
     }
     if (isset($arguments['testdoxTextFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_Text($arguments['testdoxTextFile']));
     }
     $codeCoverageReports = 0;
     if (extension_loaded('xdebug')) {
         if (isset($arguments['coverageClover'])) {
             $codeCoverageReports++;
         }
         if (isset($arguments['reportDirectory'])) {
             $codeCoverageReports++;
         }
         if (isset($arguments['coveragePHP'])) {
             $codeCoverageReports++;
         }
         if (isset($arguments['coverageText'])) {
             $codeCoverageReports++;
         }
     }
     if ($codeCoverageReports > 0) {
         $codeCoverage = new PHP_CodeCoverage(NULL, $this->codeCoverageFilter);
         $codeCoverage->setAddUncoveredFilesFromWhitelist($arguments['addUncoveredFilesFromWhitelist']);
         $codeCoverage->setProcessUncoveredFilesFromWhitelist($arguments['processUncoveredFilesFromWhitelist']);
         if (isset($arguments['forceCoversAnnotation'])) {
             $codeCoverage->setForceCoversAnnotation($arguments['forceCoversAnnotation']);
         }
         if (isset($arguments['mapTestClassNameToCoveredClassName'])) {
             $codeCoverage->setMapTestClassNameToCoveredClassName($arguments['mapTestClassNameToCoveredClassName']);
         }
         $result->setCodeCoverage($codeCoverage);
     }
     if ($codeCoverageReports > 1) {
         if (isset($arguments['cacheTokens'])) {
             $codeCoverage->setCacheTokens($arguments['cacheTokens']);
         }
     }
     if (isset($arguments['jsonLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JSON($arguments['jsonLogfile']));
     }
     if (isset($arguments['tapLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_TAP($arguments['tapLogfile']));
     }
     if (isset($arguments['junitLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JUnit($arguments['junitLogfile'], $arguments['logIncompleteSkipped']));
     }
     if ($arguments['strict']) {
         $result->strictMode(TRUE);
         $result->setTimeoutForSmallTests($arguments['timeoutForSmallTests']);
         $result->setTimeoutForMediumTests($arguments['timeoutForMediumTests']);
         $result->setTimeoutForLargeTests($arguments['timeoutForLargeTests']);
     }
     $suite->run($result, $arguments['filter'], $arguments['groups'], $arguments['excludeGroups'], $arguments['processIsolation']);
     unset($suite);
     $result->flushListeners();
     if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
         $this->printer->printResult($result);
     }
     if (isset($codeCoverage)) {
         if (isset($arguments['coverageClover'])) {
             $this->printer->write("\nGenerating code coverage report in Clover XML format ...");
             $writer = new PHP_CodeCoverage_Report_Clover();
             $writer->process($codeCoverage, $arguments['coverageClover']);
             $this->printer->write(" done\n");
             unset($writer);
         }
         if (isset($arguments['reportDirectory'])) {
             $this->printer->write("\nGenerating code coverage report in HTML format ...");
             $writer = new PHP_CodeCoverage_Report_HTML($arguments['reportCharset'], $arguments['reportHighlight'], $arguments['reportLowUpperBound'], $arguments['reportHighLowerBound'], sprintf(' and <a href="http://phpunit.de/">PHPUnit %s</a>', PHPUnit_Runner_Version::id()));
             $writer->process($codeCoverage, $arguments['reportDirectory']);
             $this->printer->write(" done\n");
             unset($writer);
         }
         if (isset($arguments['coveragePHP'])) {
             $this->printer->write("\nGenerating code coverage report in PHP format ...");
             $writer = new PHP_CodeCoverage_Report_PHP();
             $writer->process($codeCoverage, $arguments['coveragePHP']);
             $this->printer->write(" done\n");
             unset($writer);
         }
         if (isset($arguments['coverageText'])) {
             if ($arguments['coverageText'] == 'php://stdout') {
                 $outputStream = $this->printer;
                 $colors = (bool) $arguments['colors'];
             } else {
                 $outputStream = new PHPUnit_Util_Printer($arguments['coverageText']);
                 $colors = FALSE;
             }
             $writer = new PHP_CodeCoverage_Report_Text($outputStream, $arguments['reportLowUpperBound'], $arguments['reportHighLowerBound'], $arguments['coverageTextShowUncoveredFiles']);
             $writer->process($codeCoverage, $colors);
         }
     }
     return $result;
 }
Ejemplo n.º 22
0
 public function testShadowedTests()
 {
     $suite = new PHPUnit_Framework_TestSuite('OverrideTestCase');
     $suite->run($this->result);
     $this->assertEquals(1, count($this->result));
 }
Ejemplo n.º 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;
}
Ejemplo n.º 24
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;
 }
Ejemplo n.º 25
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);
     }
 }
Ejemplo n.º 26
0
 public function testNoArgTestCasePasses()
 {
     $result = new PHPUnit_Framework_TestResult();
     $t = new PHPUnit_Framework_TestSuite('NoArgTestCaseTest');
     $t->run($result);
     $this->assertEquals(1, count($result));
     $this->assertEquals(0, $result->failureCount());
     $this->assertEquals(0, $result->errorCount());
 }
Ejemplo n.º 27
0
 /**
  * @param PHPUnit_Framework_Test $suite
  * @param array                  $arguments
  * @param bool                   $exit
  *
  * @return PHPUnit_Framework_TestResult
  */
 public function doRun(PHPUnit_Framework_Test $suite, array $arguments = [], $exit)
 {
     if (isset($arguments['configuration'])) {
         $GLOBALS['__PHPUNIT_CONFIGURATION_FILE'] = $arguments['configuration'];
     }
     $this->handleConfiguration($arguments);
     $this->processSuiteFilters($suite, $arguments);
     if (isset($arguments['bootstrap'])) {
         $GLOBALS['__PHPUNIT_BOOTSTRAP'] = $arguments['bootstrap'];
     }
     if ($arguments['backupGlobals'] === false) {
         $suite->setBackupGlobals(false);
     }
     if ($arguments['backupStaticAttributes'] === true) {
         $suite->setBackupStaticAttributes(true);
     }
     if ($arguments['beStrictAboutChangesToGlobalState'] === true) {
         $suite->setbeStrictAboutChangesToGlobalState(true);
     }
     if (is_integer($arguments['repeat'])) {
         $test = new PHPUnit_Extensions_RepeatedTest($suite, $arguments['repeat'], $arguments['processIsolation']);
         $suite = new PHPUnit_Framework_TestSuite();
         $suite->addTest($test);
     }
     $result = $this->createTestResult();
     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['stopOnWarning']) {
         $result->stopOnWarning(true);
     }
     if ($arguments['stopOnIncomplete']) {
         $result->stopOnIncomplete(true);
     }
     if ($arguments['stopOnRisky']) {
         $result->stopOnRisky(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 {
             $printerClass = 'PHPUnit_TextUI_ResultPrinter';
             if (isset($arguments['printer']) && is_string($arguments['printer']) && class_exists($arguments['printer'], false)) {
                 $class = new ReflectionClass($arguments['printer']);
                 if ($class->isSubclassOf('PHPUnit_TextUI_ResultPrinter')) {
                     $printerClass = $arguments['printer'];
                 }
             }
             $this->printer = new $printerClass(isset($arguments['stderr']) ? 'php://stderr' : null, $arguments['verbose'], $arguments['colors'], $arguments['debug'], $arguments['columns'], $arguments['reverseList']);
         }
     }
     if (!$this->printer instanceof PHPUnit_Util_Log_TAP) {
         $this->printer->write(PHPUnit_Runner_Version::getVersionString() . "\n");
         self::$versionStringPrinted = true;
         if ($arguments['verbose']) {
             $runtime = $this->runtime->getNameWithVersion();
             if ($this->runtime->hasXdebug()) {
                 $runtime .= sprintf(' with Xdebug %s', phpversion('xdebug'));
             }
             $this->writeMessage('Runtime', $runtime);
             if (isset($arguments['configuration'])) {
                 $this->writeMessage('Configuration', $arguments['configuration']->getFilename());
             }
         }
         if (isset($arguments['deprecatedCheckForUnintentionallyCoveredCodeSettingUsed'])) {
             print "Warning:       Deprecated configuration setting \"checkForUnintentionallyCoveredCode\" used\n";
         }
     }
     foreach ($arguments['listeners'] as $listener) {
         $result->addListener($listener);
     }
     $result->addListener($this->printer);
     if (isset($arguments['testdoxHTMLFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_HTML($arguments['testdoxHTMLFile']));
     }
     if (isset($arguments['testdoxTextFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_Text($arguments['testdoxTextFile']));
     }
     $codeCoverageReports = 0;
     if (isset($arguments['coverageClover'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['coverageCrap4J'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['coverageHtml'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['coveragePHP'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['coverageText'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['coverageXml'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['noCoverage'])) {
         $codeCoverageReports = 0;
     }
     if ($codeCoverageReports > 0) {
         if (!$this->runtime->canCollectCodeCoverage()) {
             $this->writeMessage('Error', 'No code coverage driver is available');
             $codeCoverageReports = 0;
         } elseif (!isset($arguments['whitelist']) && !$this->codeCoverageFilter->hasWhitelist()) {
             $this->writeMessage('Error', 'No whitelist configured, no code coverage will be generated');
             $codeCoverageReports = 0;
         }
     }
     if (!$this->printer instanceof PHPUnit_Util_Log_TAP) {
         $this->printer->write("\n");
     }
     if ($codeCoverageReports > 0) {
         $codeCoverage = new PHP_CodeCoverage(null, $this->codeCoverageFilter);
         $codeCoverage->setAddUncoveredFilesFromWhitelist($arguments['addUncoveredFilesFromWhitelist']);
         $codeCoverage->setCheckForUnintentionallyCoveredCode($arguments['strictCoverage']);
         $codeCoverage->setCheckForUnexecutedCoveredCode($arguments['strictCoverage']);
         $codeCoverage->setProcessUncoveredFilesFromWhitelist($arguments['processUncoveredFilesFromWhitelist']);
         if (isset($arguments['forceCoversAnnotation'])) {
             $codeCoverage->setForceCoversAnnotation($arguments['forceCoversAnnotation']);
         }
         if (isset($arguments['disableCodeCoverageIgnore'])) {
             $codeCoverage->setDisableIgnoredLines(true);
         }
         if (isset($arguments['whitelist'])) {
             $this->codeCoverageFilter->addDirectoryToWhitelist($arguments['whitelist']);
         }
         $result->setCodeCoverage($codeCoverage);
     }
     if ($codeCoverageReports > 1) {
         if (isset($arguments['cacheTokens'])) {
             $codeCoverage->setCacheTokens($arguments['cacheTokens']);
         }
     }
     if (isset($arguments['jsonLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JSON($arguments['jsonLogfile']));
     }
     if (isset($arguments['tapLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_TAP($arguments['tapLogfile']));
     }
     if (isset($arguments['teamcityLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_TeamCity($arguments['teamcityLogfile']));
     }
     if (isset($arguments['junitLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JUnit($arguments['junitLogfile'], $arguments['logIncompleteSkipped']));
     }
     $result->beStrictAboutTestsThatDoNotTestAnything($arguments['reportUselessTests']);
     $result->beStrictAboutOutputDuringTests($arguments['disallowTestOutput']);
     $result->beStrictAboutTodoAnnotatedTests($arguments['disallowTodoAnnotatedTests']);
     $result->beStrictAboutResourceUsageDuringSmallTests($arguments['beStrictAboutResourceUsageDuringSmallTests']);
     $result->enforceTimeLimit($arguments['enforceTimeLimit']);
     $result->setTimeoutForSmallTests($arguments['timeoutForSmallTests']);
     $result->setTimeoutForMediumTests($arguments['timeoutForMediumTests']);
     $result->setTimeoutForLargeTests($arguments['timeoutForLargeTests']);
     if ($suite instanceof PHPUnit_Framework_TestSuite) {
         $suite->setRunTestInSeparateProcess($arguments['processIsolation']);
     }
     $suite->run($result);
     unset($suite);
     $result->flushListeners();
     if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
         $this->printer->printResult($result);
     }
     if (isset($codeCoverage)) {
         if (isset($arguments['coverageClover'])) {
             $this->printer->write("\nGenerating code coverage report in Clover XML format ...");
             try {
                 $writer = new PHP_CodeCoverage_Report_Clover();
                 $writer->process($codeCoverage, $arguments['coverageClover']);
                 $this->printer->write(" done\n");
                 unset($writer);
             } catch (PHP_CodeCoverage_Exception $e) {
                 $this->printer->write(" failed\n" . $e->getMessage() . "\n");
             }
         }
         if (isset($arguments['coverageCrap4J'])) {
             $this->printer->write("\nGenerating Crap4J report XML file ...");
             try {
                 $writer = new PHP_CodeCoverage_Report_Crap4j($arguments['crap4jThreshold']);
                 $writer->process($codeCoverage, $arguments['coverageCrap4J']);
                 $this->printer->write(" done\n");
                 unset($writer);
             } catch (PHP_CodeCoverage_Exception $e) {
                 $this->printer->write(" failed\n" . $e->getMessage() . "\n");
             }
         }
         if (isset($arguments['coverageHtml'])) {
             $this->printer->write("\nGenerating code coverage report in HTML format ...");
             try {
                 $writer = new PHP_CodeCoverage_Report_HTML($arguments['reportLowUpperBound'], $arguments['reportHighLowerBound'], sprintf(' and <a href="https://phpunit.de/">PHPUnit %s</a>', PHPUnit_Runner_Version::id()));
                 $writer->process($codeCoverage, $arguments['coverageHtml']);
                 $this->printer->write(" done\n");
                 unset($writer);
             } catch (PHP_CodeCoverage_Exception $e) {
                 $this->printer->write(" failed\n" . $e->getMessage() . "\n");
             }
         }
         if (isset($arguments['coveragePHP'])) {
             $this->printer->write("\nGenerating code coverage report in PHP format ...");
             try {
                 $writer = new PHP_CodeCoverage_Report_PHP();
                 $writer->process($codeCoverage, $arguments['coveragePHP']);
                 $this->printer->write(" done\n");
                 unset($writer);
             } catch (PHP_CodeCoverage_Exception $e) {
                 $this->printer->write(" failed\n" . $e->getMessage() . "\n");
             }
         }
         if (isset($arguments['coverageText'])) {
             if ($arguments['coverageText'] == 'php://stdout') {
                 $outputStream = $this->printer;
                 $colors = $arguments['colors'] && $arguments['colors'] != PHPUnit_TextUI_ResultPrinter::COLOR_NEVER;
             } else {
                 $outputStream = new PHPUnit_Util_Printer($arguments['coverageText']);
                 $colors = false;
             }
             $processor = new PHP_CodeCoverage_Report_Text($arguments['reportLowUpperBound'], $arguments['reportHighLowerBound'], $arguments['coverageTextShowUncoveredFiles'], $arguments['coverageTextShowOnlySummary']);
             $outputStream->write($processor->process($codeCoverage, $colors));
         }
         if (isset($arguments['coverageXml'])) {
             $this->printer->write("\nGenerating code coverage report in PHPUnit XML format ...");
             try {
                 $writer = new PHP_CodeCoverage_Report_XML();
                 $writer->process($codeCoverage, $arguments['coverageXml']);
                 $this->printer->write(" done\n");
                 unset($writer);
             } catch (PHP_CodeCoverage_Exception $e) {
                 $this->printer->write(" failed\n" . $e->getMessage() . "\n");
             }
         }
     }
     if ($exit) {
         if ($result->wasSuccessful()) {
             if ($arguments['failOnRisky'] && !$result->allHarmless()) {
                 exit(self::FAILURE_EXIT);
             }
             if ($arguments['failOnWarning'] && $result->warningCount() > 0) {
                 exit(self::FAILURE_EXIT);
             }
             exit(self::SUCCESS_EXIT);
         }
         if ($result->errorCount() > 0) {
             exit(self::EXCEPTION_EXIT);
         }
         if ($result->failureCount() > 0) {
             exit(self::FAILURE_EXIT);
         }
     }
     return $result;
 }
Ejemplo n.º 28
0
 public function testDontSkipInheritedClass()
 {
     $suite = new PHPUnit_Framework_TestSuite('DontSkipInheritedClass');
     $dir = dirname(__DIR__) . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Inheritance' . DIRECTORY_SEPARATOR;
     $suite->addTestFile($dir . 'InheritanceA.php');
     $suite->addTestFile($dir . 'InheritanceB.php');
     $result = $suite->run();
     $this->assertEquals(2, count($result));
 }
Ejemplo n.º 29
0
 /**
  * @param  PHPUnit_Framework_Test       $suite
  * @param  array                        $arguments
  * @return PHPUnit_Framework_TestResult
  */
 public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array())
 {
     $this->handleConfiguration($arguments);
     $this->processSuiteFilters($suite, $arguments);
     if (isset($arguments['bootstrap'])) {
         $GLOBALS['__PHPUNIT_BOOTSTRAP'] = $arguments['bootstrap'];
     }
     if ($arguments['backupGlobals'] === false) {
         $suite->setBackupGlobals(false);
     }
     if ($arguments['backupStaticAttributes'] === true) {
         $suite->setBackupStaticAttributes(true);
     }
     if ($arguments['disallowChangesToGlobalState'] === true) {
         $suite->setDisallowChangesToGlobalState(true);
     }
     if (is_integer($arguments['repeat'])) {
         $test = new PHPUnit_Extensions_RepeatedTest($suite, $arguments['repeat'], $arguments['processIsolation']);
         $suite = new PHPUnit_Framework_TestSuite();
         $suite->addTest($test);
     }
     $result = $this->createTestResult();
     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['stopOnRisky']) {
         $result->stopOnRisky(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 {
             $printerClass = 'PHPUnit_TextUI_ResultPrinter';
             if (isset($arguments['printer']) && is_string($arguments['printer']) && class_exists($arguments['printer'], false)) {
                 $class = new ReflectionClass($arguments['printer']);
                 if ($class->isSubclassOf('PHPUnit_TextUI_ResultPrinter')) {
                     $printerClass = $arguments['printer'];
                 }
             }
             $this->printer = new $printerClass(isset($arguments['stderr']) ? 'php://stderr' : null, $arguments['verbose'], $arguments['colors'], $arguments['debug'], $arguments['columns']);
         }
     }
     if (!$this->printer instanceof PHPUnit_Util_Log_TAP) {
         $this->printer->write(PHPUnit_Runner_Version::getVersionString() . "\n");
         self::$versionStringPrinted = true;
         if ($arguments['verbose']) {
             $this->printer->write(sprintf("\nRuntime:\t%s", $this->runtime->getNameWithVersion()));
             if ($this->runtime->hasXdebug()) {
                 $this->printer->write(sprintf(" with Xdebug %s", phpversion('xdebug')));
             }
             if (isset($arguments['configuration'])) {
                 $this->printer->write(sprintf("\nConfiguration:\t%s", $arguments['configuration']->getFilename()));
             }
             $this->printer->write("\n");
         }
         if (isset($arguments['deprecatedStrictModeOption'])) {
             print "Warning:\tDeprecated option \"--strict\" used\n";
         } elseif (isset($arguments['deprecatedStrictModeSetting'])) {
             print "Warning:\tDeprecated configuration setting \"strict\" used\n";
         }
         if (isset($arguments['deprecatedSeleniumConfiguration'])) {
             print "Warning:\tDeprecated configuration setting \"selenium\" used\n";
         }
     }
     foreach ($arguments['listeners'] as $listener) {
         $result->addListener($listener);
     }
     $result->addListener($this->printer);
     if (isset($arguments['testdoxHTMLFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_HTML($arguments['testdoxHTMLFile']));
     }
     if (isset($arguments['testdoxTextFile'])) {
         $result->addListener(new PHPUnit_Util_TestDox_ResultPrinter_Text($arguments['testdoxTextFile']));
     }
     $codeCoverageReports = 0;
     if (isset($arguments['coverageClover'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['coverageCrap4J'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['coverageHtml'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['coveragePHP'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['coverageText'])) {
         $codeCoverageReports++;
     }
     if (isset($arguments['coverageXml'])) {
         $codeCoverageReports++;
     }
     if (!$this->printer instanceof PHPUnit_Util_Log_TAP) {
         if ($codeCoverageReports > 0 && !$this->codeCoverageFilter->hasWhitelist()) {
             $this->printer->write("Warning:\tNo whitelist configured for code coverage\n");
         }
         $this->printer->write("\n");
     }
     if ($codeCoverageReports > 0 && (!extension_loaded('tokenizer') || !$this->runtime->canCollectCodeCoverage())) {
         if (!extension_loaded('tokenizer')) {
             $this->showExtensionNotLoadedMessage('tokenizer', 'No code coverage will be generated.');
         } elseif (!extension_loaded('Xdebug')) {
             $this->showExtensionNotLoadedMessage('Xdebug', 'No code coverage will be generated.');
         }
         $codeCoverageReports = 0;
     }
     if ($codeCoverageReports > 0) {
         $codeCoverage = new PHP_CodeCoverage(null, $this->codeCoverageFilter);
         $codeCoverage->setAddUncoveredFilesFromWhitelist($arguments['addUncoveredFilesFromWhitelist']);
         $codeCoverage->setCheckForUnintentionallyCoveredCode($arguments['strictCoverage']);
         $codeCoverage->setProcessUncoveredFilesFromWhitelist($arguments['processUncoveredFilesFromWhitelist']);
         if (isset($arguments['forceCoversAnnotation'])) {
             $codeCoverage->setForceCoversAnnotation($arguments['forceCoversAnnotation']);
         }
         if (isset($arguments['mapTestClassNameToCoveredClassName'])) {
             $codeCoverage->setMapTestClassNameToCoveredClassName($arguments['mapTestClassNameToCoveredClassName']);
         }
         $result->setCodeCoverage($codeCoverage);
     }
     if ($codeCoverageReports > 1) {
         if (isset($arguments['cacheTokens'])) {
             $codeCoverage->setCacheTokens($arguments['cacheTokens']);
         }
     }
     if (isset($arguments['jsonLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JSON($arguments['jsonLogfile']));
     }
     if (isset($arguments['tapLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_TAP($arguments['tapLogfile']));
     }
     if (isset($arguments['junitLogfile'])) {
         $result->addListener(new PHPUnit_Util_Log_JUnit($arguments['junitLogfile'], $arguments['logIncompleteSkipped']));
     }
     $result->beStrictAboutTestsThatDoNotTestAnything($arguments['reportUselessTests']);
     $result->beStrictAboutOutputDuringTests($arguments['disallowTestOutput']);
     $result->beStrictAboutTodoAnnotatedTests($arguments['disallowTodoAnnotatedTests']);
     $result->beStrictAboutTestSize($arguments['enforceTimeLimit']);
     $result->setTimeoutForSmallTests($arguments['timeoutForSmallTests']);
     $result->setTimeoutForMediumTests($arguments['timeoutForMediumTests']);
     $result->setTimeoutForLargeTests($arguments['timeoutForLargeTests']);
     if ($suite instanceof PHPUnit_Framework_TestSuite) {
         $suite->setRunTestInSeparateProcess($arguments['processIsolation']);
     }
     $suite->run($result);
     unset($suite);
     $result->flushListeners();
     if ($this->printer instanceof PHPUnit_TextUI_ResultPrinter) {
         $this->printer->printResult($result);
     }
     if (isset($codeCoverage)) {
         if (isset($arguments['coverageClover'])) {
             $this->printer->write("\nGenerating code coverage report in Clover XML format ...");
             $writer = new PHP_CodeCoverage_Report_Clover();
             $writer->process($codeCoverage, $arguments['coverageClover']);
             $this->printer->write(" done\n");
             unset($writer);
         }
         if (isset($arguments['coverageCrap4J'])) {
             $this->printer->write("\nGenerating Crap4J report XML file ...");
             $writer = new PHP_CodeCoverage_Report_Crap4j();
             $writer->process($codeCoverage, $arguments['coverageCrap4J']);
             $this->printer->write(" done\n");
             unset($writer);
         }
         if (isset($arguments['coverageHtml'])) {
             $this->printer->write("\nGenerating code coverage report in HTML format ...");
             $writer = new PHP_CodeCoverage_Report_HTML($arguments['reportLowUpperBound'], $arguments['reportHighLowerBound'], sprintf(' and <a href="http://phpunit.de/">PHPUnit %s</a>', PHPUnit_Runner_Version::id()));
             $writer->process($codeCoverage, $arguments['coverageHtml']);
             $this->printer->write(" done\n");
             unset($writer);
         }
         if (isset($arguments['coveragePHP'])) {
             $this->printer->write("\nGenerating code coverage report in PHP format ...");
             $writer = new PHP_CodeCoverage_Report_PHP();
             $writer->process($codeCoverage, $arguments['coveragePHP']);
             $this->printer->write(" done\n");
             unset($writer);
         }
         if (isset($arguments['coverageText'])) {
             if ($arguments['coverageText'] == 'php://stdout') {
                 $outputStream = $this->printer;
                 $colors = $arguments['colors'];
             } else {
                 $outputStream = new PHPUnit_Util_Printer($arguments['coverageText']);
                 $colors = false;
             }
             $processor = new PHP_CodeCoverage_Report_Text($arguments['reportLowUpperBound'], $arguments['reportHighLowerBound'], $arguments['coverageTextShowUncoveredFiles'], $arguments['coverageTextShowOnlySummary']);
             $outputStream->write($processor->process($codeCoverage, $colors));
         }
         if (isset($arguments['coverageXml'])) {
             $this->printer->write("\nGenerating code coverage report in PHPUnit XML format ...");
             $writer = new PHP_CodeCoverage_Report_XML();
             $writer->process($codeCoverage, $arguments['coverageXml']);
             $this->printer->write(" done\n");
             unset($writer);
         }
     }
     return $result;
 }
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 * http://www.gnu.org/copyleft/gpl.html
 *
 * @addtogroup Maintenance
 *
 */
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Framework/TestSuite.php';
require_once dirname(__FILE__) . '/MediaWikiUserInterfaceTestCase.php';
require_once dirname(__FILE__) . '/MediaWikiButtonsAvailabilityTestCase.php';
require_once dirname(__FILE__) . '/MediaWikiHelpFieldHintTestCase.php';
require_once dirname(__FILE__) . '/MediaWikiRightFrameworkLinksTestCase.php';
require_once dirname(__FILE__) . '/MediaWikiRestartInstallationTestCase.php';
require_once dirname(__FILE__) . '/MediaWikiErrorsConnectToDatabasePageTestCase.php';
require_once dirname(__FILE__) . '/MediaWikiErrorsNamepageTestCase.php';
require_once dirname(__FILE__) . '/MediaWikiMySQLDataBaseTestCase.php';
require_once dirname(__FILE__) . '/MediaWikiMySQLiteDataBaseTestCase.php';
require_once dirname(__FILE__) . '/MediaWikiUpgradeExistingDatabaseTestCase.php';
require_once dirname(__FILE__) . '/MediaWikiDifferntDatabasePrefixTestCase.php';
require_once dirname(__FILE__) . '/MediaWikiDifferentDatabaseAccountTestCase.php';
require_once dirname(__FILE__) . '/MediaWikiOnAlreadyInstalledTestCase.php';
$suite = new PHPUnit_Framework_TestSuite('ArrayTest');
$result = new PHPUnit_Framework_TestResult();
$suite->run($result);