option('test-directory')); /** @var string $name */ $name = $this->argument('name'); $type = ((bool) $this->option('unit')) ? 'Unit' : (((bool) $this->option('dusk')) ? 'Browser' : 'Feature'); $relativePath = sprintf( testDirectory('%s/%s.php'), $type, ucfirst($name) ); /* @phpstan-ignore-next-line */ $target = base_path($relativePath); if (!File::isDirectory(dirname($target))) { File::makeDirectory(dirname($target), 0777, true, true); } if (File::exists($target) && !(bool) $this->option('force')) { throw new InvalidConsoleArgument(sprintf('%s already exist', $target)); } $contents = File::get(implode(DIRECTORY_SEPARATOR, [ dirname(__DIR__, 3), 'stubs', sprintf('%s.php', $type), ])); $name = mb_strtolower($name); $name = Str::endsWith($name, 'test') ? mb_substr($name, 0, -4) : $name; File::put($target, str_replace('{name}', $name, $contents)); $message = sprintf('`%s` created successfully.', $relativePath); $this->output->success($message); } }