Skip to content

Commit

Permalink
Make --testsuite CLI option value available in Configuration value ob…
Browse files Browse the repository at this point in the history
…ject
  • Loading branch information
sebastianbergmann committed Oct 12, 2022
1 parent e91f94b commit 03e729d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/TextUI/Configuration/Configuration.php
Expand Up @@ -120,11 +120,12 @@ final class Configuration
private int $randomOrderSeed;
private ?string $xmlValidationErrors;
private bool $includeUncoveredFiles;
private ?string $testSuite;

/**
* @psalm-param list<array{className: class-string, parameters: array<string, string>}> $extensionBootstrappers
*/
public function __construct(?string $configurationFile, ?string $bootstrap, bool $cacheResult, ?string $cacheDirectory, ?string $coverageCacheDirectory, string $testResultCacheFile, ?string $coverageClover, ?string $coverageCobertura, ?string $coverageCrap4j, int $coverageCrap4jThreshold, ?string $coverageHtml, int $coverageHtmlLowUpperBound, int $coverageHtmlHighLowerBound, string $coverageHtmlColorSuccessLow, string $coverageHtmlColorSuccessMedium, string $coverageHtmlColorSuccessHigh, string $coverageHtmlColorWarning, string $coverageHtmlColorDanger, ?string $coverageHtmlCustomCssFile, ?string $coveragePhp, ?string $coverageText, bool $coverageTextShowUncoveredFiles, bool $coverageTextShowOnlySummary, ?string $coverageXml, bool $pathCoverage, bool $ignoreDeprecatedCodeUnitsFromCodeCoverage, bool $disableCodeCoverageIgnore, bool $failOnEmptyTestSuite, bool $failOnIncomplete, bool $failOnRisky, bool $failOnSkipped, bool $failOnWarning, bool $outputToStandardErrorStream, int|string $columns, bool $tooFewColumnsRequested, bool $loadPharExtensions, ?string $pharExtensionDirectory, array $extensionBootstrappers, bool $backupGlobals, bool $backupStaticProperties, bool $beStrictAboutChangesToGlobalState, bool $colors, bool $processIsolation, bool $stopOnDefect, bool $stopOnError, bool $stopOnFailure, bool $stopOnWarning, bool $stopOnIncomplete, bool $stopOnRisky, bool $stopOnSkipped, bool $enforceTimeLimit, int $defaultTimeLimit, int $timeoutForSmallTests, int $timeoutForMediumTests, int $timeoutForLargeTests, bool $reportUselessTests, bool $strictCoverage, bool $disallowTestOutput, bool $displayDetailsOnIncompleteTests, bool $displayDetailsOnSkippedTests, bool $displayDetailsOnTestsThatTriggerDeprecations, bool $displayDetailsOnTestsThatTriggerErrors, bool $displayDetailsOnTestsThatTriggerNotices, bool $displayDetailsOnTestsThatTriggerWarnings, bool $reverseDefectList, bool $requireCoverageMetadata, bool $registerMockObjectsFromTestArgumentsRecursively, bool $noProgress, bool $noResults, bool $noOutput, int $executionOrder, int $executionOrderDefects, bool $resolveDependencies, ?string $logfileText, ?string $logfileTeamcity, ?string $logfileJunit, ?string $logfileTestdoxHtml, ?string $logfileTestdoxText, ?string $logfileTestdoxXml, ?string $logEventsText, ?string $logEventsVerboseText, bool $teamCityOutput, bool $testDoxOutput, int $repeat, ?array $testsCovering, ?array $testsUsing, ?string $filter, ?array $groups, ?array $excludeGroups, ?string $includePath, int $randomOrderSeed, bool $includeUncoveredFiles, ?string $xmlValidationErrors)
public function __construct(?string $configurationFile, ?string $bootstrap, bool $cacheResult, ?string $cacheDirectory, ?string $coverageCacheDirectory, string $testResultCacheFile, ?string $coverageClover, ?string $coverageCobertura, ?string $coverageCrap4j, int $coverageCrap4jThreshold, ?string $coverageHtml, int $coverageHtmlLowUpperBound, int $coverageHtmlHighLowerBound, string $coverageHtmlColorSuccessLow, string $coverageHtmlColorSuccessMedium, string $coverageHtmlColorSuccessHigh, string $coverageHtmlColorWarning, string $coverageHtmlColorDanger, ?string $coverageHtmlCustomCssFile, ?string $coveragePhp, ?string $coverageText, bool $coverageTextShowUncoveredFiles, bool $coverageTextShowOnlySummary, ?string $coverageXml, bool $pathCoverage, bool $ignoreDeprecatedCodeUnitsFromCodeCoverage, bool $disableCodeCoverageIgnore, bool $failOnEmptyTestSuite, bool $failOnIncomplete, bool $failOnRisky, bool $failOnSkipped, bool $failOnWarning, bool $outputToStandardErrorStream, int|string $columns, bool $tooFewColumnsRequested, bool $loadPharExtensions, ?string $pharExtensionDirectory, array $extensionBootstrappers, bool $backupGlobals, bool $backupStaticProperties, bool $beStrictAboutChangesToGlobalState, bool $colors, bool $processIsolation, bool $stopOnDefect, bool $stopOnError, bool $stopOnFailure, bool $stopOnWarning, bool $stopOnIncomplete, bool $stopOnRisky, bool $stopOnSkipped, bool $enforceTimeLimit, int $defaultTimeLimit, int $timeoutForSmallTests, int $timeoutForMediumTests, int $timeoutForLargeTests, bool $reportUselessTests, bool $strictCoverage, bool $disallowTestOutput, bool $displayDetailsOnIncompleteTests, bool $displayDetailsOnSkippedTests, bool $displayDetailsOnTestsThatTriggerDeprecations, bool $displayDetailsOnTestsThatTriggerErrors, bool $displayDetailsOnTestsThatTriggerNotices, bool $displayDetailsOnTestsThatTriggerWarnings, bool $reverseDefectList, bool $requireCoverageMetadata, bool $registerMockObjectsFromTestArgumentsRecursively, bool $noProgress, bool $noResults, bool $noOutput, int $executionOrder, int $executionOrderDefects, bool $resolveDependencies, ?string $logfileText, ?string $logfileTeamcity, ?string $logfileJunit, ?string $logfileTestdoxHtml, ?string $logfileTestdoxText, ?string $logfileTestdoxXml, ?string $logEventsText, ?string $logEventsVerboseText, bool $teamCityOutput, bool $testDoxOutput, int $repeat, ?array $testsCovering, ?array $testsUsing, ?string $filter, ?array $groups, ?array $excludeGroups, ?string $includePath, int $randomOrderSeed, bool $includeUncoveredFiles, ?string $testSuite, ?string $xmlValidationErrors)
{
$this->configurationFile = $configurationFile;
$this->bootstrap = $bootstrap;
Expand Down Expand Up @@ -218,6 +219,7 @@ public function __construct(?string $configurationFile, ?string $bootstrap, bool
$this->includePath = $includePath;
$this->randomOrderSeed = $randomOrderSeed;
$this->includeUncoveredFiles = $includeUncoveredFiles;
$this->testSuite = $testSuite;
$this->xmlValidationErrors = $xmlValidationErrors;
}

Expand Down Expand Up @@ -1109,6 +1111,26 @@ public function includeUncoveredFiles(): bool
return $this->includeUncoveredFiles;
}

/**
* @psalm-assert-if-true !null $this->testSuite
*/
public function hasTestSuite(): bool
{
return $this->testSuite !== null;
}

/**
* @throws TestSuiteNotSelectedException
*/
public function testSuite(): string
{
if (!$this->hasTestSuite()) {
throw new TestSuiteNotSelectedException;
}

return $this->testSuite;
}

/**
* @psalm-assert-if-true !null $this->xmlValidationErrors
*/
Expand Down
@@ -0,0 +1,19 @@
<?php declare(strict_types=1);
/*
* This file is part of PHPUnit.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace PHPUnit\TextUI\Configuration;

use RuntimeException;

/**
* @internal This class is not covered by the backward compatibility promise for PHPUnit
*/
final class TestSuiteNotSelectedException extends RuntimeException implements Exception
{
}
7 changes: 7 additions & 0 deletions src/TextUI/Configuration/Merger.php
Expand Up @@ -620,6 +620,12 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC

$includeUncoveredFiles = $xmlConfiguration->codeCoverage()->includeUncoveredFiles();

$testSuite = null;

if ($cliConfiguration->hasTestSuite()) {
$testSuite = $cliConfiguration->testSuite();
}

return new Configuration(
$configurationFile,
$bootstrap,
Expand Down Expand Up @@ -713,6 +719,7 @@ public function merge(CliConfiguration $cliConfiguration, XmlConfiguration $xmlC
$includePath,
$randomOrderSeed,
$includeUncoveredFiles,
$testSuite,
$xmlValidationErrors,
);
}
Expand Down

0 comments on commit 03e729d

Please sign in to comment.