Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure global exception/error handlers checks #5888

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Framework/TestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ private function configureTestCase(TestCase $test, bool $runTestInSeparateProces
}

$test->setBackupStaticPropertiesExcludeList($backupSettings['backupStaticPropertiesExcludeList']);

$test->setShouldBackupGlobalErrorHandlers(ConfigurationRegistry::get()->backupGlobalErrorHandlers());
$test->setShouldBackupGlobalExceptionHandlers(ConfigurationRegistry::get()->backupGlobalExceptionHandlers());
}

/**
Expand Down
47 changes: 35 additions & 12 deletions src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,22 @@ abstract class TestCase extends Assert implements Reorderable, SelfDescribing, T
/**
* @var list<callable>
*/
private ?array $backupGlobalErrorHandlers = null;
private ?array $backupGlobalErrorHandlers = null;
private ?bool $shouldBackupGlobalErrorHandlers = null;

/**
* @var list<callable>
*/
private ?array $backupGlobalExceptionHandlers = null;
private ?bool $runClassInSeparateProcess = null;
private ?bool $runTestInSeparateProcess = null;
private bool $preserveGlobalState = false;
private bool $inIsolation = false;
private ?string $expectedException = null;
private ?string $expectedExceptionMessage = null;
private ?string $expectedExceptionMessageRegExp = null;
private null|int|string $expectedExceptionCode = null;
private ?array $backupGlobalExceptionHandlers = null;
private ?bool $shouldBackupGlobalExceptionHandlers = null;
private ?bool $runClassInSeparateProcess = null;
private ?bool $runTestInSeparateProcess = null;
private bool $preserveGlobalState = false;
private bool $inIsolation = false;
private ?string $expectedException = null;
private ?string $expectedExceptionMessage = null;
private ?string $expectedExceptionMessageRegExp = null;
private null|int|string $expectedExceptionCode = null;

/**
* @var list<ExecutionOrderDependency>
Expand Down Expand Up @@ -947,6 +949,22 @@ final public function wasPrepared(): bool
return $this->wasPrepared;
}

/**
* @internal This method is not covered by the backward compatibility promise for PHPUnit
*/
final public function setShouldBackupGlobalErrorHandlers(bool $shouldBackupGlobalErrorHandlers): void
{
$this->shouldBackupGlobalErrorHandlers = $shouldBackupGlobalErrorHandlers;
}

/**
* @internal This method is not covered by the backward compatibility promise for PHPUnit
*/
final public function setShouldBackupGlobalExceptionHandlers(bool $shouldBackupGlobalExceptionHandlers): void
{
$this->shouldBackupGlobalExceptionHandlers = $shouldBackupGlobalExceptionHandlers;
}

/**
* Returns a matcher that matches when the method is executed
* zero or more times.
Expand Down Expand Up @@ -1897,8 +1915,13 @@ private function stopOutputBuffering(): bool

private function snapshotGlobalErrorExceptionHandlers(): void
{
$this->backupGlobalErrorHandlers = $this->getActiveErrorHandlers();
$this->backupGlobalExceptionHandlers = $this->getActiveExceptionHandlers();
if ($this->shouldBackupGlobalErrorHandlers) {
$this->backupGlobalErrorHandlers = $this->getActiveErrorHandlers();
}

if ($this->shouldBackupGlobalExceptionHandlers) {
$this->backupGlobalExceptionHandlers = $this->getActiveExceptionHandlers();
}
}

private function restoreGlobalErrorExceptionHandlers(): void
Expand Down
16 changes: 15 additions & 1 deletion src/TextUI/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@
private int $numberOfTestsBeforeGarbageCollection;
private ?string $generateBaseline;
private bool $debug;
private bool $backupGlobalErrorHandlers;
private bool $backupGlobalExceptionHandlers;

/**
* @var non-negative-int
Expand All @@ -173,7 +175,7 @@
* @param non-empty-list<non-empty-string> $testSuffixes
* @param non-negative-int $shortenArraysForExportThreshold
*/
public function __construct(array $cliArguments, ?string $configurationFile, ?string $bootstrap, bool $cacheResult, ?string $cacheDirectory, ?string $coverageCacheDirectory, Source $source, 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 $failOnDeprecation, bool $failOnEmptyTestSuite, bool $failOnIncomplete, bool $failOnNotice, bool $failOnRisky, bool $failOnSkipped, bool $failOnWarning, bool $stopOnDefect, bool $stopOnDeprecation, bool $stopOnError, bool $stopOnFailure, bool $stopOnIncomplete, bool $stopOnNotice, bool $stopOnRisky, bool $stopOnSkipped, bool $stopOnWarning, bool $outputToStandardErrorStream, int|string $columns, bool $noExtensions, ?string $pharExtensionDirectory, array $extensionBootstrappers, bool $backupGlobals, bool $backupStaticProperties, bool $beStrictAboutChangesToGlobalState, bool $colors, bool $processIsolation, 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 $noProgress, bool $noResults, bool $noOutput, int $executionOrder, int $executionOrderDefects, bool $resolveDependencies, ?string $logfileTeamcity, ?string $logfileJunit, ?string $logfileTestdoxHtml, ?string $logfileTestdoxText, ?string $logEventsText, ?string $logEventsVerboseText, bool $teamCityOutput, bool $testDoxOutput, bool $testDoxOutputSummary, ?array $testsCovering, ?array $testsUsing, ?string $filter, ?string $excludeFilter, array $groups, array $excludeGroups, int $randomOrderSeed, bool $includeUncoveredFiles, TestSuiteCollection $testSuite, string $includeTestSuite, string $excludeTestSuite, ?string $defaultTestSuite, array $testSuffixes, Php $php, bool $controlGarbageCollector, int $numberOfTestsBeforeGarbageCollection, ?string $generateBaseline, bool $debug, int $shortenArraysForExportThreshold)
public function __construct(array $cliArguments, ?string $configurationFile, ?string $bootstrap, bool $cacheResult, ?string $cacheDirectory, ?string $coverageCacheDirectory, Source $source, 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 $failOnDeprecation, bool $failOnEmptyTestSuite, bool $failOnIncomplete, bool $failOnNotice, bool $failOnRisky, bool $failOnSkipped, bool $failOnWarning, bool $stopOnDefect, bool $stopOnDeprecation, bool $stopOnError, bool $stopOnFailure, bool $stopOnIncomplete, bool $stopOnNotice, bool $stopOnRisky, bool $stopOnSkipped, bool $stopOnWarning, bool $outputToStandardErrorStream, int|string $columns, bool $noExtensions, ?string $pharExtensionDirectory, array $extensionBootstrappers, bool $backupGlobals, bool $backupStaticProperties, bool $beStrictAboutChangesToGlobalState, bool $colors, bool $processIsolation, 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 $noProgress, bool $noResults, bool $noOutput, int $executionOrder, int $executionOrderDefects, bool $resolveDependencies, ?string $logfileTeamcity, ?string $logfileJunit, ?string $logfileTestdoxHtml, ?string $logfileTestdoxText, ?string $logEventsText, ?string $logEventsVerboseText, bool $teamCityOutput, bool $testDoxOutput, bool $testDoxOutputSummary, ?array $testsCovering, ?array $testsUsing, ?string $filter, ?string $excludeFilter, array $groups, array $excludeGroups, int $randomOrderSeed, bool $includeUncoveredFiles, TestSuiteCollection $testSuite, string $includeTestSuite, string $excludeTestSuite, ?string $defaultTestSuite, array $testSuffixes, Php $php, bool $controlGarbageCollector, int $numberOfTestsBeforeGarbageCollection, ?string $generateBaseline, bool $debug, int $shortenArraysForExportThreshold, bool $backupGlobalErrorHandlers, bool $backupGlobalExceptionHandlers)
{
$this->cliArguments = $cliArguments;
$this->configurationFile = $configurationFile;
Expand Down Expand Up @@ -280,6 +282,8 @@ public function __construct(array $cliArguments, ?string $configurationFile, ?st
$this->generateBaseline = $generateBaseline;
$this->debug = $debug;
$this->shortenArraysForExportThreshold = $shortenArraysForExportThreshold;
$this->backupGlobalErrorHandlers = $backupGlobalErrorHandlers;
$this->backupGlobalExceptionHandlers = $backupGlobalExceptionHandlers;
}

/**
Expand Down Expand Up @@ -1252,4 +1256,14 @@ public function shortenArraysForExportThreshold(): int
{
return $this->shortenArraysForExportThreshold;
}

public function backupGlobalExceptionHandlers(): bool
{
return $this->backupGlobalExceptionHandlers;
}

public function backupGlobalErrorHandlers(): bool
{
return $this->backupGlobalErrorHandlers;
}
}
Loading