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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Console/DevTestsRunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($runCommands as $key) {
[$dir, $options] = $this->commands[$key];
$dirName = realpath(BP . '/dev/tests/' . $dir);
if ($dirName === false) {
$output->writeln('<error>Test directory not found: ' . BP . '/dev/tests/' . $dir . '</error>');
$failures[] = 'missing directory: ' . $dir;
continue;
}
chdir($dirName);
// Build ParaTest command
$command = sprintf(
Expand All @@ -116,6 +121,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$command .= ' ' . $commandArguments;
}
$this->logCommand($output, $dirName, $command);
// $commandArguments is passed through unescaped, same as Magento's native
// dev:tests:run: it is meant to carry multiple shell tokens (e.g. "--filter=Foo bar.php"),
// so escaping the whole string would break that. This command is a local dev CLI tool
// invoked directly by the developer, not fed untrusted input from a remote caller.
// passthru() call have to be here.
// phpcs:ignore Magento2.Security.InsecureFunction
passthru($command, $returnVal);
Expand Down
24 changes: 24 additions & 0 deletions Test/Unit/Console/DevTestsRunCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,28 @@ public function testProcessesCannotBeBelowOne()
$tester->getDisplay()
);
}

public function testMissingTestDirectoryIsReportedAsFailure()
{
global $devTestsRunCommandTestResult;
$devTestsRunCommandTestResult = 0;

$dir = BP . '/dev/tests/unit';
rename($dir, $dir . '.bak');

try {
$tester = new CommandTester($this->command);
$tester->execute([DevTestsRunCommand::INPUT_ARG_TYPE => 'unit']);

$output = $tester->getDisplay();
$this->assertStringContainsString(
'Test directory not found',
$output,
'A missing test directory should be reported instead of chdir()-ing into it blindly'
);
$this->assertStringContainsString('FAILED - ', $output);
} finally {
rename($dir . '.bak', $dir);
}
}
}
Loading