Skip to content

Commit 06ebc1c

Browse files
authored
Merge pull request #688 from PHPCSStandards/feature/generators-html-markdown-error-reporting
Generators/Markdown: reset error_reporting to original value
2 parents 6792fb1 + 3820695 commit 06ebc1c

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

src/Generators/Markdown.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,10 @@ protected function printFooter()
7373
{
7474
// Turn off errors so we don't get timezone warnings if people
7575
// don't have their timezone set.
76-
error_reporting(0);
76+
$errorLevel = error_reporting(0);
7777
echo 'Documentation generated on '.date('r');
7878
echo ' by [PHP_CodeSniffer '.Config::VERSION.'](https://github.com/PHPCSStandards/PHP_CodeSniffer)'.PHP_EOL;
79+
error_reporting($errorLevel);
7980

8081
}//end printFooter()
8182

tests/Core/Generators/HTMLTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,32 @@ public function testFooter()
101101
}//end testFooter()
102102

103103

104+
/**
105+
* Safeguard that the footer logic doesn't permanently change the error level.
106+
*
107+
* @runInSeparateProcess
108+
* @preserveGlobalState disabled
109+
*
110+
* @return void
111+
*/
112+
public function testFooterResetsErrorReportingToOriginalSetting()
113+
{
114+
$expected = error_reporting();
115+
116+
// Set up the ruleset.
117+
$standard = __DIR__.'/OneDocTest.xml';
118+
$config = new ConfigDouble(["--standard=$standard"]);
119+
$ruleset = new Ruleset($config);
120+
121+
// We know there will be output, but we're not interested in the output for this test.
122+
ob_start();
123+
$generator = new HTMLDouble($ruleset);
124+
$generator->printRealFooter();
125+
ob_end_clean();
126+
127+
$this->assertSame($expected, error_reporting());
128+
129+
}//end testFooterResetsErrorReportingToOriginalSetting()
130+
131+
104132
}//end class

tests/Core/Generators/MarkdownTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,32 @@ public function testFooter()
9999
}//end testFooter()
100100

101101

102+
/**
103+
* Safeguard that the footer logic doesn't permanently change the error level.
104+
*
105+
* @runInSeparateProcess
106+
* @preserveGlobalState disabled
107+
*
108+
* @return void
109+
*/
110+
public function testFooterResetsErrorReportingToOriginalSetting()
111+
{
112+
$expected = error_reporting();
113+
114+
// Set up the ruleset.
115+
$standard = __DIR__.'/OneDocTest.xml';
116+
$config = new ConfigDouble(["--standard=$standard"]);
117+
$ruleset = new Ruleset($config);
118+
119+
// We know there will be output, but we're not interested in the output for this test.
120+
ob_start();
121+
$generator = new MarkdownDouble($ruleset);
122+
$generator->printRealFooter();
123+
ob_end_clean();
124+
125+
$this->assertSame($expected, error_reporting());
126+
127+
}//end testFooterResetsErrorReportingToOriginalSetting()
128+
129+
102130
}//end class

0 commit comments

Comments
 (0)