Licitator 1.0
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
2.3 KiB

5 years ago
  1. <?= "<?php\n" ?>
  2. namespace <?= $namespace; ?>;
  3. use PHPUnit\Framework\MockObject\MockBuilder;
  4. use Symfony\Bundle\FrameworkBundle\Client;
  5. use Symfony\Bundle\FrameworkBundle\Console\Application;
  6. use Symfony\Bundle\FrameworkBundle\KernelBrowser;
  7. use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
  8. use Symfony\Component\BrowserKit\Cookie;
  9. use Symfony\Component\Console\Tester\CommandTester;
  10. use Symfony\Component\DependencyInjection\ContainerInterface;
  11. use Symfony\Component\DependencyInjection\ResettableContainerInterface;
  12. use Symfony\Component\DomCrawler\Crawler;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  15. use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
  16. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  17. use Symfony\Component\Security\Core\User\UserInterface;
  18. class <?= $class_name ?> extends WebTestCase
  19. {
  20. public function test<?= $class_name ?>()
  21. {
  22. $this->runCommand(<?= $class_name ?>::getCommandName());
  23. }
  24. /**
  25. * Builds up the environment to run the given command.
  26. *
  27. * @param string $name
  28. * @param array $params
  29. * @param bool $reuseKernel
  30. *
  31. * @return CommandTester
  32. */
  33. protected function runCommand(string $name, array $params = [], bool $reuseKernel = false): CommandTester
  34. {
  35. if (!$reuseKernel) {
  36. if (null !== static::$kernel) {
  37. static::$kernel->shutdown();
  38. }
  39. $kernel = static::$kernel = static::createKernel(['environment' => $this->environment]);
  40. $kernel->boot();
  41. } else {
  42. $kernel = $this->getContainer()->get('kernel');
  43. }
  44. $application = new Application($kernel);
  45. $options = [
  46. 'interactive' => false,
  47. 'decorated' => $this->getDecorated(),
  48. 'verbosity' => $this->getVerbosityLevel(),
  49. ];
  50. $command = $application->find($name);
  51. $commandTester = new CommandTester($command);
  52. if (null !== $inputs = $this->getInputs()) {
  53. $commandTester->setInputs($inputs);
  54. $options['interactive'] = true;
  55. $this->inputs = null;
  56. }
  57. $commandTester->execute(
  58. array_merge(['command' => $command->getName()], $params),
  59. $options
  60. );
  61. return $commandTester;
  62. }
  63. }