/** * Call the same functions used by the CLI PHPUnit * to engage the tests * @param string $modulePath path to the phpunit.xml to use * @return int * 0: Tests successful * 1: Tests failed * 2: Failed with exception */ public function run($modulePath, $params = array()) { $runner = new \PHPUnit_TextUI_Command(); $options = array('--configuration', $modulePath . '/phpunit.xml'); if (isset($params['filter']) && !empty($params['filter'])) { $options[] = '--filter'; $options[] = $params['filter']; } if (isset($params['coverage']) && !empty($params['coverage'])) { $coverage = $params['coverage']; $path = $this->getCoveragePath(); switch ($coverage) { case 'html': $options[] = '--coverage-html'; $path .= '/html'; $options[] = $path; break; default: $options[] = '--coverage-text'; break; } echo "Coverage data will be written to {$path}" . PHP_EOL; } array_unshift($options, 'phpunit'); return $runner->run($options, false); }
public function runTests() { $cliOptions = ['phpunit']; // first entry is the command array_push($cliOptions, '-c', __QCUBED_CORE__ . '/tests/phpunit.xml'); // the config file is here // array_push($cliOptions, '--bootstrap', __QCUBED_CORE__ . '/../vendor/autoload.php'); $tester = new PHPUnit_TextUI_Command(); $tester->run($cliOptions); }
public function execute() { global $IP; // NOTE (phuedx, 2014-03-26) wgAutoloadClasses isn't set up // by either of the dependencies at the top of the file, so // require it here. require_once __DIR__ . '/../tests/TestsAutoLoader.php'; $textUICommand = new PHPUnit_TextUI_Command(); $argv = array("{$IP}/tests/phpunit/phpunit.php", "{$IP}/tests/phpunit/suites/LessTestSuite.php"); $textUICommand->run($argv); }
/** * (non-PHPdoc) * * @see \SK\ITCBundle\Code\Generator\PHPUnit\AbstractGenerator::execute($input, $output) */ public function execute(InputInterface $input, OutputInterface $output) { $this->writeHeader($output); if (strpos('/usr/bin/php', '@php_bin') === 0) { require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'PHPUnit' . DIRECTORY_SEPARATOR . 'Autoload.php'; } else { require '/usr/share/pear' . DIRECTORY_SEPARATOR . 'PHPUnit' . DIRECTORY_SEPARATOR . 'Autoload.php'; } $commandArg = array('-c' => "phpunit.xml"); $command = new \PHPUnit_TextUI_Command(); $command->run($commandArg); }
/** * Read configuration file, and run check. * * @return void * @throws \Exception */ public function run() { if (is_null($this->config)) { exit("Can not find a set of checks to run.\n"); } PHP_Timer::start(); $command = new \PHPUnit_TextUI_Command(); $command->run(array('--configuration', $this->config, '--testdox'), false); $duration = PHP_Timer::stop(); $c = new Color(); echo $c('Time : ' . PHP_Timer::secondsToTimeString($duration))->bold() . PHP_EOL; }
/** * new method to launch a web server * @param array $options * @tutorial php bin/console server:run * php bin/console server:run -a 192.168.0.1:8000 */ public function phpunit(array $options = array()) { ob_get_clean(); $files = scandir(__DIR__ . '/../../../../tests'); foreach ($files as $one) { if (is_dir(__DIR__ . '/../../../../tests/' . $one) && $one != '..' && $one != '.') { $controllerFiles = scandir(__DIR__ . '/../../../../tests' . '/' . $one . '/app/Controller'); foreach ($controllerFiles as $oneController) { if (is_file(__DIR__ . '/../../../../tests/' . $one . '/app/Controller/' . $oneController) && $oneController != '..' && $oneController != '.') { $unitTest = new \PHPUnit_TextUI_Command(); $unitTest->run([__DIR__ . '/../../../../tests/' . $one . '/app/Controller/' . $oneController]); } } } } }
/** * Runs PHPUnit. * * @return void */ public function run() { require_once 'PHPUnit/Autoload.php'; /** @var string */ define('PHPUnit_MAIN_METHOD', 'PHPUnit_TextUI_Command::main'); PHPUnit_TextUI_Command::main(); }
protected function showHelp() { parent::showHelp(); print <<<EOT --rerun Runs tests that failed on last execution. EOT; }
/** * Should run tests in browser * @param null $filterClass */ public function runAction($filterClass = null) { // Make sure PHPUnit is autoloaded require_once 'PHPUnit/Autoload.php'; set_time_limit(3600); $version = \PHPUnit_Runner_Version::id(); $kernel_dir = $this->container->getParameter('kernel.root_dir'); chdir($kernel_dir); // This will force the printer class to be autoloaded by Symfony, before PHPUnit tries to (and does not) find it $printerClass = 'Goutte\\DoodleBundle\\Tools\\PHPUnit\\HtmlResultPrinter'; if (!class_exists($printerClass)) { $printerClass = false; } $argv = array(); $argv[] = 'phpunit'; if ($filterClass) { $argv[] = '--filter'; $argv[] = $filterClass; } if (version_compare($version, "3.6.0") >= 0) { if ($printerClass) { $argv[] = '--printer'; $argv[] = $printerClass; } $_SERVER['argv'] = $argv; \PHPUnit_TextUI_Command::main(true); } else { ob_end_clean(); echo '<pre>'; $_SERVER['argv'] = $argv; \PHPUnit_TextUI_Command::main(false); echo '</pre>'; exit; } }
/** * Uses an instance of PHPUnit_TextUI_Command to execute the PHPUnit * tests and simulates any Mutagenesis supported command line options suitable * for PHPUnit. At present, we merely dissect a generic 'options' string * equivelant to anything typed into a console after a normal 'phpunit' * command. The adapter captures the TextUI output for further processing. * * To prevent duplication of output from stdout, PHPUnit is hard * configured to write to stderrm(stdin is used in proc_open call) * * @param array $arguments Mutagenesis arguments to pass to PHPUnit * @return void */ public static function main(array $arguments, $useStdout = false) { if (!$useStdout) { array_unshift($arguments['clioptions'], '--stderr'); } if (!in_array('--stop-on-failure', $arguments['clioptions'])) { array_unshift($arguments['clioptions'], '--stop-on-failure'); } array_unshift($arguments['clioptions'], 'phpunit'); $originalWorkingDirectory = getcwd(); if (isset($arguments['tests'])) { chdir($arguments['tests']); } $command = new \PHPUnit_TextUI_Command(); $command->run($arguments['clioptions'], false); chdir($originalWorkingDirectory); }
public function showHelp() { parent::showHelp(); print <<<EOT --order <rand[:seed]> Randomize the order of the tests. Optionally you can pass a seed to run a specific order. EOT; }
public function execute() { global $IP; // NOTE (phuedx, 2014-03-26) wgAutoloadClasses isn't set up // by either of the dependencies at the top of the file, so // require it here. require_once __DIR__ . '/../tests/TestsAutoLoader.php'; // If phpunit isn't available by autoloader try pulling it in if (!class_exists('PHPUnit_Framework_TestCase')) { require_once 'PHPUnit/Autoload.php'; } // RequestContext::resetMain() will print warnings unless this // is defined. if (!defined('MW_PHPUNIT_TEST')) { define('MW_PHPUNIT_TEST', true); } $textUICommand = new PHPUnit_TextUI_Command(); $argv = ["{$IP}/tests/phpunit/phpunit.php", "{$IP}/tests/phpunit/suites/LessTestSuite.php"]; $textUICommand->run($argv); }
/** * Uses an instance of PHPUnit_TextUI_Command to execute the PHPUnit * tests and simulates any Mutateme supported command line options suitable * for PHPUnit. At present, we merely dissect a generic 'options' string * equivelant to anything typed into a console after a normal 'phpunit' * command. The adapter captures the TextUI output for further processing. * * To prevent duplication of output from stdout, PHPUnit is hard * configured to write to stderrm(stdin is used in proc_open call) * * @param array $arguments Mutateme arguments to pass to PHPUnit * @return void */ public static function main(array $arguments, $useStdout = false) { $optionString = 'phpunit'; if ($useStdout) { $optionString .= ''; } else { $optionString = ' --stderr'; } if (isset($arguments['options'])) { $optionString .= ' ' . $arguments['options']; } $options = explode(' ', $optionString); $originalWorkingDirectory = getcwd(); if (isset($arguments['tests'])) { chdir($arguments['tests']); } $command = new \PHPUnit_TextUI_Command(); $command->run($options, false); chdir($originalWorkingDirectory); }
/** * Runs PHPUnit. * * @return void */ public function run() { // Store current TYPO3 configuration and set the default one // This is needed as the configuration might include closures which cannot be backed up $globalBackup = $this->removeClosures($GLOBALS['TYPO3_CONF_VARS']); // Run unit tests /** @var string */ define('PHPUnit_MAIN_METHOD', 'PHPUnit_TextUI_Command::main'); PHPUnit_TextUI_Command::main(); // Restore configuration $GLOBALS['TYPO3_CONF_VARS'] = array_merge($GLOBALS['TYPO3_CONF_VARS'], $globalBackup); }
/** * {@inheritdoc} */ protected function handleArguments(array $argv) { parent::handleArguments($argv); if (array_key_exists('testSuffixes', $this->arguments)) { $fileSystem = new FileSystem(); $filePatterns = array(); foreach ($this->arguments['testSuffixes'] as $testSuffix) { $filePatterns[] = preg_quote($testSuffix) . '$'; } $this->testTargetRepository->setResources(array(empty($this->arguments['testFile']) ? $this->arguments['test'] : $this->arguments['testFile'])); $this->testTargetRepository->setFilePattern(implode('|', $filePatterns)); } }
protected function showHelp() { parent::showHelp(); print <<<EOT --db-per-test Use a clean database per test --dsn <resource> Use the database specified with a DSN: type://user:password@host/database. An example to connect with the local MySQL database is: mysql://root@mypass@localhost/unittests --list-tests Lists all tests EOT; }
/** * {@inheritdoc} */ protected function handleBootstrap($filename) { parent::handleBootstrap($filename); // By default, we want PHPUnit's autoloader before Symfony's one if (!getenv('SYMFONY_PHPUNIT_OVERLOAD')) { $filename = realpath(stream_resolve_include_path($filename)); $symfonyLoader = realpath(dirname(PHPUNIT_COMPOSER_INSTALL) . '/../../../vendor/autoload.php'); if ($filename === $symfonyLoader) { $symfonyLoader = (require $symfonyLoader); $symfonyLoader->unregister(); $symfonyLoader->register(false); } } }
public function showHelp() { parent::showHelp(); print <<<EOT ParserTest-specific options: --regex="<regex>" Only run parser tests that match the given regex --file="<filename>" Prints the version and exits. --keep-uploads Re-use the same upload directory for each test, don't delete it EOT; }
public function showHelp() { parent::showHelp(); print <<<EOT ParserTest-specific options: --regex="<regex>" Only run parser tests that match the given regex --file="<filename>" File describing parser tests --keep-uploads Re-use the same upload directory for each test, don't delete it Database options: --use-normal-tables Use normal DB tables. --reuse-db Init DB only if tables are missing and keep after finish. Debugging options: --debug-tests Log testing activity to the PHPUnitCommand log channel. EOT; }
public function showHelp() { parent::showHelp(); print <<<EOT ParserTest-specific options: --regex="<regex>" Only run parser tests that match the given regex --file="<filename>" Prints the version and exits. --keep-uploads Re-use the same upload directory for each test, don't delete it Database options: --use-normal-tables Use normal DB tables. --reuse-db Init DB only if tables are missing and keep after finish. EOT; }
public function run(array $argv, $exit = true) { $this->longOptions['phpguard-test-files'] = null; return parent::run($argv, $exit); }
/** * @param boolean $exit */ public static function main($exit = TRUE) { $command = new PHPUnit_TextUI_Command(); $command->run($_SERVER['argv'], $exit); }
$ok = false; if (class_exists('PHPUnit_TextUI_Command')) { echo "PHPUnit already present\n"; $ok = true; } else { foreach (array(stream_resolve_include_path('phpunit.phar'), stream_resolve_include_path('phpunit-old.phar'), 'PHPUnit/Runner/Version.php', 'PHPUnit/Autoload.php') as $includePath) { if ($includePath === false) { // stream_resolve_include_path can return false continue; } \MediaWiki\suppressWarnings(); include_once $includePath; \MediaWiki\restoreWarnings(); if (class_exists('PHPUnit_TextUI_Command')) { $ok = true; echo "Using PHPUnit from {$includePath}\n"; break; } } } if (!$ok) { echo "Couldn't find a usable PHPUnit.\n"; exit(1); } $puVersion = PHPUnit_Runner_Version::id(); if ($puVersion !== '@package_version@' && version_compare($puVersion, '3.7.0', '<')) { echo "PHPUnit 3.7.0 or later required; you have {$puVersion}.\n"; exit(1); } PHPUnit_TextUI_Command::main();
/** * Uses an instance of PHPUnit_TextUI_Command to execute the PHPUnit * tests and simulates any Mutagenesis supported command line options suitable * for PHPUnit. At present, we merely dissect a generic 'options' string * equivelant to anything typed into a console after a normal 'phpunit' * command. The adapter captures the TextUI output for further processing. * * To prevent duplication of output from stdout, PHPUnit is hard * configured to write to stderrm(stdin is used in proc_open call) * * @param array $arguments Mutagenesis arguments to pass to PHPUnit * @return void */ public static function main($arguments, $mutation = null, $bootstrap = null) { $arguments = unserialize($arguments); /** * Grab the Runkit extension utility and apply the mutation if needed */ if (!is_null($mutation)) { $mutation = unserialize($mutation); if (!empty($mutation)) { if (!is_null($bootstrap)) { require_once $bootstrap; } if (!in_array('runkit', get_loaded_extensions())) { throw new \Exception('Runkit extension is not loaded. Unfortunately, runkit' . ' is essential for Mutagenesis. Please see the manual or' . ' README which explains how to install an updated runkit' . ' extension suitable for Mutagenesis and PHP 5.3.'); } $runkit = new \Mutagenesis\Utility\Runkit(); $runkit->applyMutation($mutation); } } /** * Switch working directory to tests and execute the test suite */ $originalWorkingDirectory = getcwd(); if (isset($arguments['tests'])) { chdir($arguments['tests']); } $command = new \PHPUnit_TextUI_Command(); $command->run($arguments['clioptions'], false); chdir($originalWorkingDirectory); }
/** * {@inheritdoc} * * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ public function run(array $argv, $exit = true) { $argv = $this->preprocessArgv($argv); if (in_array('--sugared-debug', $argv)) { $this->logDebug('Arguments', $argv); } parent::run($argv, $exit); }
<?php // This file is loaded on all systems running tests. To override settings on // your local system, please create "civicrm.settings.local.php" and put // the settings there. //--- you shouldn't have to modify anything under this line, but might want to put the compiled templates CIVICRM_TEMPLATE_COMPILEDIR in a different folder than our default location ---------- if (!defined('CIVICRM_DSN') && !empty($GLOBALS['mysql_user'])) { $dbName = !empty($GLOBALS['mysql_db']) ? $GLOBALS['mysql_db'] : 'civicrm_tests_dev'; if (empty($GLOBALS['mysql_pass']) && $GLOBALS['mysql_pass_need_password']) { $GLOBALS['mysql_pass'] = PHPUnit_TextUI_Command::getPassword('Password'); } define('CIVICRM_DSN', "mysql://{$GLOBALS['mysql_user']}:{$GLOBALS['mysql_pass']}@{$GLOBALS['mysql_host']}/{$dbName}?new_link=true"); } if (!defined("CIVICRM_DSN")) { $dsn = getenv("CIVICRM_TEST_DSN"); if (!empty($dsn)) { define("CIVICRM_DSN", $dsn); } else { echo "\nFATAL: no DB connection configured (CIVICRM_DSN). \nYou can either create/edit " . __DIR__ . "/civicrm.settings.local.php\n"; if (strtoupper(substr(PHP_OS, 0, 3)) !== 'WIN') { echo "OR set it in your shell:\n \$export CIVICRM_TEST_DSN=mysql://db_username:db_password@localhost/civicrm_tests_dev \n"; } else { echo "OR set it in your shell:\n SETX CIVICRM_TEST_DSN mysql://db_username:db_password@localhost/civicrm_tests_dev \n\n (you will need to open a new command shell before it takes effect)"; } echo "\n\n\nIf you haven't done so already, you need to create (once) a database dedicated to the unit tests:\nmysql -uroot -p\ncreate database civicrm_tests_dev;\ngrant ALL on civicrm_tests_dev.* to db_username@localhost identified by 'db_password';\ngrant SUPER on *.* to db_username@localhost identified by 'db_password';\n"; die(""); } } require_once "DB.php"; $dsninfo = DB::parseDSN(CIVICRM_DSN); $GLOBALS['mysql_host'] = $dsninfo['hostspec'];
<?php require_once __DIR__ . '/vendor/autoload.php'; use SPE\Core\TestController; use SPE\CKlein\Reports\ConsolidatedReport; try { PHPUnit_TextUI_Command::main(false); } catch (Exception $e) { } if (TestController::isTestSuccessful()) { echo "generate consolidation report"; $consolidatedReport = new ConsolidatedReport($argv); $consolidatedReport->generate(); } else { echo "in shutdown"; TestController::shutdown(); }
/** * Run Both Unit-test and Code-coverage analysist * * @param string Path to Test (Juriya idiomatic style directory structure is required) * @return stream */ public static function runTest($target = '') { $paths = explode(PATH_SEPARATOR, get_include_path()); $pwd = $_SERVER['PWD']; if (!$target) { self::out('--test command missed target folder'); } else { // Find configuration definition $configuration = ''; $configurationExists = FALSE; if (file_exists($pwd . DIRECTORY_SEPARATOR . 'phpunit.xml')) { $configuration = $pwd . DIRECTORY_SEPARATOR . 'phpunit.xml'; $configurationExists = TRUE; } elseif (($path = $pwd . DIRECTORY_SEPARATOR . $target) && is_dir($path)) { if (($testSrc = $path . DIRECTORY_SEPARATOR . 'Tests') && is_dir($testSrc)) { $configuration = $testSrc . DIRECTORY_SEPARATOR . 'phpunit.xml'; } } else { foreach ($paths as $path) { if (($testSrc = $path . DIRECTORY_SEPARATOR . $target . DIRECTORY_SEPARATOR . 'Tests') && is_dir($testSrc)) { $configuration = $testSrc . DIRECTORY_SEPARATOR . 'phpunit.xml'; break 1; } } } // Garbage collection $coveragePhp = '/tmp/coverage.php'; file_exists($coveragePhp) and File::delete($coveragePhp); // Try to read the configuration try { $configurationInstance = \PHPUnit_Util_Configuration::getInstance($configuration); } catch (\Exception $e) { print $e->getMessage() . "\n"; exit(\PHPUnit_TextUI_TestRunner::FAILURE_EXIT); } $configurationArray = $configurationInstance->getPHPUnitConfiguration(); // Validate test suites before start processing furthermore $testDirectory = new \DirectoryIterator(str_replace('phpunit.xml', '', $configuration)); $validTestSuite = FALSE; while ($testDirectory->valid()) { if ($testDirectory->isFile() && strpos($testDirectory->getFilename(), 'Test.php') !== FALSE) { $validTestSuite = TRUE; } $testDirectory->next(); } if (!$validTestSuite) { $errorText = 'ERROR: ' . I18n::translate('command_testsuite_not_found'); if ($configurationArray['colors'] === TRUE) { $errorText = Utility::getColoredString($errorText, 'black', 'red'); } self::out($errorText); exit(\PHPUnit_TextUI_TestRunner::FAILURE_EXIT); } // Reset server arguments $_SERVER['argv'] = array('--configuration', $configuration, '--coverage-php', $coveragePhp); // Preparing reports $strippedText = 'Generating code coverage report in PHP format ... done'; $reportTestTitle = 'PHPUnit Report : '; self::out($configurationArray['colors'] ? Utility::getColoredString($reportTestTitle, 'yellow') : $reportTestTitle); $reportCcTitle = 'CodeCoverage Report : '; $reportCcTitle = $configurationArray['colors'] ? Utility::getColoredString($reportCcTitle, 'yellow') : $reportCcTitle; // Get phpunit report ob_start(); $exitCode = \PHPUnit_TextUI_Command::main(FALSE); $out = ob_get_clean(); $report = substr($out, strpos($out, "\n\n") + 1); $unitTestReport = str_replace($strippedText, $reportCcTitle, $report); $codeCoverage = @unserialize(File::read($coveragePhp)); $codeCoverageData = $codeCoverage->getData(); $codeCoverageRoot = $codeCoverage->getReport(); $codeCoverageNodes = $codeCoverageRoot->getChildNodes(); // Generate code coverage report $classCoverage = array(); $overallCoverage = array('totalClasses' => 0, 'totalCoveredClasses' => 0, 'totalMethods' => 0, 'totalCoveredMethods' => 0, 'totalLines' => 0, 'totalCoveredLines' => 0); // Closure for calculate the level $calculate = function ($percentages) { $level = 'gray'; if ($percentages >= 75) { $level = 'green'; } elseif ($percentages < 75 && $percentages >= 50) { $level = 'yellow'; } elseif ($percentages < 50 && $percentages >= 25) { $level = 'magenta'; } else { $level = 'red'; } return $level; }; $collectFromNode = function ($node) { $classes = array_merge($node->getClasses(), $node->getTraits()); $coverage = $node->getCoverageData(); $lines = array(); $ignoredLines = $node->getIgnoredLines(); foreach ($classes as $className => $class) { $classStatements = 0; $coveredClassStatements = 0; $coveredMethods = 0; foreach ($class['methods'] as $methodName => $method) { $methodCount = 0; $methodLines = 0; $methodLinesCovered = 0; for ($z = $method['startLine']; $z <= $method['endLine']; $z++) { if (isset($ignoredLines[$z])) { continue; } $add = TRUE; $count = 0; if (isset($coverage[$z])) { if ($coverage[$z] !== NULL) { $classStatements++; $methodLines++; } else { $add = FALSE; } $count = count($coverage[$z]); if ($count > 0) { $coveredClassStatements++; $methodLinesCovered++; } } else { $add = FALSE; } $methodCount = max($methodCount, $count); if ($add) { $lines[$z] = array('count' => $count, 'type' => 'stmt'); } } if ($methodCount > 0) { $coveredMethods++; } } if (!empty($class['package']['namespace'])) { $namespace = '\\' . $class['package']['namespace'] . '\\'; } elseif (!empty($class['package']['fullPackage'])) { $namespace = '@' . $class['package']['fullPackage'] . '\\'; } else { $namespace = ''; } return array('namespace' => $namespace, 'className' => $className, 'methodsCovered' => $coveredMethods, 'methodCount' => count($class['methods']), 'statementsCovered' => $coveredClassStatements, 'statementCount' => $classStatements); } }; for ($i = 0, $max = count($codeCoverageNodes); $i < $max; $i++) { $item = $codeCoverageNodes[$i]; if ($item instanceof \PHP_CodeCoverage_Report_Node_File) { array_push($classCoverage, $collectFromNode($item)); } elseif ($item instanceof \PHP_CodeCoverage_Report_Node_Directory) { foreach ($item->getChildNodes() as $itemNode) { array_push($classCoverage, $collectFromNode($itemNode)); } } else { continue; } } ksort($classCoverage); $codeCoverageReport = ''; for ($x = 0, $max = count($classCoverage); $x < $max; $x++) { $classInfo = $classCoverage[$x]; $fullQualifiedPath = $classInfo['namespace'] . $classInfo['className']; if ($classInfo['statementsCovered'] != 0) { // Increase overallCoverage $overallCoverage['totalClasses']++; $overallCoverage['totalMethods'] = $overallCoverage['totalMethods'] + $classInfo['methodCount']; $overallCoverage['totalCoveredMethods'] = $overallCoverage['totalCoveredMethods'] + $classInfo['methodsCovered']; $overallCoverage['totalLines'] = $overallCoverage['totalLines'] + $classInfo['statementCount']; $overallCoverage['totalCoveredLines'] = $overallCoverage['totalCoveredLines'] + $classInfo['statementsCovered']; // Build item Code-coverage main report $ccPath = $fullQualifiedPath; $ccMethods = str_pad(' Methods(' . $classInfo['methodsCovered'] . '/' . $classInfo['methodCount'] . ')', 18, ' '); $ccLines = str_pad(' Lines(' . $classInfo['statementsCovered'] . '/' . $classInfo['statementCount'] . ')', 18, ' '); // Calculate the percentage $ccMethodsPercentages = round((int) $classInfo['methodsCovered'] / (int) $classInfo['methodCount'] * 100, 2); $ccLinesPercentages = round((int) $classInfo['statementsCovered'] / (int) $classInfo['statementCount'] * 100, 2); // Normalize the pad $ccMethodsPercentagesText = $ccMethods . ': ' . str_pad($ccMethodsPercentages . '% ', 8, ' ', STR_PAD_LEFT); $ccLinesPercentagesText = $ccLines . ': ' . str_pad($ccLinesPercentages . '% ', 8, ' ', STR_PAD_LEFT); // Increase classed covered for 100% classes if ($ccMethodsPercentages == 100 && $ccLinesPercentages == 100) { $overallCoverage['totalCoveredClasses']++; } // Colorize if necessary if ($configurationArray['colors'] === TRUE) { $ccPath = Utility::getColoredString($ccPath, 'light_cyan'); $ccMethodsLevel = $calculate($ccMethodsPercentages); $ccLinesLevel = $calculate($ccLinesPercentages); $ccMethodsPercentagesText = Utility::getColoredString($ccMethodsPercentagesText, 'black', $ccMethodsLevel); $ccLinesPercentagesText = Utility::getColoredString($ccLinesPercentagesText, 'black', $ccLinesLevel); } $codeCoverageReport .= PHP_EOL . $ccPath . PHP_EOL . $ccMethodsPercentagesText . PHP_EOL . $ccLinesPercentagesText . PHP_EOL; } } // Finalize Code-coverage report if ($overallCoverage['totalCoveredClasses'] > 0) { $overallPercentage = round((int) $overallCoverage['totalCoveredClasses'] / (int) $overallCoverage['totalClasses'] * 100, 2); } else { $overallPercentage = 0; } if ($overallPercentage >= 75) { $overallPercentageText = 'OK'; } elseif ($overallPercentage < 75 && $overallPercentage >= 50) { $overallPercentageText = 'MEDIUM'; } else { $overallPercentageText = 'LOW'; } $overallCoverageReport = $overallPercentageText . ' ('; $overallCoverageReport .= $overallPercentage; $overallCoverageReport .= '% classes, '; if ($overallCoverage['totalCoveredMethods'] > 0) { $overallCoverageReport .= round((int) $overallCoverage['totalCoveredMethods'] / (int) $overallCoverage['totalMethods'] * 100, 2); } else { $overallCoverageReport .= 0; } $overallCoverageReport .= '% methods, '; if ($overallCoverage['totalCoveredLines'] > 0) { $overallCoverageReport .= round((int) $overallCoverage['totalCoveredLines'] / (int) $overallCoverage['totalLines'] * 100, 2); } else { $overallCoverageReport .= 0; } $overallCoverageReport .= '% lines were covered)'; // Colorize if necessary if ($configurationArray['colors'] === TRUE) { $coverageStatus = $calculate($overallPercentage); $overallCoverageReport = Utility::getColoredString($overallCoverageReport, 'black', $coverageStatus); } $codeCoverageReport .= PHP_EOL . $overallCoverageReport . PHP_EOL; // Output all tests reports self::out($unitTestReport . $codeCoverageReport); exit($exitCode); } }
/** * @param array $argv * @param boolean $exit */ public function run(array $argv, $exit = true) { parent::run($argv, false); }
public function run($options) { $phpunit = new \PHPUnit_TextUI_Command(); $phpunit->run(['', 'tests/cases', '--bootstrap=tests/bootstrap.php']); }