Initial Commit

This commit is contained in:
Riley Schneider
2025-12-03 16:38:10 +01:00
parent c5e26bf594
commit b732d8d4b5
17680 changed files with 5977495 additions and 2 deletions

View File

@@ -0,0 +1,897 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2001-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit
* @subpackage TextUI
* @author Sebastian Bergmann <sebastian@phpunit.de>
* @copyright 2001-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 3.0.0
*/
/**
* A TestRunner for the Command Line Interface (CLI)
* PHP SAPI Module.
*
* @package PHPUnit
* @subpackage TextUI
* @author Sebastian Bergmann <sebastian@phpunit.de>
* @copyright 2001-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since Class available since Release 3.0.0
*/
class PHPUnit_TextUI_Command
{
/**
* @var array
*/
protected $arguments = array(
'listGroups' => FALSE,
'loader' => NULL,
'useDefaultConfiguration' => TRUE
);
/**
* @var array
*/
protected $options = array();
/**
* @var array
*/
protected $longOptions = array(
'colors' => NULL,
'bootstrap=' => NULL,
'configuration=' => NULL,
'coverage-html=' => NULL,
'coverage-clover=' => NULL,
'coverage-php=' => NULL,
'coverage-text==' => NULL,
'debug' => NULL,
'exclude-group=' => NULL,
'filter=' => NULL,
'testsuite=' => NULL,
'group=' => NULL,
'help' => NULL,
'include-path=' => NULL,
'list-groups' => NULL,
'loader=' => NULL,
'log-json=' => NULL,
'log-junit=' => NULL,
'log-tap=' => NULL,
'process-isolation' => NULL,
'repeat=' => NULL,
'stderr' => NULL,
'stop-on-error' => NULL,
'stop-on-failure' => NULL,
'stop-on-incomplete' => NULL,
'stop-on-skipped' => NULL,
'strict' => NULL,
'tap' => NULL,
'testdox' => NULL,
'testdox-html=' => NULL,
'testdox-text=' => NULL,
'test-suffix=' => NULL,
'no-configuration' => NULL,
'no-globals-backup' => NULL,
'printer=' => NULL,
'static-backup' => NULL,
'verbose' => NULL,
'version' => NULL
);
/**
* @var array
*/
protected $missingExtensions = array();
/**
* @param boolean $exit
*/
public static function main($exit = TRUE)
{
$command = new PHPUnit_TextUI_Command;
return $command->run($_SERVER['argv'], $exit);
}
/**
* @param array $argv
* @param boolean $exit
*/
public function run(array $argv, $exit = TRUE)
{
$this->handleArguments($argv);
$runner = $this->createRunner();
if (is_object($this->arguments['test']) &&
$this->arguments['test'] instanceof PHPUnit_Framework_Test) {
$suite = $this->arguments['test'];
} else {
$suite = $runner->getTest(
$this->arguments['test'],
$this->arguments['testFile'],
$this->arguments['testSuffixes']
);
}
if ($this->arguments['listGroups']) {
PHPUnit_TextUI_TestRunner::printVersionString();
print "Available test group(s):\n";
$groups = $suite->getGroups();
sort($groups);
foreach ($groups as $group) {
print " - $group\n";
}
if ($exit) {
exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
} else {
return PHPUnit_TextUI_TestRunner::SUCCESS_EXIT;
}
}
unset($this->arguments['test']);
unset($this->arguments['testFile']);
try {
$result = $runner->doRun($suite, $this->arguments);
}
catch (PHPUnit_Framework_Exception $e) {
print $e->getMessage() . "\n";
}
$ret = PHPUnit_TextUI_TestRunner::FAILURE_EXIT;
if (isset($result) && $result->wasSuccessful()) {
$ret = PHPUnit_TextUI_TestRunner::SUCCESS_EXIT;
}
else if (!isset($result) || $result->errorCount() > 0) {
$ret = PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT;
}
if ($exit) {
exit($ret);
} else {
return $ret;
}
}
/**
* Create a TestRunner, override in subclasses.
*
* @return PHPUnit_TextUI_TestRunner
* @since Method available since Release 3.6.0
*/
protected function createRunner()
{
return new PHPUnit_TextUI_TestRunner($this->arguments['loader']);
}
/**
* Handles the command-line arguments.
*
* A child class of PHPUnit_TextUI_Command can hook into the argument
* parsing by adding the switch(es) to the $longOptions array and point to a
* callback method that handles the switch(es) in the child class like this
*
* <code>
* <?php
* class MyCommand extends PHPUnit_TextUI_Command
* {
* public function __construct()
* {
* $this->longOptions['--my-switch'] = 'myHandler';
* }
*
* // --my-switch foo -> myHandler('foo')
* protected function myHandler($value)
* {
* }
* }
* </code>
*
* @param array $argv
*/
protected function handleArguments(array $argv)
{
try {
$this->options = PHPUnit_Util_Getopt::getopt(
$argv,
'd:c:hv',
array_keys($this->longOptions)
);
}
catch (PHPUnit_Framework_Exception $e) {
PHPUnit_TextUI_TestRunner::showError($e->getMessage());
}
foreach ($this->options[0] as $option) {
switch ($option[0]) {
case '--colors': {
$this->arguments['colors'] = TRUE;
}
break;
case '--bootstrap': {
$this->arguments['bootstrap'] = $option[1];
}
break;
case 'c':
case '--configuration': {
$this->arguments['configuration'] = $option[1];
}
break;
case '--coverage-clover':
case '--coverage-html':
case '--coverage-php':
case '--coverage-text': {
if (!extension_loaded('tokenizer')) {
$this->showExtensionNotLoadedMessage(
'tokenizer', 'No code coverage will be generated.'
);
continue;
}
if (!extension_loaded('xdebug')) {
$this->showExtensionNotLoadedMessage(
'Xdebug', 'No code coverage will be generated.'
);
continue;
}
switch ($option[0]) {
case '--coverage-clover': {
$this->arguments['coverageClover'] = $option[1];
}
break;
case '--coverage-html': {
$this->arguments['reportDirectory'] = $option[1];
}
break;
case '--coverage-php': {
$this->arguments['coveragePHP'] = $option[1];
}
break;
case '--coverage-text': {
if ($option[1] === NULL) {
$option[1] = 'php://stdout';
}
$this->arguments['coverageText'] = $option[1];
$this->arguments['coverageTextShowUncoveredFiles'] = FALSE;
}
break;
}
}
break;
case 'd': {
$ini = explode('=', $option[1]);
if (isset($ini[0])) {
if (isset($ini[1])) {
ini_set($ini[0], $ini[1]);
} else {
ini_set($ini[0], TRUE);
}
}
}
break;
case '--debug': {
$this->arguments['debug'] = TRUE;
}
break;
case 'h':
case '--help': {
$this->showHelp();
exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
}
break;
case '--filter': {
$this->arguments['filter'] = $option[1];
}
break;
case '--testsuite': {
$this->arguments['testsuite'] = $option[1];
}
break;
case '--group': {
$this->arguments['groups'] = explode(',', $option[1]);
}
break;
case '--exclude-group': {
$this->arguments['excludeGroups'] = explode(
',', $option[1]
);
}
break;
case '--test-suffix': {
$this->arguments['testSuffixes'] = explode(
',', $option[1]
);
}
break;
case '--include-path': {
$includePath = $option[1];
}
break;
case '--list-groups': {
$this->arguments['listGroups'] = TRUE;
}
break;
case '--printer': {
$this->arguments['printer'] = $option[1];
}
break;
case '--loader': {
$this->arguments['loader'] = $option[1];
}
break;
case '--log-json': {
$this->arguments['jsonLogfile'] = $option[1];
}
break;
case '--log-junit': {
$this->arguments['junitLogfile'] = $option[1];
}
break;
case '--log-tap': {
$this->arguments['tapLogfile'] = $option[1];
}
break;
case '--process-isolation': {
$this->arguments['processIsolation'] = TRUE;
}
break;
case '--repeat': {
$this->arguments['repeat'] = (int)$option[1];
}
break;
case '--stderr': {
$this->arguments['printer'] = new PHPUnit_TextUI_ResultPrinter(
'php://stderr',
isset($this->arguments['verbose']) ? $this->arguments['verbose'] : FALSE
);
}
break;
case '--stop-on-error': {
$this->arguments['stopOnError'] = TRUE;
}
break;
case '--stop-on-failure': {
$this->arguments['stopOnFailure'] = TRUE;
}
break;
case '--stop-on-incomplete': {
$this->arguments['stopOnIncomplete'] = TRUE;
}
break;
case '--stop-on-skipped': {
$this->arguments['stopOnSkipped'] = TRUE;
}
break;
case '--tap': {
$this->arguments['printer'] = new PHPUnit_Util_Log_TAP;
}
break;
case '--testdox': {
$this->arguments['printer'] = new PHPUnit_Util_TestDox_ResultPrinter_Text;
}
break;
case '--testdox-html': {
$this->arguments['testdoxHTMLFile'] = $option[1];
}
break;
case '--testdox-text': {
$this->arguments['testdoxTextFile'] = $option[1];
}
break;
case '--no-configuration': {
$this->arguments['useDefaultConfiguration'] = FALSE;
}
break;
case '--no-globals-backup': {
$this->arguments['backupGlobals'] = FALSE;
}
break;
case '--static-backup': {
$this->arguments['backupStaticAttributes'] = TRUE;
}
break;
case 'v':
case '--verbose': {
$this->arguments['verbose'] = TRUE;
}
break;
case '--version': {
PHPUnit_TextUI_TestRunner::printVersionString();
exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
}
break;
case '--strict': {
$this->arguments['strict'] = TRUE;
}
break;
default: {
$optionName = str_replace('--', '', $option[0]);
if (isset($this->longOptions[$optionName])) {
$handler = $this->longOptions[$optionName];
}
else if (isset($this->longOptions[$optionName . '='])) {
$handler = $this->longOptions[$optionName . '='];
}
if (isset($handler) && is_callable(array($this, $handler))) {
$this->$handler($option[1]);
}
}
}
}
$this->handleCustomTestSuite();
if (!isset($this->arguments['test'])) {
if (isset($this->options[1][0])) {
$this->arguments['test'] = $this->options[1][0];
}
if (isset($this->options[1][1])) {
$this->arguments['testFile'] = $this->options[1][1];
} else {
$this->arguments['testFile'] = '';
}
if (isset($this->arguments['test']) &&
is_file($this->arguments['test']) &&
substr($this->arguments['test'], -5, 5) != '.phpt') {
$this->arguments['testFile'] = realpath($this->arguments['test']);
$this->arguments['test'] = substr($this->arguments['test'], 0, strrpos($this->arguments['test'], '.'));
}
}
if (!isset($this->arguments['testSuffixes'])) {
$this->arguments['testSuffixes'] = array('Test.php', '.phpt');
}
if (isset($includePath)) {
ini_set(
'include_path',
$includePath . PATH_SEPARATOR . ini_get('include_path')
);
}
if (isset($this->arguments['bootstrap'])) {
$this->handleBootstrap($this->arguments['bootstrap']);
}
if (isset($this->arguments['printer']) &&
is_string($this->arguments['printer'])) {
$this->arguments['printer'] = $this->handlePrinter($this->arguments['printer']);
}
if ($this->arguments['loader'] !== NULL) {
$this->arguments['loader'] = $this->handleLoader($this->arguments['loader']);
}
if (isset($this->arguments['configuration']) &&
is_dir($this->arguments['configuration'])) {
$configurationFile = $this->arguments['configuration'] .
'/phpunit.xml';
if (file_exists($configurationFile)) {
$this->arguments['configuration'] = realpath(
$configurationFile
);
}
else if (file_exists($configurationFile . '.dist')) {
$this->arguments['configuration'] = realpath(
$configurationFile . '.dist'
);
}
}
else if (!isset($this->arguments['configuration']) &&
$this->arguments['useDefaultConfiguration']) {
if (file_exists('phpunit.xml')) {
$this->arguments['configuration'] = realpath('phpunit.xml');
} else if (file_exists('phpunit.xml.dist')) {
$this->arguments['configuration'] = realpath(
'phpunit.xml.dist'
);
}
}
if (isset($this->arguments['configuration'])) {
try {
$configuration = PHPUnit_Util_Configuration::getInstance(
$this->arguments['configuration']
);
}
catch (Exception $e) {
print $e->getMessage() . "\n";
exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
}
$phpunit = $configuration->getPHPUnitConfiguration();
$configuration->handlePHPConfiguration();
if (!isset($this->arguments['bootstrap']) && isset($phpunit['bootstrap'])) {
$this->handleBootstrap($phpunit['bootstrap']);
}
if (isset($phpunit['printerClass'])) {
if (isset($phpunit['printerFile'])) {
$file = $phpunit['printerFile'];
} else {
$file = '';
}
$this->arguments['printer'] = $this->handlePrinter(
$phpunit['printerClass'], $file
);
}
if (isset($phpunit['testSuiteLoaderClass'])) {
if (isset($phpunit['testSuiteLoaderFile'])) {
$file = $phpunit['testSuiteLoaderFile'];
} else {
$file = '';
}
$this->arguments['loader'] = $this->handleLoader(
$phpunit['testSuiteLoaderClass'], $file
);
}
$logging = $configuration->getLoggingConfiguration();
if (isset($logging['coverage-html']) || isset($logging['coverage-clover']) || isset($logging['coverage-text']) ) {
if (!extension_loaded('tokenizer')) {
$this->showExtensionNotLoadedMessage(
'tokenizer', 'No code coverage will be generated.'
);
}
else if (!extension_loaded('Xdebug')) {
$this->showExtensionNotLoadedMessage(
'Xdebug', 'No code coverage will be generated.'
);
}
}
$browsers = $configuration->getSeleniumBrowserConfiguration();
if (!empty($browsers) &&
class_exists('PHPUnit_Extensions_SeleniumTestCase')) {
PHPUnit_Extensions_SeleniumTestCase::$browsers = $browsers;
}
if (!isset($this->arguments['test'])) {
$testSuite = $configuration->getTestSuiteConfiguration(isset($this->arguments['testsuite']) ? $this->arguments['testsuite'] : null);
if ($testSuite !== NULL) {
$this->arguments['test'] = $testSuite;
}
}
}
if (isset($this->arguments['test']) && is_string($this->arguments['test']) && substr($this->arguments['test'], -5, 5) == '.phpt') {
$test = new PHPUnit_Extensions_PhptTestCase($this->arguments['test']);
$this->arguments['test'] = new PHPUnit_Framework_TestSuite;
$this->arguments['test']->addTest($test);
}
if (!isset($this->arguments['test']) ||
(isset($this->arguments['testDatabaseLogRevision']) && !isset($this->arguments['testDatabaseDSN']))) {
$this->showHelp();
exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
}
}
/**
* Handles the loading of the PHPUnit_Runner_TestSuiteLoader implementation.
*
* @param string $loaderClass
* @param string $loaderFile
* @return PHPUnit_Runner_TestSuiteLoader
*/
protected function handleLoader($loaderClass, $loaderFile = '')
{
if (!class_exists($loaderClass, FALSE)) {
if ($loaderFile == '') {
$loaderFile = PHPUnit_Util_Filesystem::classNameToFilename(
$loaderClass
);
}
$loaderFile = stream_resolve_include_path($loaderFile);
if ($loaderFile) {
require $loaderFile;
}
}
if (class_exists($loaderClass, FALSE)) {
$class = new ReflectionClass($loaderClass);
if ($class->implementsInterface('PHPUnit_Runner_TestSuiteLoader') &&
$class->isInstantiable()) {
$loader = $class->newInstance();
}
}
if (!isset($loader)) {
PHPUnit_TextUI_TestRunner::showError(
sprintf(
'Could not use "%s" as loader.',
$loaderClass
)
);
}
return $loader;
}
/**
* Handles the loading of the PHPUnit_Util_Printer implementation.
*
* @param string $printerClass
* @param string $printerFile
* @return PHPUnit_Util_Printer
*/
protected function handlePrinter($printerClass, $printerFile = '')
{
if (!class_exists($printerClass, FALSE)) {
if ($printerFile == '') {
$printerFile = PHPUnit_Util_Filesystem::classNameToFilename(
$printerClass
);
}
$printerFile = stream_resolve_include_path($printerFile);
if ($printerFile) {
require $printerFile;
}
}
if (class_exists($printerClass, FALSE)) {
$class = new ReflectionClass($printerClass);
if ($class->implementsInterface('PHPUnit_Framework_TestListener') &&
$class->isSubclassOf('PHPUnit_Util_Printer') &&
$class->isInstantiable()) {
$printer = $class->newInstance();
}
}
if (!isset($printer)) {
PHPUnit_TextUI_TestRunner::showError(
sprintf(
'Could not use "%s" as printer.',
$printerClass
)
);
}
return $printer;
}
/**
* Loads a bootstrap file.
*
* @param string $filename
*/
protected function handleBootstrap($filename)
{
try {
PHPUnit_Util_Fileloader::checkAndLoad($filename);
}
catch (PHPUnit_Framework_Exception $e) {
PHPUnit_TextUI_TestRunner::showError($e->getMessage());
}
}
/**
* @param string $message
* @since Method available since Release 3.6.0
*/
protected function showExtensionNotLoadedMessage($extension, $message = '')
{
if (isset($this->missingExtensions[$extension])) {
return;
}
if (!empty($message)) {
$message = ' ' . $message;
}
$this->showMessage(
'The ' . $extension . ' extension is not loaded.' . $message . "\n",
FALSE
);
$this->missingExtensions[$extension] = TRUE;
}
/**
* Shows a message.
*
* @param string $message
* @param boolean $exit
*/
protected function showMessage($message, $exit = TRUE)
{
PHPUnit_TextUI_TestRunner::printVersionString();
print $message . "\n";
if ($exit) {
exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
} else {
print "\n";
}
}
/**
* Show the help message.
*/
protected function showHelp()
{
PHPUnit_TextUI_TestRunner::printVersionString();
print <<<EOT
Usage: phpunit [switches] UnitTest [UnitTest.php]
phpunit [switches] <directory>
--log-junit <file> Log test execution in JUnit XML format to file.
--log-tap <file> Log test execution in TAP format to file.
--log-json <file> Log test execution in JSON format.
--coverage-clover <file> Generate code coverage report in Clover XML format.
--coverage-html <dir> Generate code coverage report in HTML format.
--coverage-php <file> Serialize PHP_CodeCoverage object to file.
--coverage-text=<file> Generate code coverage report in text format.
Default to writing to the standard output.
--testdox-html <file> Write agile documentation in HTML format to file.
--testdox-text <file> Write agile documentation in Text format to file.
--filter <pattern> Filter which tests to run.
--testsuite <pattern> Filter which testsuite to run.
--group ... Only runs tests from the specified group(s).
--exclude-group ... Exclude tests from the specified group(s).
--list-groups List available test groups.
--test-suffix ... Only search for test in files with specified
suffix(es). Default: Test.php,.phpt
--loader <loader> TestSuiteLoader implementation to use.
--printer <printer> TestSuiteListener implementation to use.
--repeat <times> Runs the test(s) repeatedly.
--tap Report test execution progress in TAP format.
--testdox Report test execution progress in TestDox format.
--colors Use colors in output.
--stderr Write to STDERR instead of STDOUT.
--stop-on-error Stop execution upon first error.
--stop-on-failure Stop execution upon first error or failure.
--stop-on-skipped Stop execution upon first skipped test.
--stop-on-incomplete Stop execution upon first incomplete test.
--strict Run tests in strict mode.
-v|--verbose Output more verbose information.
--debug Display debugging information during test execution.
--process-isolation Run each test in a separate PHP process.
--no-globals-backup Do not backup and restore \$GLOBALS for each test.
--static-backup Backup and restore static attributes for each test.
--bootstrap <file> A "bootstrap" PHP file that is run before the tests.
-c|--configuration <file> Read configuration from XML file.
--no-configuration Ignore default configuration file (phpunit.xml).
--include-path <path(s)> Prepend PHP's include_path with given path(s).
-d key[=value] Sets a php.ini value.
-h|--help Prints this usage information.
--version Prints the version and exits.
EOT;
}
/**
* Custom callback for test suite discovery.
*/
protected function handleCustomTestSuite()
{
}
}

View File

@@ -0,0 +1,664 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2001-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit
* @subpackage TextUI
* @author Sebastian Bergmann <sebastian@phpunit.de>
* @copyright 2001-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 2.0.0
*/
/**
* Prints the result of a TextUI TestRunner run.
*
* @package PHPUnit
* @subpackage TextUI
* @author Sebastian Bergmann <sebastian@phpunit.de>
* @copyright 2001-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since Class available since Release 2.0.0
*/
class PHPUnit_TextUI_ResultPrinter extends PHPUnit_Util_Printer implements PHPUnit_Framework_TestListener
{
const EVENT_TEST_START = 0;
const EVENT_TEST_END = 1;
const EVENT_TESTSUITE_START = 2;
const EVENT_TESTSUITE_END = 3;
/**
* @var integer
*/
protected $column = 0;
/**
* @var integer
*/
protected $maxColumn;
/**
* @var boolean
*/
protected $lastTestFailed = FALSE;
/**
* @var integer
*/
protected $numAssertions = 0;
/**
* @var integer
*/
protected $numTests = -1;
/**
* @var integer
*/
protected $numTestsRun = 0;
/**
* @var integer
*/
protected $numTestsWidth;
/**
* @var boolean
*/
protected $colors = FALSE;
/**
* @var boolean
*/
protected $debug = FALSE;
/**
* @var boolean
*/
protected $verbose = FALSE;
/**
* Constructor.
*
* @param mixed $out
* @param boolean $verbose
* @param boolean $colors
* @param boolean $debug
* @throws PHPUnit_Framework_Exception
* @since Method available since Release 3.0.0
*/
public function __construct($out = NULL, $verbose = FALSE, $colors = FALSE, $debug = FALSE)
{
parent::__construct($out);
if (is_bool($verbose)) {
$this->verbose = $verbose;
} else {
throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'boolean');
}
if (is_bool($colors)) {
$this->colors = $colors;
} else {
throw PHPUnit_Util_InvalidArgumentHelper::factory(3, 'boolean');
}
if (is_bool($debug)) {
$this->debug = $debug;
} else {
throw PHPUnit_Util_InvalidArgumentHelper::factory(4, 'boolean');
}
}
/**
* @param PHPUnit_Framework_TestResult $result
*/
public function printResult(PHPUnit_Framework_TestResult $result)
{
$this->printHeader();
if ($result->errorCount() > 0) {
$this->printErrors($result);
}
if ($result->failureCount() > 0) {
if ($result->errorCount() > 0) {
print "\n--\n\n";
}
$this->printFailures($result);
}
if ($this->verbose) {
if ($result->deprecatedFeaturesCount() > 0) {
if ($result->failureCount() > 0) {
print "\n--\n\nDeprecated PHPUnit features are being used";
}
foreach ($result->deprecatedFeatures() as $deprecatedFeature) {
$this->write($deprecatedFeature . "\n\n");
}
}
if ($result->notImplementedCount() > 0) {
if ($result->failureCount() > 0) {
print "\n--\n\n";
}
$this->printIncompletes($result);
}
if ($result->skippedCount() > 0) {
if ($result->notImplementedCount() > 0) {
print "\n--\n\n";
}
$this->printSkipped($result);
}
}
$this->printFooter($result);
}
/**
* @param array $defects
* @param integer $count
* @param string $type
*/
protected function printDefects(array $defects, $count, $type)
{
static $called = FALSE;
if ($count == 0) {
return;
}
$this->write(
sprintf(
"%sThere %s %d %s%s:\n",
$called ? "\n" : '',
($count == 1) ? 'was' : 'were',
$count,
$type,
($count == 1) ? '' : 's'
)
);
$i = 1;
foreach ($defects as $defect) {
$this->printDefect($defect, $i++);
}
$called = TRUE;
}
/**
* @param PHPUnit_Framework_TestFailure $defect
* @param integer $count
*/
protected function printDefect(PHPUnit_Framework_TestFailure $defect, $count)
{
$this->printDefectHeader($defect, $count);
$this->printDefectTrace($defect);
}
/**
* @param PHPUnit_Framework_TestFailure $defect
* @param integer $count
*/
protected function printDefectHeader(PHPUnit_Framework_TestFailure $defect, $count)
{
$failedTest = $defect->failedTest();
if ($failedTest instanceof PHPUnit_Framework_SelfDescribing) {
$testName = $failedTest->toString();
} else {
$testName = get_class($failedTest);
}
$this->write(
sprintf(
"\n%d) %s\n",
$count,
$testName
)
);
}
/**
* @param PHPUnit_Framework_TestFailure $defect
*/
protected function printDefectTrace(PHPUnit_Framework_TestFailure $defect)
{
$this->write(
$defect->getExceptionAsString() . "\n" .
PHPUnit_Util_Filter::getFilteredStacktrace(
$defect->thrownException()
)
);
$e = $defect->thrownException()->getPrevious();
while ($e) {
$this->write(
"\nCaused by\n" .
PHPUnit_Framework_TestFailure::exceptionToString($e). "\n" .
PHPUnit_Util_Filter::getFilteredStacktrace($e)
);
$e = $e->getPrevious();
}
}
/**
* @param PHPUnit_Framework_TestResult $result
*/
protected function printErrors(PHPUnit_Framework_TestResult $result)
{
$this->printDefects($result->errors(), $result->errorCount(), 'error');
}
/**
* @param PHPUnit_Framework_TestResult $result
*/
protected function printFailures(PHPUnit_Framework_TestResult $result)
{
$this->printDefects(
$result->failures(),
$result->failureCount(),
'failure'
);
}
/**
* @param PHPUnit_Framework_TestResult $result
*/
protected function printIncompletes(PHPUnit_Framework_TestResult $result)
{
$this->printDefects(
$result->notImplemented(),
$result->notImplementedCount(),
'incomplete test'
);
}
/**
* @param PHPUnit_Framework_TestResult $result
* @since Method available since Release 3.0.0
*/
protected function printSkipped(PHPUnit_Framework_TestResult $result)
{
$this->printDefects(
$result->skipped(),
$result->skippedCount(),
'skipped test'
);
}
protected function printHeader()
{
$this->write("\n\n" . PHP_Timer::resourceUsage() . "\n\n");
}
/**
* @param PHPUnit_Framework_TestResult $result
*/
protected function printFooter(PHPUnit_Framework_TestResult $result)
{
if (count($result) === 0) {
if ($this->colors) {
$this->write("\x1b[30;43m\x1b[2K");
}
$this->write(
"No tests executed!\n"
);
if ($this->colors) {
$this->write("\x1b[0m\x1b[2K");
}
}
else if ($result->wasSuccessful() &&
$result->allCompletelyImplemented() &&
$result->noneSkipped()) {
if ($this->colors) {
$this->write("\x1b[30;42m\x1b[2K");
}
$this->write(
sprintf(
"OK (%d test%s, %d assertion%s)\n",
count($result),
(count($result) == 1) ? '' : 's',
$this->numAssertions,
($this->numAssertions == 1) ? '' : 's'
)
);
if ($this->colors) {
$this->write("\x1b[0m\x1b[2K");
}
}
else if ((!$result->allCompletelyImplemented() ||
!$result->noneSkipped()) &&
$result->wasSuccessful()) {
if ($this->colors) {
$this->write(
"\x1b[30;43m\x1b[2KOK, but incomplete or skipped tests!\n" .
"\x1b[0m\x1b[30;43m\x1b[2K"
);
} else {
$this->write("OK, but incomplete or skipped tests!\n");
}
$this->write(
sprintf(
"Tests: %d, Assertions: %d%s%s.\n",
count($result),
$this->numAssertions,
$this->getCountString(
$result->notImplementedCount(), 'Incomplete'
),
$this->getCountString(
$result->skippedCount(), 'Skipped'
)
)
);
if ($this->colors) {
$this->write("\x1b[0m\x1b[2K");
}
}
else {
$this->write("\n");
if ($this->colors) {
$this->write(
"\x1b[37;41m\x1b[2KFAILURES!\n\x1b[0m\x1b[37;41m\x1b[2K"
);
} else {
$this->write("FAILURES!\n");
}
$this->write(
sprintf(
"Tests: %d, Assertions: %s%s%s%s%s.\n",
count($result),
$this->numAssertions,
$this->getCountString($result->failureCount(), 'Failures'),
$this->getCountString($result->errorCount(), 'Errors'),
$this->getCountString(
$result->notImplementedCount(), 'Incomplete'
),
$this->getCountString($result->skippedCount(), 'Skipped')
)
);
if ($this->colors) {
$this->write("\x1b[0m\x1b[2K");
}
}
if (!$this->verbose &&
$result->deprecatedFeaturesCount() > 0) {
$message = sprintf(
"Warning: Deprecated PHPUnit features are being used %s times!\n" .
"Use --verbose for more information.\n",
$result->deprecatedFeaturesCount()
);
if ($this->colors) {
$message = "\x1b[37;41m\x1b[2K" . $message .
"\x1b[0m";
}
$this->write("\n" . $message);
}
}
/**
* @param integer $count
* @param string $name
* @return string
* @since Method available since Release 3.0.0
*/
protected function getCountString($count, $name)
{
$string = '';
if ($count > 0) {
$string = sprintf(
', %s: %d',
$name,
$count
);
}
return $string;
}
/**
*/
public function printWaitPrompt()
{
$this->write("\n<RETURN> to continue\n");
}
/**
* An error occurred.
*
* @param PHPUnit_Framework_Test $test
* @param Exception $e
* @param float $time
*/
public function addError(PHPUnit_Framework_Test $test, Exception $e, $time)
{
if ($this->colors) {
$this->writeProgress("\x1b[31;1mE\x1b[0m");
} else {
$this->writeProgress('E');
}
$this->lastTestFailed = TRUE;
}
/**
* A failure occurred.
*
* @param PHPUnit_Framework_Test $test
* @param PHPUnit_Framework_AssertionFailedError $e
* @param float $time
*/
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
{
if ($this->colors) {
$this->writeProgress("\x1b[41;37mF\x1b[0m");
} else {
$this->writeProgress('F');
}
$this->lastTestFailed = TRUE;
}
/**
* Incomplete test.
*
* @param PHPUnit_Framework_Test $test
* @param Exception $e
* @param float $time
*/
public function addIncompleteTest(PHPUnit_Framework_Test $test, Exception $e, $time)
{
if ($this->colors) {
$this->writeProgress("\x1b[33;1mI\x1b[0m");
} else {
$this->writeProgress('I');
}
$this->lastTestFailed = TRUE;
}
/**
* Skipped test.
*
* @param PHPUnit_Framework_Test $test
* @param Exception $e
* @param float $time
* @since Method available since Release 3.0.0
*/
public function addSkippedTest(PHPUnit_Framework_Test $test, Exception $e, $time)
{
if ($this->colors) {
$this->writeProgress("\x1b[36;1mS\x1b[0m");
} else {
$this->writeProgress('S');
}
$this->lastTestFailed = TRUE;
}
/**
* A testsuite started.
*
* @param PHPUnit_Framework_TestSuite $suite
* @since Method available since Release 2.2.0
*/
public function startTestSuite(PHPUnit_Framework_TestSuite $suite)
{
if ($this->numTests == -1) {
$this->numTests = count($suite);
$this->numTestsWidth = strlen((string)$this->numTests);
$this->maxColumn = 69 - (2 * $this->numTestsWidth);
}
}
/**
* A testsuite ended.
*
* @param PHPUnit_Framework_TestSuite $suite
* @since Method available since Release 2.2.0
*/
public function endTestSuite(PHPUnit_Framework_TestSuite $suite)
{
}
/**
* A test started.
*
* @param PHPUnit_Framework_Test $test
*/
public function startTest(PHPUnit_Framework_Test $test)
{
if ($this->debug) {
$this->write(
sprintf(
"\nStarting test '%s'.\n", PHPUnit_Util_Test::describe($test)
)
);
}
}
/**
* A test ended.
*
* @param PHPUnit_Framework_Test $test
* @param float $time
*/
public function endTest(PHPUnit_Framework_Test $test, $time)
{
if (!$this->lastTestFailed) {
$this->writeProgress('.');
}
if ($test instanceof PHPUnit_Framework_TestCase) {
$this->numAssertions += $test->getNumAssertions();
}
else if ($test instanceof PHPUnit_Extensions_PhptTestCase) {
$this->numAssertions++;
}
$this->lastTestFailed = FALSE;
if ($test instanceof PHPUnit_Framework_TestCase) {
if (!$test->hasPerformedExpectationsOnOutput()) {
$this->write($test->getActualOutput());
}
}
}
/**
* @param string $progress
*/
protected function writeProgress($progress)
{
$this->write($progress);
$this->column++;
$this->numTestsRun++;
if ($this->column == $this->maxColumn) {
$this->write(
sprintf(
' %' . $this->numTestsWidth . 'd / %' .
$this->numTestsWidth . 'd (%3s%%)',
$this->numTestsRun,
$this->numTests,
floor(($this->numTestsRun / $this->numTests) * 100)
)
);
$this->writeNewLine();
}
}
protected function writeNewLine()
{
$this->column = 0;
$this->write("\n");
}
}

View File

@@ -0,0 +1,817 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2001-2013, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package PHPUnit
* @subpackage TextUI
* @author Sebastian Bergmann <sebastian@phpunit.de>
* @copyright 2001-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since File available since Release 2.0.0
*/
/**
* A TestRunner for the Command Line Interface (CLI)
* PHP SAPI Module.
*
* @package PHPUnit
* @subpackage TextUI
* @author Sebastian Bergmann <sebastian@phpunit.de>
* @copyright 2001-2013 Sebastian Bergmann <sebastian@phpunit.de>
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
* @link http://www.phpunit.de/
* @since Class available since Release 2.0.0
*/
class PHPUnit_TextUI_TestRunner extends PHPUnit_Runner_BaseTestRunner
{
const SUCCESS_EXIT = 0;
const FAILURE_EXIT = 1;
const EXCEPTION_EXIT = 2;
/**
* @var PHP_CodeCoverage_Filter
*/
protected $codeCoverageFilter;
/**
* @var PHPUnit_Runner_TestSuiteLoader
*/
protected $loader = NULL;
/**
* @var PHPUnit_TextUI_ResultPrinter
*/
protected $printer = NULL;
/**
* @var boolean
*/
protected static $versionStringPrinted = FALSE;
/**
* @param PHPUnit_Runner_TestSuiteLoader $loader
* @param PHP_CodeCoverage_Filter $filter
* @since Method available since Release 3.4.0
*/
public function __construct(PHPUnit_Runner_TestSuiteLoader $loader = NULL, PHP_CodeCoverage_Filter $filter = NULL)
{
if ($filter === NULL) {
$filter = new PHP_CodeCoverage_Filter;
}
$this->codeCoverageFilter = $filter;
$this->loader = $loader;
}
/**
* @param mixed $test
* @param array $arguments
* @throws PHPUnit_Framework_Exception
*/
public static function run($test, array $arguments = array())
{
if ($test instanceof ReflectionClass) {
$test = new PHPUnit_Framework_TestSuite($test);
}
if ($test instanceof PHPUnit_Framework_Test) {
$aTestRunner = new PHPUnit_TextUI_TestRunner;
return $aTestRunner->doRun(
$test,
$arguments
);
} else {
throw new PHPUnit_Framework_Exception(
'No test case or test suite found.'
);
}
}
/**
* @return PHPUnit_Framework_TestResult
*/
protected function createTestResult()
{
return new PHPUnit_Framework_TestResult;
}
/**
* @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 &&
!self::$versionStringPrinted) {
$this->printer->write(
PHPUnit_Runner_Version::getVersionString() . "\n\n"
);
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;
}
/**
* @param PHPUnit_TextUI_ResultPrinter $resultPrinter
*/
public function setPrinter(PHPUnit_TextUI_ResultPrinter $resultPrinter)
{
$this->printer = $resultPrinter;
}
/**
* Override to define how to handle a failed loading of
* a test suite.
*
* @param string $message
*/
protected function runFailed($message)
{
self::printVersionString();
self::write($message . PHP_EOL);
exit(self::FAILURE_EXIT);
}
/**
* @param string $buffer
* @since Method available since Release 3.1.0
*/
protected static function write($buffer)
{
if (PHP_SAPI != 'cli') {
$buffer = htmlspecialchars($buffer);
}
print $buffer;
}
/**
* Returns the loader to be used.
*
* @return PHPUnit_Runner_TestSuiteLoader
* @since Method available since Release 2.2.0
*/
public function getLoader()
{
if ($this->loader === NULL) {
$this->loader = new PHPUnit_Runner_StandardTestSuiteLoader;
}
return $this->loader;
}
/**
*/
public static function showError($message)
{
self::printVersionString();
self::write($message . "\n");
exit(self::FAILURE_EXIT);
}
/**
*/
public static function printVersionString()
{
if (!self::$versionStringPrinted) {
self::write(PHPUnit_Runner_Version::getVersionString() . "\n\n");
self::$versionStringPrinted = TRUE;
}
}
/**
* @param array $arguments
* @since Method available since Release 3.2.1
*/
protected function handleConfiguration(array &$arguments)
{
if (isset($arguments['configuration']) &&
!$arguments['configuration'] instanceof PHPUnit_Util_Configuration) {
$arguments['configuration'] = PHPUnit_Util_Configuration::getInstance(
$arguments['configuration']
);
}
$arguments['debug'] = isset($arguments['debug']) ? $arguments['debug'] : FALSE;
$arguments['filter'] = isset($arguments['filter']) ? $arguments['filter'] : FALSE;
$arguments['listeners'] = isset($arguments['listeners']) ? $arguments['listeners'] : array();
if (isset($arguments['configuration'])) {
$arguments['configuration']->handlePHPConfiguration();
$phpunitConfiguration = $arguments['configuration']->getPHPUnitConfiguration();
if (isset($phpunitConfiguration['backupGlobals']) &&
!isset($arguments['backupGlobals'])) {
$arguments['backupGlobals'] = $phpunitConfiguration['backupGlobals'];
}
if (isset($phpunitConfiguration['backupStaticAttributes']) &&
!isset($arguments['backupStaticAttributes'])) {
$arguments['backupStaticAttributes'] = $phpunitConfiguration['backupStaticAttributes'];
}
if (isset($phpunitConfiguration['bootstrap']) &&
!isset($arguments['bootstrap'])) {
$arguments['bootstrap'] = $phpunitConfiguration['bootstrap'];
}
if (isset($phpunitConfiguration['cacheTokens']) &&
!isset($arguments['cacheTokens'])) {
$arguments['cacheTokens'] = $phpunitConfiguration['cacheTokens'];
}
if (isset($phpunitConfiguration['colors']) &&
!isset($arguments['colors'])) {
$arguments['colors'] = $phpunitConfiguration['colors'];
}
if (isset($phpunitConfiguration['convertErrorsToExceptions']) &&
!isset($arguments['convertErrorsToExceptions'])) {
$arguments['convertErrorsToExceptions'] = $phpunitConfiguration['convertErrorsToExceptions'];
}
if (isset($phpunitConfiguration['convertNoticesToExceptions']) &&
!isset($arguments['convertNoticesToExceptions'])) {
$arguments['convertNoticesToExceptions'] = $phpunitConfiguration['convertNoticesToExceptions'];
}
if (isset($phpunitConfiguration['convertWarningsToExceptions']) &&
!isset($arguments['convertWarningsToExceptions'])) {
$arguments['convertWarningsToExceptions'] = $phpunitConfiguration['convertWarningsToExceptions'];
}
if (isset($phpunitConfiguration['processIsolation']) &&
!isset($arguments['processIsolation'])) {
$arguments['processIsolation'] = $phpunitConfiguration['processIsolation'];
}
if (isset($phpunitConfiguration['stopOnFailure']) &&
!isset($arguments['stopOnFailure'])) {
$arguments['stopOnFailure'] = $phpunitConfiguration['stopOnFailure'];
}
if (isset($phpunitConfiguration['timeoutForSmallTests']) &&
!isset($arguments['timeoutForSmallTests'])) {
$arguments['timeoutForSmallTests'] = $phpunitConfiguration['timeoutForSmallTests'];
}
if (isset($phpunitConfiguration['timeoutForMediumTests']) &&
!isset($arguments['timeoutForMediumTests'])) {
$arguments['timeoutForMediumTests'] = $phpunitConfiguration['timeoutForMediumTests'];
}
if (isset($phpunitConfiguration['timeoutForLargeTests']) &&
!isset($arguments['timeoutForLargeTests'])) {
$arguments['timeoutForLargeTests'] = $phpunitConfiguration['timeoutForLargeTests'];
}
if (isset($phpunitConfiguration['strict']) &&
!isset($arguments['strict'])) {
$arguments['strict'] = $phpunitConfiguration['strict'];
}
if (isset($phpunitConfiguration['verbose']) &&
!isset($arguments['verbose'])) {
$arguments['verbose'] = $phpunitConfiguration['verbose'];
}
if (isset($phpunitConfiguration['forceCoversAnnotation']) &&
!isset($arguments['forceCoversAnnotation'])) {
$arguments['forceCoversAnnotation'] = $phpunitConfiguration['forceCoversAnnotation'];
}
if (isset($phpunitConfiguration['mapTestClassNameToCoveredClassName']) &&
!isset($arguments['mapTestClassNameToCoveredClassName'])) {
$arguments['mapTestClassNameToCoveredClassName'] = $phpunitConfiguration['mapTestClassNameToCoveredClassName'];
}
$groupCliArgs = array();
if (!empty($arguments['groups'])) {
$groupCliArgs = $arguments['groups'];
}
$groupConfiguration = $arguments['configuration']->getGroupConfiguration();
if (!empty($groupConfiguration['include']) &&
!isset($arguments['groups'])) {
$arguments['groups'] = $groupConfiguration['include'];
}
if (!empty($groupConfiguration['exclude']) &&
!isset($arguments['excludeGroups'])) {
$arguments['excludeGroups'] = array_diff($groupConfiguration['exclude'], $groupCliArgs);
}
foreach ($arguments['configuration']->getListenerConfiguration() as $listener) {
if (!class_exists($listener['class'], FALSE) &&
$listener['file'] !== '') {
require_once $listener['file'];
}
if (class_exists($listener['class'])) {
if (count($listener['arguments']) == 0) {
$listener = new $listener['class'];
} else {
$listenerClass = new ReflectionClass(
$listener['class']
);
$listener = $listenerClass->newInstanceArgs(
$listener['arguments']
);
}
if ($listener instanceof PHPUnit_Framework_TestListener) {
$arguments['listeners'][] = $listener;
}
}
}
$loggingConfiguration = $arguments['configuration']->getLoggingConfiguration();
if (isset($loggingConfiguration['coverage-html']) &&
!isset($arguments['reportDirectory'])) {
if (isset($loggingConfiguration['charset']) &&
!isset($arguments['reportCharset'])) {
$arguments['reportCharset'] = $loggingConfiguration['charset'];
}
if (isset($loggingConfiguration['highlight']) &&
!isset($arguments['reportHighlight'])) {
$arguments['reportHighlight'] = $loggingConfiguration['highlight'];
}
if (isset($loggingConfiguration['lowUpperBound']) &&
!isset($arguments['reportLowUpperBound'])) {
$arguments['reportLowUpperBound'] = $loggingConfiguration['lowUpperBound'];
}
if (isset($loggingConfiguration['highLowerBound']) &&
!isset($arguments['reportHighLowerBound'])) {
$arguments['reportHighLowerBound'] = $loggingConfiguration['highLowerBound'];
}
$arguments['reportDirectory'] = $loggingConfiguration['coverage-html'];
}
if (isset($loggingConfiguration['coverage-clover']) &&
!isset($arguments['coverageClover'])) {
$arguments['coverageClover'] = $loggingConfiguration['coverage-clover'];
}
if (isset($loggingConfiguration['coverage-php']) &&
!isset($arguments['coveragePHP'])) {
$arguments['coveragePHP'] = $loggingConfiguration['coverage-php'];
}
if (isset($loggingConfiguration['coverage-text']) &&
!isset($arguments['coverageText'])) {
$arguments['coverageText'] = $loggingConfiguration['coverage-text'];
if (isset($loggingConfiguration['coverageTextShowUncoveredFiles'])) {
$arguments['coverageTextShowUncoveredFiles'] = $loggingConfiguration['coverageTextShowUncoveredFiles'];
} else {
$arguments['coverageTextShowUncoveredFiles'] = FALSE;
}
}
if (isset($loggingConfiguration['json']) &&
!isset($arguments['jsonLogfile'])) {
$arguments['jsonLogfile'] = $loggingConfiguration['json'];
}
if (isset($loggingConfiguration['plain'])) {
$arguments['listeners'][] = new PHPUnit_TextUI_ResultPrinter(
$loggingConfiguration['plain'], TRUE
);
}
if (isset($loggingConfiguration['tap']) &&
!isset($arguments['tapLogfile'])) {
$arguments['tapLogfile'] = $loggingConfiguration['tap'];
}
if (isset($loggingConfiguration['junit']) &&
!isset($arguments['junitLogfile'])) {
$arguments['junitLogfile'] = $loggingConfiguration['junit'];
if (isset($loggingConfiguration['logIncompleteSkipped']) &&
!isset($arguments['logIncompleteSkipped'])) {
$arguments['logIncompleteSkipped'] = $loggingConfiguration['logIncompleteSkipped'];
}
}
if (isset($loggingConfiguration['testdox-html']) &&
!isset($arguments['testdoxHTMLFile'])) {
$arguments['testdoxHTMLFile'] = $loggingConfiguration['testdox-html'];
}
if (isset($loggingConfiguration['testdox-text']) &&
!isset($arguments['testdoxTextFile'])) {
$arguments['testdoxTextFile'] = $loggingConfiguration['testdox-text'];
}
if ((isset($arguments['coverageClover']) ||
isset($arguments['reportDirectory']) ||
isset($arguments['coveragePHP']) ||
isset($arguments['coverageText'])) &&
extension_loaded('xdebug')) {
$filterConfiguration = $arguments['configuration']->getFilterConfiguration();
$arguments['addUncoveredFilesFromWhitelist'] = $filterConfiguration['whitelist']['addUncoveredFilesFromWhitelist'];
$arguments['processUncoveredFilesFromWhitelist'] = $filterConfiguration['whitelist']['processUncoveredFilesFromWhitelist'];
foreach ($filterConfiguration['blacklist']['include']['directory'] as $dir) {
$this->codeCoverageFilter->addDirectoryToBlacklist(
$dir['path'], $dir['suffix'], $dir['prefix'], $dir['group']
);
}
foreach ($filterConfiguration['blacklist']['include']['file'] as $file) {
$this->codeCoverageFilter->addFileToBlacklist($file);
}
foreach ($filterConfiguration['blacklist']['exclude']['directory'] as $dir) {
$this->codeCoverageFilter->removeDirectoryFromBlacklist(
$dir['path'], $dir['suffix'], $dir['prefix'], $dir['group']
);
}
foreach ($filterConfiguration['blacklist']['exclude']['file'] as $file) {
$this->codeCoverageFilter->removeFileFromBlacklist($file);
}
foreach ($filterConfiguration['whitelist']['include']['directory'] as $dir) {
$this->codeCoverageFilter->addDirectoryToWhitelist(
$dir['path'], $dir['suffix'], $dir['prefix']
);
}
foreach ($filterConfiguration['whitelist']['include']['file'] as $file) {
$this->codeCoverageFilter->addFileToWhitelist($file);
}
foreach ($filterConfiguration['whitelist']['exclude']['directory'] as $dir) {
$this->codeCoverageFilter->removeDirectoryFromWhitelist(
$dir['path'], $dir['suffix'], $dir['prefix']
);
}
foreach ($filterConfiguration['whitelist']['exclude']['file'] as $file) {
$this->codeCoverageFilter->removeFileFromWhitelist($file);
}
}
}
$arguments['addUncoveredFilesFromWhitelist'] = isset($arguments['addUncoveredFilesFromWhitelist']) ? $arguments['addUncoveredFilesFromWhitelist'] : TRUE;
$arguments['processUncoveredFilesFromWhitelist'] = isset($arguments['processUncoveredFilesFromWhitelist']) ? $arguments['processUncoveredFilesFromWhitelist'] : FALSE;
$arguments['backupGlobals'] = isset($arguments['backupGlobals']) ? $arguments['backupGlobals'] : NULL;
$arguments['backupStaticAttributes'] = isset($arguments['backupStaticAttributes']) ? $arguments['backupStaticAttributes'] : NULL;
$arguments['cacheTokens'] = isset($arguments['cacheTokens']) ? $arguments['cacheTokens'] : FALSE;
$arguments['colors'] = isset($arguments['colors']) ? $arguments['colors'] : FALSE;
$arguments['convertErrorsToExceptions'] = isset($arguments['convertErrorsToExceptions']) ? $arguments['convertErrorsToExceptions'] : TRUE;
$arguments['convertNoticesToExceptions'] = isset($arguments['convertNoticesToExceptions']) ? $arguments['convertNoticesToExceptions'] : TRUE;
$arguments['convertWarningsToExceptions'] = isset($arguments['convertWarningsToExceptions']) ? $arguments['convertWarningsToExceptions'] : TRUE;
$arguments['excludeGroups'] = isset($arguments['excludeGroups']) ? $arguments['excludeGroups'] : array();
$arguments['groups'] = isset($arguments['groups']) ? $arguments['groups'] : array();
$arguments['logIncompleteSkipped'] = isset($arguments['logIncompleteSkipped']) ? $arguments['logIncompleteSkipped'] : FALSE;
$arguments['processIsolation'] = isset($arguments['processIsolation']) ? $arguments['processIsolation'] : FALSE;
$arguments['repeat'] = isset($arguments['repeat']) ? $arguments['repeat'] : FALSE;
$arguments['reportCharset'] = isset($arguments['reportCharset']) ? $arguments['reportCharset'] : 'UTF-8';
$arguments['reportHighlight'] = isset($arguments['reportHighlight']) ? $arguments['reportHighlight'] : FALSE;
$arguments['reportHighLowerBound'] = isset($arguments['reportHighLowerBound']) ? $arguments['reportHighLowerBound'] : 70;
$arguments['reportLowUpperBound'] = isset($arguments['reportLowUpperBound']) ? $arguments['reportLowUpperBound'] : 35;
$arguments['stopOnError'] = isset($arguments['stopOnError']) ? $arguments['stopOnError'] : FALSE;
$arguments['stopOnFailure'] = isset($arguments['stopOnFailure']) ? $arguments['stopOnFailure'] : FALSE;
$arguments['stopOnIncomplete'] = isset($arguments['stopOnIncomplete']) ? $arguments['stopOnIncomplete'] : FALSE;
$arguments['stopOnSkipped'] = isset($arguments['stopOnSkipped']) ? $arguments['stopOnSkipped'] : FALSE;
$arguments['timeoutForSmallTests'] = isset($arguments['timeoutForSmallTests']) ? $arguments['timeoutForSmallTests'] : 1;
$arguments['timeoutForMediumTests'] = isset($arguments['timeoutForMediumTests']) ? $arguments['timeoutForMediumTests'] : 10;
$arguments['timeoutForLargeTests'] = isset($arguments['timeoutForLargeTests']) ? $arguments['timeoutForLargeTests'] : 60;
$arguments['strict'] = isset($arguments['strict']) ? $arguments['strict'] : FALSE;
$arguments['verbose'] = isset($arguments['verbose']) ? $arguments['verbose'] : FALSE;
if ($arguments['filter'] !== FALSE &&
preg_match('/^[a-zA-Z0-9_]/', $arguments['filter'])) {
// Escape delimiters in regular expression. Do NOT use preg_quote,
// to keep magic characters.
$arguments['filter'] = '/' . str_replace(
'/', '\\/', $arguments['filter']
) . '/';
}
}
}