Skip to content

Commit 48bb51b

Browse files
epdenoudensebastianbergmann
authored andcommitted
Basic config infrastructure to support #2085
1 parent 2918e4f commit 48bb51b

File tree

8 files changed

+45
-0
lines changed

8 files changed

+45
-0
lines changed

phpunit.xsd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@
260260
<xs:attribute name="beStrictAboutTestsThatDoNotTestAnything" type="xs:boolean" default="true"/>
261261
<xs:attribute name="beStrictAboutTodoAnnotatedTests" type="xs:boolean" default="false"/>
262262
<xs:attribute name="beStrictAboutCoversAnnotation" type="xs:boolean" default="false"/>
263+
<xs:attribute name="defaultTimeLimit" type="xs:integer" default="1"/>
263264
<xs:attribute name="enforceTimeLimit" type="xs:boolean" default="false"/>
264265
<xs:attribute name="ignoreDeprecatedCodeUnitsFromCodeCoverage" type="xs:boolean" default="false"/>
265266
<xs:attribute name="timeoutForSmallTests" type="xs:integer" default="1"/>

src/Framework/TestResult.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ class TestResult implements Countable
139139
*/
140140
protected $beStrictAboutResourceUsageDuringSmallTests = false;
141141

142+
/**
143+
* @var int
144+
*/
145+
protected $defaultTimeLimit = 1;
146+
142147
/**
143148
* @var bool
144149
*/
@@ -1061,6 +1066,14 @@ public function wasSuccessful(): bool
10611066
return empty($this->errors) && empty($this->failures) && empty($this->warnings);
10621067
}
10631068

1069+
/**
1070+
* Sets the default timeout for tests
1071+
*/
1072+
public function setDefaultTimeLimit(int $timeout): void
1073+
{
1074+
$this->defaultTimeLimit = $timeout;
1075+
}
1076+
10641077
/**
10651078
* Sets the timeout for small tests.
10661079
*/
@@ -1085,6 +1098,14 @@ public function setTimeoutForLargeTests(int $timeout): void
10851098
$this->timeoutForLargeTests = $timeout;
10861099
}
10871100

1101+
/**
1102+
* Returns the set timeout for large tests.
1103+
*/
1104+
public function getDefaultTimeoutTests(): int
1105+
{
1106+
return $this->defaultTimeLimit;
1107+
}
1108+
10881109
/**
10891110
* Returns the set timeout for large tests.
10901111
*/

src/TextUI/Command.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class Command
8484
'disallow-test-output' => null,
8585
'disallow-resource-usage' => null,
8686
'disallow-todo-tests' => null,
87+
'default-time-limit=' => null,
8788
'enforce-time-limit' => null,
8889
'exclude-group=' => null,
8990
'filter=' => null,
@@ -692,6 +693,11 @@ protected function handleArguments(array $argv): void
692693

693694
break;
694695

696+
case '--default-time-limit':
697+
$this->arguments['defaultTimeLimit'] = (int) $option[1];
698+
699+
break;
700+
695701
case '--enforce-time-limit':
696702
$this->arguments['enforceTimeLimit'] = true;
697703

src/TextUI/TestRunner.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ public function doRun(Test $suite, array $arguments = [], bool $exit = true): Te
583583
$result->beStrictAboutTodoAnnotatedTests($arguments['disallowTodoAnnotatedTests']);
584584
$result->beStrictAboutResourceUsageDuringSmallTests($arguments['beStrictAboutResourceUsageDuringSmallTests']);
585585
$result->enforceTimeLimit($arguments['enforceTimeLimit']);
586+
$result->setDefaultTimeLimit($arguments['defaultTimeLimit']);
586587
$result->setTimeoutForSmallTests($arguments['timeoutForSmallTests']);
587588
$result->setTimeoutForMediumTests($arguments['timeoutForMediumTests']);
588589
$result->setTimeoutForLargeTests($arguments['timeoutForLargeTests']);
@@ -945,6 +946,10 @@ protected function handleConfiguration(array &$arguments): void
945946
$arguments['disallowTestOutput'] = $phpunitConfiguration['disallowTestOutput'];
946947
}
947948

949+
if (isset($phpunitConfiguration['defaultTimeLimit']) && !isset($arguments['defaultTimeLimit'])) {
950+
$arguments['defaultTimeLimit'] = $phpunitConfiguration['defaultTimeLimit'];
951+
}
952+
948953
if (isset($phpunitConfiguration['enforceTimeLimit']) && !isset($arguments['enforceTimeLimit'])) {
949954
$arguments['enforceTimeLimit'] = $phpunitConfiguration['enforceTimeLimit'];
950955
}
@@ -1182,6 +1187,7 @@ protected function handleConfiguration(array &$arguments): void
11821187
$arguments['crap4jThreshold'] = $arguments['crap4jThreshold'] ?? 30;
11831188
$arguments['disallowTestOutput'] = $arguments['disallowTestOutput'] ?? false;
11841189
$arguments['disallowTodoAnnotatedTests'] = $arguments['disallowTodoAnnotatedTests'] ?? false;
1190+
$arguments['defaultTimeLimit'] = $arguments['defaultTimeLimit'] ?? 1;
11851191
$arguments['enforceTimeLimit'] = $arguments['enforceTimeLimit'] ?? false;
11861192
$arguments['excludeGroups'] = $arguments['excludeGroups'] ?? [];
11871193
$arguments['failOnRisky'] = $arguments['failOnRisky'] ?? false;

src/Util/Configuration.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
* beStrictAboutResourceUsageDuringSmallTests="false"
6060
* beStrictAboutTestsThatDoNotTestAnything="false"
6161
* beStrictAboutTodoAnnotatedTests="false"
62+
* defaultTimeLimit="1"
6263
* enforceTimeLimit="false"
6364
* ignoreDeprecatedCodeUnitsFromCodeCoverage="false"
6465
* timeoutForSmallTests="1"
@@ -855,6 +856,13 @@ public function getPHPUnitConfiguration(): array
855856
);
856857
}
857858

859+
if ($root->hasAttribute('defaultTimeLimit')) {
860+
$result['defaultTimeLimit'] = $this->getInteger(
861+
(string) $root->getAttribute('defaultTimeLimit'),
862+
1
863+
);
864+
}
865+
858866
if ($root->hasAttribute('enforceTimeLimit')) {
859867
$result['enforceTimeLimit'] = $this->getBoolean(
860868
(string) $root->getAttribute('enforceTimeLimit'),

tests/_files/configuration.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
beStrictAboutTestsThatDoNotTestAnything="false"
2626
beStrictAboutTodoAnnotatedTests="false"
2727
beStrictAboutCoversAnnotation="false"
28+
defaultTimeLimit="123"
2829
enforceTimeLimit="false"
2930
ignoreDeprecatedCodeUnitsFromCodeCoverage="false"
3031
timeoutForSmallTests="1"

tests/_files/configuration_xinclude.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
beStrictAboutTestsThatDoNotTestAnything="false"
2727
beStrictAboutTodoAnnotatedTests="false"
2828
beStrictAboutCoversAnnotation="false"
29+
defaultTimeLimit="123"
2930
enforceTimeLimit="false"
3031
ignoreDeprecatedCodeUnitsFromCodeCoverage="false"
3132
timeoutForSmallTests="1"

tests/unit/Util/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,7 @@ public function testPHPUnitConfigurationIsReadCorrectly(): void
471471
'reportUselessTests' => false,
472472
'strictCoverage' => false,
473473
'disallowTestOutput' => false,
474+
'defaultTimeLimit' => 123,
474475
'enforceTimeLimit' => false,
475476
'extensionsDirectory' => '/tmp',
476477
'printerClass' => 'PHPUnit\TextUI\ResultPrinter',

0 commit comments

Comments
 (0)