Skip to content

Commit

Permalink
Restrict default time limit to enforced scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
epdenouden authored and sebastianbergmann committed Sep 8, 2018
1 parent 48bb51b commit 8f2b043
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion phpunit.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +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="defaultTimeLimit" type="xs:integer" default="0"/>
<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
9 changes: 7 additions & 2 deletions src/Framework/TestResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class TestResult implements Countable
/**
* @var int
*/
protected $defaultTimeLimit = 1;
protected $defaultTimeLimit = 0;

/**
* @var bool
Expand Down Expand Up @@ -644,8 +644,8 @@ public function run(Test $test): void

try {
if (!$test instanceof WarningTestCase &&
$test->getSize() != \PHPUnit\Util\Test::UNKNOWN &&
$this->enforceTimeLimit &&
($this->defaultTimeLimit || $test->getSize() != \PHPUnit\Util\Test::UNKNOWN) &&
\extension_loaded('pcntl') && \class_exists(Invoker::class)) {
switch ($test->getSize()) {
case \PHPUnit\Util\Test::SMALL:
Expand All @@ -661,6 +661,11 @@ public function run(Test $test): void
case \PHPUnit\Util\Test::LARGE:
$_timeout = $this->timeoutForLargeTests;

break;

case \PHPUnit\Util\Test::UNKNOWN:
$_timeout = $this->defaultTimeLimit;

break;
}

Expand Down
2 changes: 1 addition & 1 deletion src/TextUI/TestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +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['defaultTimeLimit'] = $arguments['defaultTimeLimit'] ?? 0;
$arguments['enforceTimeLimit'] = $arguments['enforceTimeLimit'] ?? false;
$arguments['excludeGroups'] = $arguments['excludeGroups'] ?? [];
$arguments['failOnRisky'] = $arguments['failOnRisky'] ?? false;
Expand Down
2 changes: 1 addition & 1 deletion src/Util/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
* beStrictAboutResourceUsageDuringSmallTests="false"
* beStrictAboutTestsThatDoNotTestAnything="false"
* beStrictAboutTodoAnnotatedTests="false"
* defaultTimeLimit="1"
* defaultTimeLimit="0"
* enforceTimeLimit="false"
* ignoreDeprecatedCodeUnitsFromCodeCoverage="false"
* timeoutForSmallTests="1"
Expand Down

0 comments on commit 8f2b043

Please sign in to comment.