arg.phpt 742 B

123456789101112131415161718192021222324252627282930
  1. --TEST--
  2. Single Application can be executed
  3. --ARGS--
  4. You
  5. --FILE--
  6. <?php
  7. use Symfony\Component\Console\Input\InputArgument;
  8. use Symfony\Component\Console\Input\InputInterface;
  9. use Symfony\Component\Console\Output\OutputInterface;
  10. use Symfony\Component\Console\SingleCommandApplication;
  11. $vendor = __DIR__;
  12. while (!file_exists($vendor.'/vendor')) {
  13. $vendor = dirname($vendor);
  14. }
  15. require $vendor.'/vendor/autoload.php';
  16. (new SingleCommandApplication())
  17. ->addArgument('who', InputArgument::OPTIONAL, 'Who', 'World')
  18. ->setCode(function (InputInterface $input, OutputInterface $output): int {
  19. $output->writeln(sprintf('Hello %s!', $input->getArgument('who')));
  20. return 0;
  21. })
  22. ->run()
  23. ;
  24. ?>
  25. --EXPECT--
  26. Hello You!