Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RunTestCommand.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types = 1);
7 
9 
10 use Symfony\Component\Console\Input\ArrayInput;
11 use Symfony\Component\Console\Input\InputArgument;
12 use Symfony\Component\Console\Input\InputInterface;
13 use Symfony\Component\Console\Input\InputOption;
14 use Symfony\Component\Console\Output\OutputInterface;
15 use Symfony\Component\Process\Process;
17 
19 {
25  protected function configure()
26  {
27  $this->setName("run:test")
28  ->setDescription("generation and execution of test(s) defined in xml")
29  ->addArgument(
30  'name',
31  InputArgument::REQUIRED | InputArgument::IS_ARRAY,
32  "name of tests to generate and execute"
33  )->addOption('skip-generate', 'k', InputOption::VALUE_NONE, "skip generation and execute existing test")
34  ->addOption(
35  "force",
36  'f',
37  InputOption::VALUE_NONE,
38  'force generation of tests regardless of Magento Instance Configuration'
39  );
40 
41  parent::configure();
42  }
43 
54  protected function execute(InputInterface $input, OutputInterface $output)
55  {
56  $tests = $input->getArgument('name');
57  $skipGeneration = $input->getOption('skip-generate');
58  $force = $input->getOption('force');
59  $remove = $input->getOption('remove');
60 
61  if ($skipGeneration and $remove) {
62  // "skip-generate" and "remove" options cannot be used at the same time
63  throw new TestFrameworkException(
64  "\"skip-generate\" and \"remove\" options can not be used at the same time."
65  );
66  }
67 
68  if (!$skipGeneration) {
69  $command = $this->getApplication()->find('generate:tests');
70  $args = [
71  '--tests' => json_encode([
72  'tests' => $tests,
73  'suites' => null
74  ]),
75  '--force' => $force,
76  '--remove' => $remove
77  ];
78  $command->run(new ArrayInput($args), $output);
79  }
80 
81  // we only generate relevant tests here so we can execute "all tests"
82  $codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . " run functional --verbose --steps";
83 
84  $process = new Process($codeceptionCommand);
85  $process->setWorkingDirectory(TESTS_BP);
86  $process->setIdleTimeout(600);
87  $process->setTimeout(0);
88  $process->run(
89  function ($type, $buffer) use ($output) {
90  $output->write($buffer);
91  }
92  );
93  }
94 }
const PROJECT_ROOT
Definition: _bootstrap.php:8
$type
Definition: item.phtml:13
execute(InputInterface $input, OutputInterface $output)