Skip to content

Commit 57eb776

Browse files
Merge branch '13.1'
* 13.1: Closes #6587
2 parents 11c89af + 620e87f commit 57eb776

7 files changed

Lines changed: 79 additions & 32 deletions

File tree

src/TextUI/Configuration/Merger.php

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,10 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
146146

147147
if ($cliConfiguration->hasFailOnEmptyTestSuite()) {
148148
$failOnEmptyTestSuite = $cliConfiguration->failOnEmptyTestSuite();
149-
} else {
149+
} elseif ($xmlConfiguration->phpunit()->hasFailOnEmptyTestSuite()) {
150150
$failOnEmptyTestSuite = $xmlConfiguration->phpunit()->failOnEmptyTestSuite();
151+
} else {
152+
$failOnEmptyTestSuite = $this->hasExplicitTestSelection($cliConfiguration);
151153
}
152154

153155
if ($cliConfiguration->hasFailOnIncomplete()) {
@@ -1190,4 +1192,33 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
11901192
$xmlConfiguration->phpunit()->shortenArraysForExportThreshold(),
11911193
);
11921194
}
1195+
1196+
private function hasExplicitTestSelection(CliConfiguration $cliConfiguration): bool
1197+
{
1198+
if ($cliConfiguration->hasFilter()) {
1199+
return true;
1200+
}
1201+
1202+
if ($cliConfiguration->hasExcludeFilter()) {
1203+
return true;
1204+
}
1205+
1206+
if ($cliConfiguration->hasGroups()) {
1207+
return true;
1208+
}
1209+
1210+
if ($cliConfiguration->hasExcludeGroups()) {
1211+
return true;
1212+
}
1213+
1214+
if ($cliConfiguration->hasTestSuite()) {
1215+
return true;
1216+
}
1217+
1218+
if ($cliConfiguration->hasExcludedTestSuite()) {
1219+
return true;
1220+
}
1221+
1222+
return false;
1223+
}
11931224
}

src/TextUI/Configuration/Xml/DefaultConfiguration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ public static function create(): self
133133
false,
134134
false,
135135
false,
136+
false,
136137
0,
137138
0,
138139
0,

src/TextUI/Configuration/Xml/Loader.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,7 @@ private function phpunit(string $filename, DOMDocument $document, DOMXPath $xpat
10301030
$this->parseBooleanAttribute($document->documentElement, 'failOnPhpunitNotice', false),
10311031
$this->parseBooleanAttribute($document->documentElement, 'failOnPhpunitWarning', true),
10321032
$this->parseBooleanAttribute($document->documentElement, 'failOnEmptyTestSuite', false),
1033+
$document->documentElement->hasAttribute('failOnEmptyTestSuite'),
10331034
$this->parseBooleanAttribute($document->documentElement, 'failOnIncomplete', false),
10341035
$this->parseBooleanAttribute($document->documentElement, 'failOnNotice', false),
10351036
$this->parseBooleanAttribute($document->documentElement, 'failOnRisky', false),

src/TextUI/Configuration/Xml/PHPUnit.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
private bool $failOnPhpunitNotice;
6060
private bool $failOnPhpunitWarning;
6161
private bool $failOnEmptyTestSuite;
62+
private bool $hasFailOnEmptyTestSuite;
6263
private bool $failOnIncomplete;
6364
private bool $failOnNotice;
6465
private bool $failOnRisky;
@@ -190,7 +191,7 @@
190191
* @param non-negative-int $shortenArraysForExportThreshold
191192
* @param positive-int $diffContext
192193
*/
193-
public function __construct(?string $cacheDirectory, bool $cacheResult, int|string $columns, string $colors, bool $stderr, bool $displayDetailsOnAllIssues, bool $displayDetailsOnIncompleteTests, bool $displayDetailsOnSkippedTests, bool $displayDetailsOnTestsThatTriggerDeprecations, bool $displayDetailsOnPhpunitDeprecations, bool $displayDetailsOnPhpunitNotices, bool $displayDetailsOnTestsThatTriggerErrors, bool $displayDetailsOnTestsThatTriggerNotices, bool $displayDetailsOnTestsThatTriggerWarnings, bool $reverseDefectList, bool $requireCoverageMetadata, bool $requireSealedMockObjects, ?string $bootstrap, array $bootstrapForTestSuite, bool $processIsolation, bool $failOnAllIssues, bool $failOnDeprecation, bool $failOnPhpunitDeprecation, bool $failOnPhpunitNotice, bool $failOnPhpunitWarning, bool $failOnEmptyTestSuite, bool $failOnIncomplete, bool $failOnNotice, bool $failOnRisky, bool $failOnSkipped, bool $failOnWarning, int $stopOnDefect, int $stopOnDeprecation, int $stopOnError, int $stopOnFailure, int $stopOnIncomplete, int $stopOnNotice, int $stopOnRisky, int $stopOnSkipped, int $stopOnWarning, ?string $extensionsDirectory, bool $beStrictAboutChangesToGlobalState, bool $beStrictAboutOutputDuringTests, bool $beStrictAboutTestsThatDoNotTestAnything, bool $beStrictAboutCoverageMetadata, bool $requireCoverageContribution, bool $enforceTimeLimit, int $defaultTimeLimit, int $timeoutForSmallTests, int $timeoutForMediumTests, int $timeoutForLargeTests, ?string $defaultTestSuite, int $executionOrder, bool $resolveDependencies, bool $defectsFirst, bool $backupGlobals, bool $backupStaticProperties, bool $testdoxPrinter, bool $testdoxPrinterSummary, bool $controlGarbageCollector, int $numberOfTestsBeforeGarbageCollection, int $shortenArraysForExportThreshold, int $diffContext)
194+
public function __construct(?string $cacheDirectory, bool $cacheResult, int|string $columns, string $colors, bool $stderr, bool $displayDetailsOnAllIssues, bool $displayDetailsOnIncompleteTests, bool $displayDetailsOnSkippedTests, bool $displayDetailsOnTestsThatTriggerDeprecations, bool $displayDetailsOnPhpunitDeprecations, bool $displayDetailsOnPhpunitNotices, bool $displayDetailsOnTestsThatTriggerErrors, bool $displayDetailsOnTestsThatTriggerNotices, bool $displayDetailsOnTestsThatTriggerWarnings, bool $reverseDefectList, bool $requireCoverageMetadata, bool $requireSealedMockObjects, ?string $bootstrap, array $bootstrapForTestSuite, bool $processIsolation, bool $failOnAllIssues, bool $failOnDeprecation, bool $failOnPhpunitDeprecation, bool $failOnPhpunitNotice, bool $failOnPhpunitWarning, bool $failOnEmptyTestSuite, bool $hasFailOnEmptyTestSuite, bool $failOnIncomplete, bool $failOnNotice, bool $failOnRisky, bool $failOnSkipped, bool $failOnWarning, int $stopOnDefect, int $stopOnDeprecation, int $stopOnError, int $stopOnFailure, int $stopOnIncomplete, int $stopOnNotice, int $stopOnRisky, int $stopOnSkipped, int $stopOnWarning, ?string $extensionsDirectory, bool $beStrictAboutChangesToGlobalState, bool $beStrictAboutOutputDuringTests, bool $beStrictAboutTestsThatDoNotTestAnything, bool $beStrictAboutCoverageMetadata, bool $requireCoverageContribution, bool $enforceTimeLimit, int $defaultTimeLimit, int $timeoutForSmallTests, int $timeoutForMediumTests, int $timeoutForLargeTests, ?string $defaultTestSuite, int $executionOrder, bool $resolveDependencies, bool $defectsFirst, bool $backupGlobals, bool $backupStaticProperties, bool $testdoxPrinter, bool $testdoxPrinterSummary, bool $controlGarbageCollector, int $numberOfTestsBeforeGarbageCollection, int $shortenArraysForExportThreshold, int $diffContext)
194195
{
195196
$this->cacheDirectory = $cacheDirectory;
196197
$this->cacheResult = $cacheResult;
@@ -218,6 +219,7 @@ public function __construct(?string $cacheDirectory, bool $cacheResult, int|stri
218219
$this->failOnPhpunitNotice = $failOnPhpunitNotice;
219220
$this->failOnPhpunitWarning = $failOnPhpunitWarning;
220221
$this->failOnEmptyTestSuite = $failOnEmptyTestSuite;
222+
$this->hasFailOnEmptyTestSuite = $hasFailOnEmptyTestSuite;
221223
$this->failOnIncomplete = $failOnIncomplete;
222224
$this->failOnNotice = $failOnNotice;
223225
$this->failOnRisky = $failOnRisky;
@@ -427,6 +429,11 @@ public function failOnEmptyTestSuite(): bool
427429
return $this->failOnEmptyTestSuite;
428430
}
429431

432+
public function hasFailOnEmptyTestSuite(): bool
433+
{
434+
return $this->hasFailOnEmptyTestSuite;
435+
}
436+
430437
public function failOnIncomplete(): bool
431438
{
432439
return $this->failOnIncomplete;

src/TextUI/ShellExitCodeCalculator.php

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function calculate(Configuration $configuration, TestResult $result): int
2929
$failOnPhpunitDeprecation = false;
3030
$failOnPhpunitNotice = false;
3131
$failOnPhpunitWarning = false;
32-
$failOnEmptyTestSuite = $this->hasExplicitTestSelection($configuration);
32+
$failOnEmptyTestSuite = false;
3333
$failOnIncomplete = false;
3434
$failOnNotice = false;
3535
$failOnRisky = false;
@@ -181,33 +181,4 @@ public function calculate(Configuration $configuration, TestResult $result): int
181181

182182
return $returnCode;
183183
}
184-
185-
private function hasExplicitTestSelection(Configuration $configuration): bool
186-
{
187-
if ($configuration->hasFilter()) {
188-
return true;
189-
}
190-
191-
if ($configuration->hasExcludeFilter()) {
192-
return true;
193-
}
194-
195-
if ($configuration->hasGroups()) {
196-
return true;
197-
}
198-
199-
if ($configuration->hasExcludeGroups()) {
200-
return true;
201-
}
202-
203-
if ($configuration->includeTestSuites() !== []) {
204-
return true;
205-
}
206-
207-
if ($configuration->excludeTestSuites() !== []) {
208-
return true;
209-
}
210-
211-
return false;
212-
}
213184
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="../../../../../../phpunit.xsd"
4+
failOnEmptyTestSuite="false">
5+
<testsuites>
6+
<testsuite name="default">
7+
<directory suffix="Test.php">../../../../_files/groups/tests</directory>
8+
</testsuite>
9+
</testsuites>
10+
</phpunit>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
Test Runner exits with shell exit code indicating success when --group does not match any tests and phpunit.xml has failOnEmptyTestSuite="false"
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--debug';
7+
$_SERVER['argv'][] = '--configuration';
8+
$_SERVER['argv'][] = __DIR__ . '/_files/do-not-fail-on-empty-test-suite/phpunit.xml';
9+
$_SERVER['argv'][] = '--group';
10+
$_SERVER['argv'][] = 'doesNotExist';
11+
12+
require __DIR__ . '/../../../bootstrap.php';
13+
14+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
15+
--EXPECTF--
16+
PHPUnit Started (PHPUnit %s using %s)
17+
Test Runner Configured
18+
Event Facade Sealed
19+
Test Suite Loaded (3 tests)
20+
Test Runner Started
21+
Test Suite Sorted
22+
Test Suite Filtered (0 tests)
23+
Test Runner Execution Started (0 tests)
24+
Test Runner Execution Finished
25+
Test Runner Finished
26+
PHPUnit Finished (Shell Exit Code: 0)

0 commit comments

Comments
 (0)