Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CleanProjectCommand.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types = 1);
7 
9 
10 use Symfony\Component\Console\Command\Command;
11 use Symfony\Component\Console\Input\InputInterface;
12 use Symfony\Component\Console\Input\InputOption;
13 use Symfony\Component\Console\Output\OutputInterface;
14 use Symfony\Component\Filesystem\Filesystem;
15 use Symfony\Component\Finder\Finder;
16 
17 class CleanProjectCommand extends Command
18 {
20  // codeception.yml file for top level config
21  TESTS_BP . DIRECTORY_SEPARATOR . 'codeception.yml',
22  // functional.suite.yml for test execution config
23  TESTS_BP . DIRECTORY_SEPARATOR . 'tests' . DIRECTORY_SEPARATOR . 'functional.suite.yml',
24  // Acceptance Tester Actions generated by codeception
25  FW_BP . '/src/Magento/FunctionalTestingFramework/_generated',
26  // AcceptanceTester Class generated by codeception
27  FW_BP . '/src/Magento/FunctionalTestingFramework/AcceptanceTester.php'
28  ];
29 
30  const GENERATED_FILES = [
31  TESTS_MODULE_PATH . '/_generated'
32  ];
33 
39  protected function configure()
40  {
41  $this->setName('reset')
42  ->setDescription(
43  'This command will clean any configuration files from the environment (not including .env), as well as generated artifacts.' // phpcs:ignore
44  )
45  ->addOption('hard', null, InputOption::VALUE_NONE, "parameter to force reset of configuration files.");
46  }
47 
56  protected function execute(InputInterface $input, OutputInterface $output)
57  {
58  $isHardReset = $input->getOption('hard');
59  $fileSystem = new Filesystem();
60  $finder = new Finder();
61  $finder->files()->name('*.php')->in(realpath(FW_BP . '/src/Magento/FunctionalTestingFramework/Group/'));
62  $filesForRemoval = [];
63 
64  // include config files if user specifies a hard reset for deletion
65  if ($isHardReset) {
66  $filesForRemoval = array_merge($filesForRemoval, self::CONFIGURATION_FILES);
67  }
68 
69  // include the files mftf generates during test execution in TESTS_BP for deletion
70  $filesForRemoval = array_merge($filesForRemoval, self::GENERATED_FILES);
71 
72  if ($output->isVerbose()) {
73  $output->writeln('Deleting Files:');
74  }
75 
76  // delete any suite based group files
77  foreach ($finder->files() as $file) {
78  if ($output->isVerbose()) {
79  $output->writeln($file->getRealPath());
80  }
81 
82  $fileSystem->remove($file);
83  }
84 
85  // delete files specified for removal
86  foreach ($filesForRemoval as $fileForRemoval) {
87  if ($fileSystem->exists($fileForRemoval) && $output->isVerbose()) {
88  $output->writeln($fileForRemoval);
89  }
90 
91  $fileSystem->remove($fileForRemoval);
92  }
93 
94  $output->writeln('mftf files removed from filesystem.');
95  }
96 }
execute(InputInterface $input, OutputInterface $output)