'phpunit.xml', 'Pest.php' => 'tests/Pest.php', 'ExampleTest.php' => 'tests/ExampleTest.php', ]; /** * @var OutputInterface */ private $output; /** * @var TestSuite */ private $testSuite; /** * Creates a new Plugin instance. */ public function __construct(TestSuite $testSuite, OutputInterface $output) { $this->testSuite = $testSuite; $this->output = $output; } public function handleArguments(array $arguments): array { if (!array_key_exists(1, $arguments) || $arguments[1] !== self::INIT_OPTION) { return $arguments; } unset($arguments[1]); $this->init(); return array_values($arguments); } private function init(): void { $testsBaseDir = "{$this->testSuite->rootPath}/tests"; if (!is_dir($testsBaseDir)) { if (!mkdir($testsBaseDir) && !is_dir($testsBaseDir)) { $this->output->writeln(sprintf( "\n ERROR Directory `%s` was not created.", $testsBaseDir )); return; } $this->output->writeln( ' DONE Created `tests` directory.', ); } foreach (self::STUBS as $from => $to) { $fromPath = __DIR__ . "/../../stubs/init/{$from}"; $toPath = "{$this->testSuite->rootPath}/{$to}"; if (file_exists($toPath)) { $this->output->writeln(sprintf( ' INFO File `%s` already exists, skipped.', $to )); continue; } if ($from === 'phpunit.xml' && file_exists($toPath . '.dist')) { $this->output->writeln(sprintf( ' INFO File `%s` already exists, skipped.', $to . '.dist' )); continue; } if (!copy($fromPath, $toPath)) { $this->output->writeln(sprintf( '[WARNING] Failed to copy stub `%s` to `%s`', $from, $toPath )); continue; } $this->output->writeln(sprintf( ' DONE Created `%s` file.', $to )); } $this->output->writeln( "\n DONE Pest initialised.\n", ); (new Thanks($this->output))(); exit(0); } }