Files
pest/src/Laravel/Commands/PestInstallCommand.php
2020-12-27 15:24:21 +01:00

67 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Pest\Laravel\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Pest\Console\Thanks;
use Pest\Exceptions\InvalidConsoleArgument;
use Pest\Support\Str;
/**
* @internal
*/
final class PestInstallCommand extends Command
{
/**
* The console command name.
*
* @var string
*/
protected $signature = 'pest:install';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Creates Pest resources in your current PHPUnit test suite';
/**
* Execute the console command.
*/
public function handle(): void
{
/* @phpstan-ignore-next-line */
$pest = base_path('tests/Pest.php');
$stubs = 'stubs/Laravel';
if (File::exists($pest)) {
throw new InvalidConsoleArgument(sprintf('%s already exist', $pest));
}
File::copy(implode(DIRECTORY_SEPARATOR, [
dirname(__DIR__, 3),
$stubs,
'Pest.php',
]), $pest);
$this->output->success('`tests/Pest.php` created successfully.');
if (!(bool) $this->option('no-interaction')) {
(new Thanks($this->output))();
}
}
/**
* Determine if this is a Lumen application.
*/
private function isLumen(): bool
{
/* @phpstan-ignore-next-line */
return Str::startsWith(app()->version(), 'Lumen');
}
}