diff --git a/src/Runner.php b/src/Runner.php index db0e26d91b..24d1d3009a 100644 --- a/src/Runner.php +++ b/src/Runner.php @@ -351,7 +351,7 @@ private function run() } $numFiles = count($todo); - if ($numFiles === 0) { + if ($numFiles === 0 && Config::getConfigData('allow_empty_file_list') !== '1') { $error = 'ERROR: No files were checked.' . PHP_EOL; $error .= 'All specified files were excluded or did not match filtering rules.' . PHP_EOL . PHP_EOL; throw new DeepExitException($error, ExitCode::PROCESS_ERROR); diff --git a/src/Util/Help.php b/src/Util/Help.php index c9faf71d76..323afbe467 100644 --- a/src/Util/Help.php +++ b/src/Util/Help.php @@ -579,7 +579,7 @@ private function getAllOptions() 'config-explain' => [ 'text' => 'Default values for a selection of options can be stored in a user-specific CodeSniffer.conf configuration file.' . "\n" - . 'This applies to the following options: "default_standard", "report_format", "tab_width", "encoding", "severity", "error_severity", "warning_severity", "show_warnings", "report_width", "show_progress", "quiet", "colors", "cache", "parallel", "installed_paths", "php_version", "ignore_errors_on_exit", "ignore_warnings_on_exit", "ignore_non_auto_fixable_on_exit".', + . 'This applies to the following options: "default_standard", "report_format", "tab_width", "encoding", "severity", "error_severity", "warning_severity", "show_warnings", "report_width", "show_progress", "quiet", "colors", "cache", "parallel", "installed_paths", "php_version", "ignore_errors_on_exit", "ignore_warnings_on_exit", "ignore_non_auto_fixable_on_exit", "allow_empty_file_list".', ], 'config-show' => [ 'argument' => '--config-show', diff --git a/tests/Core/Runner/RunAllFilesExcludedErrorTest.php b/tests/Core/Runner/RunAllFilesExcludedErrorTest.php index c38420cdae..145ecf32d9 100644 --- a/tests/Core/Runner/RunAllFilesExcludedErrorTest.php +++ b/tests/Core/Runner/RunAllFilesExcludedErrorTest.php @@ -73,6 +73,67 @@ public function testPhpcbf($sourceDir, $extraArgs) } + /** + * Verify that the "All files were excluded" error message is not shown when all files are excluded and it is + * allowed via --allow-empty-file-list (PHPCS). + * + * @param string $sourceDir The (fixture) directory to scan for files. + * @param array $extraArgs Any extra arguments to pass on the command line. + * + * @dataProvider data + * + * @return void + */ + public function testPhpcsAllowEmpty($sourceDir, $extraArgs) + { + if (PHP_CODESNIFFER_CBF === true) { + $this->markTestSkipped('This test needs CS mode to run'); + } + + $extraArgs[] = '--runtime-set'; + $extraArgs[] = 'allow_empty_file_list'; + $extraArgs[] = '1'; + $this->setupTest($sourceDir, $extraArgs); + + $runner = new Runner(); + $runner->runPHPCS(); + + $regex = '`^(Time: [0-9]+ms; Memory: [0-9\.]+MB' . PHP_EOL . ')?$`'; + $this->assertStderrOutputMatchesRegex($regex); + } + + + /** + * Verify that the "All files were excluded" error message is not shown when all files are excluded and it is + * * allowed via --allow-empty-file-list (PHPCBF). + * + * @param string $sourceDir The (fixture) directory to scan for files. + * @param array $extraArgs Any extra arguments to pass on the command line. + * + * @dataProvider data + * @group CBF + * + * @return void + */ + public function testPhpcbfAllowEmpty($sourceDir, $extraArgs) + { + if (PHP_CODESNIFFER_CBF === false) { + $this->markTestSkipped('This test needs CBF mode to run'); + } + + $extraArgs[] = '--runtime-set'; + $extraArgs[] = 'allow_empty_file_list'; + $extraArgs[] = '1'; + $this->setupTest($sourceDir, $extraArgs); + + $runner = new Runner(); + $runner->runPHPCBF(); + + $regex = '`^.*No violations were found.*(Time: [0-9]+ms; Memory: [0-9\.]+MB' . PHP_EOL . ')?$`m'; + $this->assertStderrOutputMatchesRegex($regex); + } + + /** * Data provider. *