File tree Expand file tree Collapse file tree 2 files changed +44
-8
lines changed Expand file tree Collapse file tree 2 files changed +44
-8
lines changed Original file line number Diff line number Diff line change @@ -126,8 +126,17 @@ public function runPHPCS()
126126 Timing::printRunTime ();
127127 }
128128 } catch (DeepExitException $ e ) {
129- echo $ e ->getMessage ();
130- return $ e ->getCode ();
129+ $ exitCode = $ e ->getCode ();
130+ $ message = $ e ->getMessage ();
131+ if ($ message !== '' ) {
132+ if ($ exitCode === 0 ) {
133+ echo $ e ->getMessage ();
134+ } else {
135+ StatusWriter::write ($ e ->getMessage (), 0 , 0 );
136+ }
137+ }
138+
139+ return $ exitCode ;
131140 }//end try
132141
133142 if ($ numErrors === 0 ) {
@@ -212,8 +221,17 @@ public function runPHPCBF()
212221 Timing::printRunTime ();
213222 }
214223 } catch (DeepExitException $ e ) {
215- echo $ e ->getMessage ();
216- return $ e ->getCode ();
224+ $ exitCode = $ e ->getCode ();
225+ $ message = $ e ->getMessage ();
226+ if ($ message !== '' ) {
227+ if ($ exitCode === 0 ) {
228+ echo $ e ->getMessage ();
229+ } else {
230+ StatusWriter::write ($ e ->getMessage (), 0 , 0 );
231+ }
232+ }
233+
234+ return $ exitCode ;
217235 }//end try
218236
219237 if ($ this ->reporter ->totalFixed === 0 ) {
Original file line number Diff line number Diff line change 1010
1111use PHP_CodeSniffer \Runner ;
1212use PHP_CodeSniffer \Tests \Core \Runner \AbstractRunnerTestCase ;
13+ use PHP_CodeSniffer \Tests \Core \StatusWriterTestHelper ;
1314
1415/**
1516 * Tests for the "All files were excluded" error message.
1819 */
1920final class RunAllFilesExcludedErrorTest extends AbstractRunnerTestCase
2021{
22+ use StatusWriterTestHelper;
2123
2224
2325 /**
@@ -41,6 +43,8 @@ public function testPhpcs($sourceDir, $extraArgs)
4143 $ runner = new Runner ();
4244 $ runner ->runPHPCS ();
4345
46+ $ this ->verifyOutput ();
47+
4448 }//end testPhpcs()
4549
4650
@@ -66,6 +70,8 @@ public function testPhpcbf($sourceDir, $extraArgs)
6670 $ runner = new Runner ();
6771 $ runner ->runPHPCBF ();
6872
73+ $ this ->verifyOutput ();
74+
6975 }//end testPhpcbf()
7076
7177
@@ -111,12 +117,24 @@ private function setupTest($sourceDir, $extraArgs)
111117 $ _SERVER ['argv ' ][] = $ arg ;
112118 }
113119
114- $ message = 'ERROR: No files were checked. ' .PHP_EOL ;
115- $ message .= 'All specified files were excluded or did not match filtering rules. ' .PHP_EOL .PHP_EOL ;
116-
117- $ this ->expectOutputString ($ message );
120+ $ this ->expectNoStdoutOutput ();
118121
119122 }//end setupTest()
120123
121124
125+ /**
126+ * Helper method to verify the output expectation for STDERR.
127+ *
128+ * @return void
129+ */
130+ private function verifyOutput ()
131+ {
132+ $ expected = 'ERROR: No files were checked. ' .PHP_EOL ;
133+ $ expected .= 'All specified files were excluded or did not match filtering rules. ' .PHP_EOL .PHP_EOL ;
134+
135+ $ this ->assertStderrOutputSameString ($ expected );
136+
137+ }//end verifyOutput()
138+
139+
122140}//end class
You can’t perform that action at this time.
0 commit comments