diff --git a/src/Framework/TestBuilder.php b/src/Framework/TestBuilder.php index 08691a1e48f..f0d470ed6e4 100644 --- a/src/Framework/TestBuilder.php +++ b/src/Framework/TestBuilder.php @@ -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()); } /** diff --git a/src/Framework/TestCase.php b/src/Framework/TestCase.php index d671832d0f2..73626427e31 100644 --- a/src/Framework/TestCase.php +++ b/src/Framework/TestCase.php @@ -135,20 +135,22 @@ abstract class TestCase extends Assert implements Reorderable, SelfDescribing, T /** * @var list */ - private ?array $backupGlobalErrorHandlers = null; + private ?array $backupGlobalErrorHandlers = null; + private ?bool $shouldBackupGlobalErrorHandlers = null; /** * @var list */ - 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 @@ -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. @@ -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 diff --git a/src/TextUI/Configuration/Configuration.php b/src/TextUI/Configuration/Configuration.php index c56a53c07ba..338aa8e3639 100644 --- a/src/TextUI/Configuration/Configuration.php +++ b/src/TextUI/Configuration/Configuration.php @@ -156,6 +156,8 @@ private int $numberOfTestsBeforeGarbageCollection; private ?string $generateBaseline; private bool $debug; + private bool $backupGlobalErrorHandlers; + private bool $backupGlobalExceptionHandlers; /** * @var non-negative-int @@ -173,7 +175,7 @@ * @param non-empty-list $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; @@ -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; } /** @@ -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; + } }