@@ -71,9 +71,10 @@ final class CheckTest extends XTestCase
7171 */
7272 protected function setUpPrerequisites ()
7373 {
74- $ this ->config = $ this ->createCompatibleMockBuilderWithMethods (Config::class, [])
74+ $ this ->config = $ this ->createCompatibleMockBuilderWithMethods (Config::class, [])
7575 ->disableOriginalConstructor ()
7676 ->getMock ();
77+ $ this ->setObjectProperty ($ this ->config , 'showColored ' , false );
7778 $ this ->extractor = new CodeBlocksExtractor ();
7879 $ cliArgs = ['--runtime-set ' , 'installed_paths ' , \realpath (self ::STANDARD_DIR )];
7980 $ this ->phpcsConfig = PHPCSConfigLoader::getPHPCSConfigInstance ($ cliArgs );
@@ -195,7 +196,7 @@ public function testGetXmlDocValidator()
195196
196197 /**
197198 * Test the run() method without mocking the Check class. Test only the two happy paths.
198- * More detailed tests are performed in the testRun() method.
199+ * More detailed tests are performed in the testRun() method. Colored output is disabled.
199200 *
200201 * @dataProvider dataRunWithoutMockingCheckClass
201202 *
@@ -206,7 +207,50 @@ public function testGetXmlDocValidator()
206207 *
207208 * @return void
208209 */
209- public function testRunWithoutMockingCheckClass (array $ xmlDocs , int $ expectedExitCode , string $ expectedStdout , string $ expectedStderr )
210+ public function testRunWithoutMockingCheckClassWithoutColoredOutput (array $ xmlDocs , int $ expectedExitCode , string $ expectedStdout , string $ expectedStderr )
211+ {
212+ $ this ->executeTestForRunMethodWithoutMockingCheckClass ($ xmlDocs , $ expectedExitCode , $ expectedStdout , $ expectedStderr );
213+ }
214+
215+ /**
216+ * Test the run() method without mocking the Check class. Test only the two happy paths.
217+ * More detailed tests are performed in the testRun() method. Colored output is enabled.
218+ *
219+ * @dataProvider dataRunWithoutMockingCheckClass
220+ *
221+ * @param array<string> $xmlDocs XML doc files to process.
222+ * @param int $expectedExitCode Expected exit code from the run() method.
223+ * @param string $expectedStdout Expected stdout output.
224+ * @param string $expectedStderr Expected stderr output.
225+ *
226+ * @return void
227+ */
228+ public function testRunWithoutMockingCheckClassWithColoredOutput (array $ xmlDocs , int $ expectedExitCode , string $ expectedStdout , string $ expectedStderr )
229+ {
230+ $ this ->setObjectProperty ($ this ->config , 'showColored ' , true );
231+
232+ if (empty ($ expectedStderr ) === true ) {
233+ $ expectedStdout = "\033[32m {$ expectedStdout }\033[0m " ;
234+ } elseif (empty ($ expectedStdout ) === false ) {
235+ $ expectedStdout = "\033[31m {$ expectedStdout }\033[0m " ;
236+ }
237+
238+ $ this ->executeTestForRunMethodWithoutMockingCheckClass ($ xmlDocs , $ expectedExitCode , $ expectedStdout , $ expectedStderr );
239+ }
240+
241+ /**
242+ * Helper method to execute the run() method of the Check class without mocking it.
243+ * This is used for both testRunWithoutMockingCheckClassWithoutColoredOutput and
244+ * testRunWithoutMockingCheckClassWithColoredOutput.
245+ *
246+ * @param array<string> $xmlDocs XML doc files to process.
247+ * @param int $expectedExitCode Expected exit code from the run() method.
248+ * @param string $expectedStdout Expected stdout output.
249+ * @param string $expectedStderr Expected stderr output.
250+ *
251+ * @return void
252+ */
253+ protected function executeTestForRunMethodWithoutMockingCheckClass (array $ xmlDocs , int $ expectedExitCode , string $ expectedStdout , string $ expectedStderr )
210254 {
211255 $ this ->setObjectProperty ($ this ->config , 'projectRoot ' , \realpath (self ::FIXTURE_DIR ));
212256 $ this ->setObjectProperty ($ this ->config , 'targetPaths ' , $ xmlDocs );
0 commit comments