diff --git a/src/Generators/Markdown.php b/src/Generators/Markdown.php index de207ec601..97e8717c1f 100644 --- a/src/Generators/Markdown.php +++ b/src/Generators/Markdown.php @@ -69,9 +69,10 @@ protected function printFooter() { // Turn off errors so we don't get timezone warnings if people // don't have their timezone set. - error_reporting(0); + $errorLevel = error_reporting(0); echo 'Documentation generated on '.date('r'); echo ' by [PHP_CodeSniffer '.Config::VERSION.'](https://github.com/PHPCSStandards/PHP_CodeSniffer)'.PHP_EOL; + error_reporting($errorLevel); }//end printFooter() diff --git a/tests/Core/Generators/HTMLTest.php b/tests/Core/Generators/HTMLTest.php index 4140937ab7..211d8c446e 100644 --- a/tests/Core/Generators/HTMLTest.php +++ b/tests/Core/Generators/HTMLTest.php @@ -101,4 +101,32 @@ public function testFooter() }//end testFooter() + /** + * Safeguard that the footer logic doesn't permanently change the error level. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + * + * @return void + */ + public function testFooterResetsErrorReportingToOriginalSetting() + { + $expected = error_reporting(); + + // Set up the ruleset. + $standard = __DIR__.'/OneDocTest.xml'; + $config = new ConfigDouble(["--standard=$standard"]); + $ruleset = new Ruleset($config); + + // We know there will be output, but we're not interested in the output for this test. + ob_start(); + $generator = new HTMLDouble($ruleset); + $generator->printRealFooter(); + ob_end_clean(); + + $this->assertSame($expected, error_reporting()); + + }//end testFooterResetsErrorReportingToOriginalSetting() + + }//end class diff --git a/tests/Core/Generators/MarkdownTest.php b/tests/Core/Generators/MarkdownTest.php index 9a3e540044..394b0ce5c1 100644 --- a/tests/Core/Generators/MarkdownTest.php +++ b/tests/Core/Generators/MarkdownTest.php @@ -99,4 +99,32 @@ public function testFooter() }//end testFooter() + /** + * Safeguard that the footer logic doesn't permanently change the error level. + * + * @runInSeparateProcess + * @preserveGlobalState disabled + * + * @return void + */ + public function testFooterResetsErrorReportingToOriginalSetting() + { + $expected = error_reporting(); + + // Set up the ruleset. + $standard = __DIR__.'/OneDocTest.xml'; + $config = new ConfigDouble(["--standard=$standard"]); + $ruleset = new Ruleset($config); + + // We know there will be output, but we're not interested in the output for this test. + ob_start(); + $generator = new MarkdownDouble($ruleset); + $generator->printRealFooter(); + ob_end_clean(); + + $this->assertSame($expected, error_reporting()); + + }//end testFooterResetsErrorReportingToOriginalSetting() + + }//end class