YourCustomCommand.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /**
  3. * An example for a custom command to add to the framework.
  4. *
  5. * @author Tobias Matthaiou <tm@solutionDrive.de>
  6. * @date 27.01.16
  7. */
  8. namespace Project\Command;
  9. use \Symfony\Component\Console\Command\Command;
  10. use \Codeception\CustomCommandInterface;
  11. use \Symfony\Component\Console\Input\InputOption;
  12. use \Symfony\Component\Console\Input\InputInterface;
  13. use \Symfony\Component\Console\Output\OutputInterface;
  14. class YourCustomCommand extends Command implements CustomCommandInterface
  15. {
  16. use \Codeception\Command\Shared\FileSystem;
  17. use \Codeception\Command\Shared\Config;
  18. /**
  19. * returns the name of the command
  20. *
  21. * @return string
  22. */
  23. public static function getCommandName()
  24. {
  25. return "myProject:yourCommand";
  26. }
  27. /**
  28. * Configures the current command.
  29. */
  30. protected function configure()
  31. {
  32. $this->setDefinition(array(
  33. new InputOption('something', 's', InputOption::VALUE_NONE, 'The Message will show you something more'),
  34. ));
  35. parent::configure();
  36. }
  37. /**
  38. * Returns the description for the command.
  39. *
  40. * @return string The description for the command
  41. */
  42. public function getDescription()
  43. {
  44. return "This is your command make something";
  45. }
  46. /**
  47. * Executes the current command.
  48. *
  49. * This method is not abstract because you can use this class
  50. * as a concrete class. In this case, instead of defining the
  51. * execute() method, you set the code to execute by passing
  52. * a Closure to the setCode() method.
  53. *
  54. * @param \Symfony\Component\Console\Input\InputInterface $input An InputInterface instance
  55. * @param \Symfony\Component\Console\Output\OutputInterface $output An OutputInterface instance
  56. *
  57. * @return null|int null or 0 if everything went fine, or an error code
  58. *
  59. * @throws LogicException When this abstract method is not implemented
  60. *
  61. * @see setCode()
  62. */
  63. protected function execute(InputInterface $input, OutputInterface $output)
  64. {
  65. $messageEnd = "!" . PHP_EOL;
  66. if ($input->getOption('something')) {
  67. $messageEnd = "," . PHP_EOL;
  68. $messageEnd .= "push the Button!" . PHP_EOL;
  69. }
  70. echo "Hello Rabbit";
  71. echo $messageEnd . PHP_EOL;
  72. }
  73. }