Skip to content

Commit

Permalink
Basic config infrastructure to support #2085
Browse files Browse the repository at this point in the history
  • Loading branch information
epdenouden authored and sebastianbergmann committed Sep 8, 2018
1 parent 2918e4f commit 48bb51b
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions phpunit.xsd
Expand Up @@ -260,6 +260,7 @@
<xs:attribute name="beStrictAboutTestsThatDoNotTestAnything" type="xs:boolean" default="true"/>
<xs:attribute name="beStrictAboutTodoAnnotatedTests" type="xs:boolean" default="false"/>
<xs:attribute name="beStrictAboutCoversAnnotation" type="xs:boolean" default="false"/>
<xs:attribute name="defaultTimeLimit" type="xs:integer" default="1"/>
<xs:attribute name="enforceTimeLimit" type="xs:boolean" default="false"/>
<xs:attribute name="ignoreDeprecatedCodeUnitsFromCodeCoverage" type="xs:boolean" default="false"/>
<xs:attribute name="timeoutForSmallTests" type="xs:integer" default="1"/>
Expand Down
21 changes: 21 additions & 0 deletions src/Framework/TestResult.php
Expand Up @@ -139,6 +139,11 @@ class TestResult implements Countable
*/
protected $beStrictAboutResourceUsageDuringSmallTests = false;

/**
* @var int
*/
protected $defaultTimeLimit = 1;

/**
* @var bool
*/
Expand Down Expand Up @@ -1061,6 +1066,14 @@ public function wasSuccessful(): bool
return empty($this->errors) && empty($this->failures) && empty($this->warnings);
}

/**
* Sets the default timeout for tests
*/
public function setDefaultTimeLimit(int $timeout): void
{
$this->defaultTimeLimit = $timeout;
}

/**
* Sets the timeout for small tests.
*/
Expand All @@ -1085,6 +1098,14 @@ public function setTimeoutForLargeTests(int $timeout): void
$this->timeoutForLargeTests = $timeout;
}

/**
* Returns the set timeout for large tests.
*/
public function getDefaultTimeoutTests(): int
{
return $this->defaultTimeLimit;
}

/**
* Returns the set timeout for large tests.
*/
Expand Down
6 changes: 6 additions & 0 deletions src/TextUI/Command.php
Expand Up @@ -84,6 +84,7 @@ class Command
'disallow-test-output' => null,
'disallow-resource-usage' => null,
'disallow-todo-tests' => null,
'default-time-limit=' => null,
'enforce-time-limit' => null,
'exclude-group=' => null,
'filter=' => null,
Expand Down Expand Up @@ -692,6 +693,11 @@ protected function handleArguments(array $argv): void

break;

case '--default-time-limit':
$this->arguments['defaultTimeLimit'] = (int) $option[1];

break;

case '--enforce-time-limit':
$this->arguments['enforceTimeLimit'] = true;

Expand Down
6 changes: 6 additions & 0 deletions src/TextUI/TestRunner.php
Expand Up @@ -583,6 +583,7 @@ public function doRun(Test $suite, array $arguments = [], bool $exit = true): Te
$result->beStrictAboutTodoAnnotatedTests($arguments['disallowTodoAnnotatedTests']);
$result->beStrictAboutResourceUsageDuringSmallTests($arguments['beStrictAboutResourceUsageDuringSmallTests']);
$result->enforceTimeLimit($arguments['enforceTimeLimit']);
$result->setDefaultTimeLimit($arguments['defaultTimeLimit']);
$result->setTimeoutForSmallTests($arguments['timeoutForSmallTests']);
$result->setTimeoutForMediumTests($arguments['timeoutForMediumTests']);
$result->setTimeoutForLargeTests($arguments['timeoutForLargeTests']);
Expand Down Expand Up @@ -945,6 +946,10 @@ protected function handleConfiguration(array &$arguments): void
$arguments['disallowTestOutput'] = $phpunitConfiguration['disallowTestOutput'];
}

if (isset($phpunitConfiguration['defaultTimeLimit']) && !isset($arguments['defaultTimeLimit'])) {
$arguments['defaultTimeLimit'] = $phpunitConfiguration['defaultTimeLimit'];
}

if (isset($phpunitConfiguration['enforceTimeLimit']) && !isset($arguments['enforceTimeLimit'])) {
$arguments['enforceTimeLimit'] = $phpunitConfiguration['enforceTimeLimit'];
}
Expand Down Expand Up @@ -1182,6 +1187,7 @@ protected function handleConfiguration(array &$arguments): void
$arguments['crap4jThreshold'] = $arguments['crap4jThreshold'] ?? 30;
$arguments['disallowTestOutput'] = $arguments['disallowTestOutput'] ?? false;
$arguments['disallowTodoAnnotatedTests'] = $arguments['disallowTodoAnnotatedTests'] ?? false;
$arguments['defaultTimeLimit'] = $arguments['defaultTimeLimit'] ?? 1;
$arguments['enforceTimeLimit'] = $arguments['enforceTimeLimit'] ?? false;
$arguments['excludeGroups'] = $arguments['excludeGroups'] ?? [];
$arguments['failOnRisky'] = $arguments['failOnRisky'] ?? false;
Expand Down
8 changes: 8 additions & 0 deletions src/Util/Configuration.php
Expand Up @@ -59,6 +59,7 @@
* beStrictAboutResourceUsageDuringSmallTests="false"
* beStrictAboutTestsThatDoNotTestAnything="false"
* beStrictAboutTodoAnnotatedTests="false"
* defaultTimeLimit="1"
* enforceTimeLimit="false"
* ignoreDeprecatedCodeUnitsFromCodeCoverage="false"
* timeoutForSmallTests="1"
Expand Down Expand Up @@ -855,6 +856,13 @@ public function getPHPUnitConfiguration(): array
);
}

if ($root->hasAttribute('defaultTimeLimit')) {
$result['defaultTimeLimit'] = $this->getInteger(
(string) $root->getAttribute('defaultTimeLimit'),
1
);
}

if ($root->hasAttribute('enforceTimeLimit')) {
$result['enforceTimeLimit'] = $this->getBoolean(
(string) $root->getAttribute('enforceTimeLimit'),
Expand Down
1 change: 1 addition & 0 deletions tests/_files/configuration.xml
Expand Up @@ -25,6 +25,7 @@
beStrictAboutTestsThatDoNotTestAnything="false"
beStrictAboutTodoAnnotatedTests="false"
beStrictAboutCoversAnnotation="false"
defaultTimeLimit="123"
enforceTimeLimit="false"
ignoreDeprecatedCodeUnitsFromCodeCoverage="false"
timeoutForSmallTests="1"
Expand Down
1 change: 1 addition & 0 deletions tests/_files/configuration_xinclude.xml
Expand Up @@ -26,6 +26,7 @@
beStrictAboutTestsThatDoNotTestAnything="false"
beStrictAboutTodoAnnotatedTests="false"
beStrictAboutCoversAnnotation="false"
defaultTimeLimit="123"
enforceTimeLimit="false"
ignoreDeprecatedCodeUnitsFromCodeCoverage="false"
timeoutForSmallTests="1"
Expand Down
1 change: 1 addition & 0 deletions tests/unit/Util/ConfigurationTest.php
Expand Up @@ -471,6 +471,7 @@ public function testPHPUnitConfigurationIsReadCorrectly(): void
'reportUselessTests' => false,
'strictCoverage' => false,
'disallowTestOutput' => false,
'defaultTimeLimit' => 123,
'enforceTimeLimit' => false,
'extensionsDirectory' => '/tmp',
'printerClass' => 'PHPUnit\TextUI\ResultPrinter',
Expand Down

0 comments on commit 48bb51b

Please sign in to comment.