Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Util/Help.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
61 changes: 61 additions & 0 deletions tests/Core/Runner/RunAllFilesExcludedErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> $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<string> $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.
*
Expand Down