protected function execute(InputInterface $input, OutputInterface $output)
{
$suites = $input->getArgument('suites');
if (empty($suites)) {
$output->writeln("<error>\nPlease specify at least one suite\n</error>");
return;
}
if (false !== strpos($suites, ',')) {
$suites = explode(',', $suites);
} else {
$suites = [$suites];
}
$path = $this->getRootPath();
chdir($path);
if (!file_exists('codeception.yml')) {
$output->writeln("<error>\nMissing 'codeception.yml' file\n</error>");
return;
}
// read test folder location from codeception.yml file
$config = Yaml::parse('codeception.yml');
$testsPath = empty($config['paths']['tests']) ? 'tests' : $config['paths']['tests'];
if (!is_dir($testsPath)) {
$output->writeln("<error>\nThe tests paths is not set or not accessible.\n</error>");
return;
}
$testsPath = DIRECTORY_SEPARATOR . Utils::unleadslashit(Utils::untrailslashit($testsPath)) . DIRECTORY_SEPARATOR;
if (!count($suites)) {
$output->writeln("<error>\nPlease specify at least one suite.\n</error>");
return;
}
$suitesEntries = [];
$suffix = $input->getArgument('suffix');
foreach ($suites as $suite) {
$suitePath = $path . $testsPath . $suite;
if (!file_exists($suitePath)) {
$output->writeln("<error>\nThe suite '{$suite}' folder cannot be found\n</error>");
return;
}
$args = ['name' => ucfirst($suite), 'suffix' => $suffix, 'pathToFiles' => Utils::unleadslashit($testsPath) . $suite];
$suitesEntries[] = $this->getTestsuiteEntry($args);
}
// maybe the user already did this and modified the default file?
$xmlFile = 'phpunit.xml';
$previousConfig = $this->loadPreviousConfig($xmlFile);
$xmlFileContents = $this->getXmlFileContent($suitesEntries, $testsPath, $previousConfig);
$vendor = $input->getArgument('vendor');
if (!is_dir($this->getRootPath() . DIRECTORY_SEPARATOR . Utils::unleadslashit($vendor))) {
$output->writeln("<error>\nThe vendor folder {$vendor} does not exist\n</error>");
return;
}
file_put_contents($xmlFile, $xmlFileContents);
$bootstrapFileContents = $this->getBootstrapFileContents($vendor, $testsPath);
file_put_contents($this->bootstrapFilePath($testsPath), $bootstrapFileContents);
}