PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Codeception/Command/GenerateHelper.php

https://github.com/pmcjury/Codeception
PHP | 52 lines | 38 code | 8 blank | 6 comment | 2 complexity | fd8d35f8e08e07397d698e8fa3c54db9 MD5 | raw file
  1. <?php
  2. namespace Codeception\Command;
  3. use Codeception\Lib\Generator\Helper;
  4. use Symfony\Component\Console\Input\InputArgument;
  5. use Symfony\Component\Console\Input\InputInterface;
  6. use Symfony\Component\Console\Input\InputOption;
  7. use Symfony\Component\Console\Output\OutputInterface;
  8. use Symfony\Component\Console\Command\Command;
  9. /**
  10. * Creates empty Helper class.
  11. *
  12. * * `codecept g:helper MyHelper`
  13. *
  14. */
  15. class GenerateHelper extends Command
  16. {
  17. use Shared\FileSystem;
  18. use Shared\Config;
  19. protected function configure()
  20. {
  21. $this->setDefinition(
  22. array(
  23. new InputArgument('name', InputArgument::REQUIRED, 'suite to be generated'),
  24. new InputOption('config', 'c', InputOption::VALUE_OPTIONAL, 'Use custom path for config'),
  25. )
  26. );
  27. }
  28. public function getDescription()
  29. {
  30. return 'Generates new helper';
  31. }
  32. public function execute(InputInterface $input, OutputInterface $output)
  33. {
  34. $name = ucfirst($input->getArgument('name'));
  35. $config = \Codeception\Configuration::config($input->getOption('config'));
  36. $file = \Codeception\Configuration::helpersDir() . "{$name}Helper.php";
  37. $res = $this->save($file, (new Helper($name, $config['namespace']))->produce());
  38. if ($res) {
  39. $output->writeln("<info>Helper $file created</info>");
  40. } else {
  41. $output->writeln("<error>Error creating helper $file</error>");
  42. }
  43. }
  44. }