PageRenderTime 25ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/src/Codeception/Command/GenerateGroup.php

https://github.com/pmcjury/Codeception
PHP | 53 lines | 38 code | 10 blank | 5 comment | 1 complexity | e7fb6654d22f6a067c33a63a64bac103 MD5 | raw file
  1. <?php
  2. namespace Codeception\Command;
  3. use Symfony\Component\Console\Command\Command;
  4. use Symfony\Component\Console\Input\InputInterface;
  5. use Symfony\Component\Console\Input\InputOption;
  6. use Symfony\Component\Console\Input\InputArgument;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use Codeception\Lib\Generator\Group as GroupGenerator;
  9. /**
  10. * Creates empty Group file - extension which handles all group events.
  11. *
  12. * * `codecept g:group Admin`
  13. */
  14. class GenerateGroup extends Command
  15. {
  16. use Shared\FileSystem;
  17. use Shared\Config;
  18. protected function configure()
  19. {
  20. $this->setDefinition(array(
  21. new InputArgument('group', InputArgument::REQUIRED, 'Group class name'),
  22. new InputOption('config', 'c', InputOption::VALUE_OPTIONAL, 'Use custom path for config'),
  23. ));
  24. }
  25. public function execute(InputInterface $input, OutputInterface $output)
  26. {
  27. $config = $this->getGlobalConfig($input->getOption('config'));
  28. $group = $input->getArgument('group');
  29. $class = ucfirst($group);
  30. $path = $this->buildPath($config['paths']['tests'].'/_groups/', $class);
  31. $filename = $this->completeSuffix($class, 'Group');
  32. $filename = $path.$filename;
  33. $this->introduceAutoloader($config['paths']['tests'].DIRECTORY_SEPARATOR.$config['settings']['bootstrap'],'Group','_groups');
  34. $gen = new GroupGenerator($config, $group);
  35. $res = $this->save($filename, $gen->produce());
  36. if (!$res) {
  37. $output->writeln("<error>Group $filename already exists</error>");
  38. return;
  39. }
  40. $output->writeln("<info>Group extension was created in $filename</info>");
  41. $output->writeln('To use this group extension, include it to "extensions" option of global Codeception config.');
  42. }
  43. }