api + ApiTester * * `codecept g:suite integration Code` -> integration + CodeTester * * `codecept g:suite frontend Front` -> frontend + FrontTester * */ class GenerateSuite extends Command { use Shared\FileSystem; use Shared\Config; use Shared\Style; protected function configure() { $this->setDefinition([ new InputArgument('suite', InputArgument::REQUIRED, 'suite to be generated'), new InputArgument('actor', InputArgument::OPTIONAL, 'name of new actor class'), ]); } public function getDescription() { return 'Generates new test suite'; } public function execute(InputInterface $input, OutputInterface $output) { $this->addStyles($output); $suite = $input->getArgument('suite'); $actor = $input->getArgument('actor'); if ($this->containsInvalidCharacters($suite)) { $output->writeln("Suite name '$suite' contains invalid characters. ([A-Za-z0-9_])."); return; } $config = $this->getGlobalConfig(); if (!$actor) { $actor = ucfirst($suite) . $config['actor_suffix']; } $dir = Configuration::testsDir(); if (file_exists($dir . $suite . '.suite.yml')) { throw new \Exception("Suite configuration file '$suite.suite.yml' already exists."); } $this->createDirectoryFor($dir . $suite); if ($config['settings']['bootstrap']) { // generate bootstrap file $this->createFile( $dir . $suite . DIRECTORY_SEPARATOR . $config['settings']['bootstrap'], "createDirectoryFor( Configuration::supportDir() . "Helper", "$helperName.php" ) . "$helperName.php"; $gen = new Helper($helperName, $config['namespace']); // generate helper $this->createFile( $file, $gen->produce() ); $output->writeln("Helper " . $gen->getHelperName() . " was created in $file"); $yamlSuiteConfigTemplate = <<createFile( $dir . $suite . '.suite.yml', $yamlSuiteConfig = (new Template($yamlSuiteConfigTemplate)) ->place('actor', $actor) ->place('helper', $gen->getHelperName()) ->produce() ); Configuration::append(Yaml::parse($yamlSuiteConfig)); $actorGenerator = new ActorGenerator(Configuration::config()); $content = $actorGenerator->produce(); $file = $this->createDirectoryFor( Configuration::supportDir(), $actor ) . $this->getShortClassName($actor); $file .= '.php'; $this->createFile($file, $content); $output->writeln("Actor " . $actor . " was created in $file"); $output->writeln("Suite config $suite.suite.yml was created."); $output->writeln(' '); $output->writeln("Next steps:"); $output->writeln("1. Edit $suite.suite.yml to enable modules for this suite"); $output->writeln("2. Create first test with generate:cest testName ( or test|cept) command"); $output->writeln("3. Run tests of this suite with codecept run $suite command"); $output->writeln("Suite $suite generated"); } private function containsInvalidCharacters($suite) { return preg_match('#[^A-Za-z0-9_]#', $suite) ? true : false; } }