Skip to content

Commit

Permalink
Add --disallow-resource-usage commandline option and beStrictAboutRes…
Browse files Browse the repository at this point in the history
…ourceUsageDuringSmallTests configuration setting for #1604
  • Loading branch information
sebastianbergmann committed Jul 18, 2015
1 parent accc042 commit 64c623e
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 107 deletions.
50 changes: 26 additions & 24 deletions src/Framework/TestCase.php
Expand Up @@ -634,11 +634,12 @@ public function run(PHPUnit_Framework_TestResult $result = null)
$iniSettings = '';
}

$coverage = $result->getCollectCodeCoverageInformation() ? 'true' : 'false';
$isStrictAboutTestsThatDoNotTestAnything = $result->isStrictAboutTestsThatDoNotTestAnything() ? 'true' : 'false';
$isStrictAboutOutputDuringTests = $result->isStrictAboutOutputDuringTests() ? 'true' : 'false';
$enforcesTimeLimit = $result->enforcesTimeLimit() ? 'true' : 'false';
$isStrictAboutTodoAnnotatedTests = $result->isStrictAboutTodoAnnotatedTests() ? 'true' : 'false';
$coverage = $result->getCollectCodeCoverageInformation() ? 'true' : 'false';
$isStrictAboutTestsThatDoNotTestAnything = $result->isStrictAboutTestsThatDoNotTestAnything() ? 'true' : 'false';
$isStrictAboutOutputDuringTests = $result->isStrictAboutOutputDuringTests() ? 'true' : 'false';
$enforcesTimeLimit = $result->enforcesTimeLimit() ? 'true' : 'false';
$isStrictAboutTodoAnnotatedTests = $result->isStrictAboutTodoAnnotatedTests() ? 'true' : 'false';
$isStrictAboutResourceUsageDuringSmallTests = $result->isStrictAboutResourceUsageDuringSmallTests() ? 'true' : 'false';

if (defined('PHPUNIT_COMPOSER_INSTALL')) {
$composerAutoload = var_export(PHPUNIT_COMPOSER_INSTALL, true);
Expand Down Expand Up @@ -673,25 +674,26 @@ public function run(PHPUnit_Framework_TestResult $result = null)

$template->setVar(
[
'composerAutoload' => $composerAutoload,
'phar' => $phar,
'filename' => $class->getFileName(),
'className' => $class->getName(),
'methodName' => $this->name,
'collectCodeCoverageInformation' => $coverage,
'data' => $data,
'dataName' => $dataName,
'dependencyInput' => $dependencyInput,
'constants' => $constants,
'globals' => $globals,
'include_path' => $includePath,
'included_files' => $includedFiles,
'iniSettings' => $iniSettings,
'isStrictAboutTestsThatDoNotTestAnything' => $isStrictAboutTestsThatDoNotTestAnything,
'isStrictAboutOutputDuringTests' => $isStrictAboutOutputDuringTests,
'enforcesTimeLimit' => $enforcesTimeLimit,
'isStrictAboutTodoAnnotatedTests' => $isStrictAboutTodoAnnotatedTests,
'codeCoverageFilter' => $codeCoverageFilter
'composerAutoload' => $composerAutoload,
'phar' => $phar,
'filename' => $class->getFileName(),
'className' => $class->getName(),
'methodName' => $this->name,
'collectCodeCoverageInformation' => $coverage,
'data' => $data,
'dataName' => $dataName,
'dependencyInput' => $dependencyInput,
'constants' => $constants,
'globals' => $globals,
'include_path' => $includePath,
'included_files' => $includedFiles,
'iniSettings' => $iniSettings,
'isStrictAboutTestsThatDoNotTestAnything' => $isStrictAboutTestsThatDoNotTestAnything,
'isStrictAboutOutputDuringTests' => $isStrictAboutOutputDuringTests,
'enforcesTimeLimit' => $enforcesTimeLimit,
'isStrictAboutTodoAnnotatedTests' => $isStrictAboutTodoAnnotatedTests,
'isStrictAboutResourceUsageDuringSmallTests' => $isStrictAboutResourceUsageDuringSmallTests,
'codeCoverageFilter' => $codeCoverageFilter
]
);

Expand Down
28 changes: 28 additions & 0 deletions src/Framework/TestResult.php
Expand Up @@ -107,6 +107,11 @@ class PHPUnit_Framework_TestResult implements Countable
*/
protected $beStrictAboutTodoAnnotatedTests = false;

/**
* @var bool
*/
protected $beStrictAboutResourceUsageDuringSmallTests = false;

/**
* @var bool
*/
Expand Down Expand Up @@ -877,6 +882,29 @@ public function isStrictAboutOutputDuringTests()
return $this->beStrictAboutOutputDuringTests;
}

/**
* @param bool $flag
* @throws PHPUnit_Framework_Exception
* @since Method available since Release 5.0.0
*/
public function beStrictAboutResourceUsageDuringSmallTests($flag)
{
if (!is_bool($flag)) {
throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'boolean');
}

$this->beStrictAboutResourceUsageDuringSmallTests = $flag;
}

/**
* @return bool
* @since Method available since Release 5.0.0
*/
public function isStrictAboutResourceUsageDuringSmallTests()
{
return $this->beStrictAboutResourceUsageDuringSmallTests;
}

/**
* @param bool $flag
* @throws PHPUnit_Framework_Exception
Expand Down
104 changes: 55 additions & 49 deletions src/TextUI/Command.php
Expand Up @@ -34,55 +34,56 @@ class PHPUnit_TextUI_Command
* @var array
*/
protected $longOptions = [
'bootstrap=' => null,
'colors==' => null,
'columns=' => null,
'configuration=' => null,
'coverage-clover=' => null,
'coverage-crap4j=' => null,
'coverage-html=' => null,
'coverage-php=' => null,
'coverage-text==' => null,
'coverage-xml=' => null,
'debug' => null,
'disallow-test-output' => null,
'disallow-todo-tests' => null,
'enforce-time-limit' => null,
'exclude-group=' => null,
'filter=' => null,
'group=' => null,
'help' => null,
'include-path=' => null,
'list-groups' => null,
'loader=' => null,
'log-json=' => null,
'log-junit=' => null,
'log-tap=' => null,
'no-configuration' => null,
'no-coverage' => null,
'no-globals-backup' => null,
'printer=' => null,
'process-isolation' => null,
'repeat=' => null,
'report-useless-tests' => null,
'reverse-list' => null,
'static-backup' => null,
'stderr' => null,
'stop-on-error' => null,
'stop-on-failure' => null,
'stop-on-incomplete' => null,
'stop-on-risky' => null,
'stop-on-skipped' => null,
'strict-coverage' => null,
'strict-global-state' => null,
'tap' => null,
'testdox' => null,
'testdox-html=' => null,
'testdox-text=' => null,
'test-suffix=' => null,
'testsuite=' => null,
'verbose' => null,
'version' => null
'bootstrap=' => null,
'colors==' => null,
'columns=' => null,
'configuration=' => null,
'coverage-clover=' => null,
'coverage-crap4j=' => null,
'coverage-html=' => null,
'coverage-php=' => null,
'coverage-text==' => null,
'coverage-xml=' => null,
'debug' => null,
'disallow-test-output' => null,
'disallow-resource-usage' => null,
'disallow-todo-tests' => null,
'enforce-time-limit' => null,
'exclude-group=' => null,
'filter=' => null,
'group=' => null,
'help' => null,
'include-path=' => null,
'list-groups' => null,
'loader=' => null,
'log-json=' => null,
'log-junit=' => null,
'log-tap=' => null,
'no-configuration' => null,
'no-coverage' => null,
'no-globals-backup' => null,
'printer=' => null,
'process-isolation' => null,
'repeat=' => null,
'report-useless-tests' => null,
'reverse-list' => null,
'static-backup' => null,
'stderr' => null,
'stop-on-error' => null,
'stop-on-failure' => null,
'stop-on-incomplete' => null,
'stop-on-risky' => null,
'stop-on-skipped' => null,
'strict-coverage' => null,
'strict-global-state' => null,
'tap' => null,
'testdox' => null,
'testdox-html=' => null,
'testdox-text=' => null,
'test-suffix=' => null,
'testsuite=' => null,
'verbose' => null,
'version' => null
];

/**
Expand Down Expand Up @@ -458,6 +459,10 @@ protected function handleArguments(array $argv)
$this->arguments['disallowTestOutput'] = true;
break;

case '--disallow-resource-usage':
$this->arguments['beStrictAboutResourceUsageDuringSmallTests'] = true;
break;

case '--enforce-time-limit':
$this->arguments['enforceTimeLimit'] = true;
break;
Expand Down Expand Up @@ -887,6 +892,7 @@ protected function showHelp()
--strict-coverage Be strict about unintentionally covered code.
--strict-global-state Be strict about changes to global state
--disallow-test-output Be strict about output during tests.
--disallow-resource-usage Be strict about resource usage during small tests.
--enforce-time-limit Enforce time limit based on test size.
--disallow-todo-tests Disallow @todo-annotated tests.
Expand Down

0 comments on commit 64c623e

Please sign in to comment.