mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
init command tweak
This commit is contained in:
@ -4,6 +4,9 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Plugins;
|
namespace Pest\Plugins;
|
||||||
|
|
||||||
|
use App\Console\Kernel;
|
||||||
|
use Composer\InstalledVersions;
|
||||||
|
use Illuminate\Support\Facades\Process;
|
||||||
use Pest\Console\Thanks;
|
use Pest\Console\Thanks;
|
||||||
use Pest\Contracts\Plugins\HandlesArguments;
|
use Pest\Contracts\Plugins\HandlesArguments;
|
||||||
use Pest\Support\View;
|
use Pest\Support\View;
|
||||||
@ -26,7 +29,9 @@ final class Init implements HandlesArguments
|
|||||||
private const STUBS = [
|
private const STUBS = [
|
||||||
'phpunit.xml' => 'phpunit.xml',
|
'phpunit.xml' => 'phpunit.xml',
|
||||||
'Pest.php' => 'tests/Pest.php',
|
'Pest.php' => 'tests/Pest.php',
|
||||||
'ExampleTest.php' => 'tests/ExampleTest.php',
|
'TestCase.php' => 'tests/TestCase.php',
|
||||||
|
'Unit/ExampleTest.php' => 'tests/Unit/ExampleTest.php',
|
||||||
|
'Feature/ExampleTest.php' => 'tests/Feature/ExampleTest.php',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -59,16 +64,19 @@ final class Init implements HandlesArguments
|
|||||||
|
|
||||||
private function init(): void
|
private function init(): void
|
||||||
{
|
{
|
||||||
|
if ($this->isLaravelInstalled()) {
|
||||||
|
exit($this->initLaravel());
|
||||||
|
}
|
||||||
|
|
||||||
$testsBaseDir = "{$this->testSuite->rootPath}/tests";
|
$testsBaseDir = "{$this->testSuite->rootPath}/tests";
|
||||||
|
|
||||||
if (! is_dir($testsBaseDir)) {
|
if (! is_dir($testsBaseDir)) {
|
||||||
mkdir($testsBaseDir);
|
mkdir($testsBaseDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->output->writeln([
|
View::render('components.badge', [
|
||||||
'',
|
'type' => 'INFO',
|
||||||
' <fg=white;bg=blue;options=bold> INFO </> Preparing tests directory.</>',
|
'content' => 'Preparing tests directory.',
|
||||||
'',
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
foreach (self::STUBS as $from => $to) {
|
foreach (self::STUBS as $from => $to) {
|
||||||
@ -98,4 +106,68 @@ final class Init implements HandlesArguments
|
|||||||
|
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function initLaravel(): int
|
||||||
|
{
|
||||||
|
View::render('components.badge', [
|
||||||
|
'type' => 'INFO',
|
||||||
|
'content' => 'Laravel installation detected, pest-plugin-laravel will be installed.',
|
||||||
|
]);
|
||||||
|
|
||||||
|
exec('composer require pestphp/pest-plugin-laravel 2.x-dev', result_code: $result);
|
||||||
|
|
||||||
|
/** @var int $result */
|
||||||
|
if ($result > 0) {
|
||||||
|
View::render('components.badge', [
|
||||||
|
'type' => 'ERROR',
|
||||||
|
'content' => 'Something went wrong while installing pest-plugin-laravel package. Please refer the above output for more info.',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
View::render('components.badge', [
|
||||||
|
'type' => 'INFO',
|
||||||
|
'content' => 'Running artisan command to install Pest.',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$app = require $this->testSuite->rootPath.'/bootstrap/app.php';
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
|
$app->make(Kernel::class)->bootstrap();
|
||||||
|
|
||||||
|
/** @phpstan-ignore-next-line */
|
||||||
|
$result = Process::run('php artisan pest:install --no-interaction');
|
||||||
|
|
||||||
|
if ($result->failed()) {
|
||||||
|
$this->output->writeln($result->errorOutput());
|
||||||
|
|
||||||
|
View::render('components.badge', [
|
||||||
|
'type' => 'ERROR',
|
||||||
|
'content' => 'Something went wrong while installing Pest in laravel. Please refer the above output for more info.',
|
||||||
|
]);
|
||||||
|
|
||||||
|
return $result->exitCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->output->writeln($result->output());
|
||||||
|
|
||||||
|
View::render('components.two-column-detail', [
|
||||||
|
'left' => 'pest-plugin-laravel',
|
||||||
|
'right' => 'Installed',
|
||||||
|
]);
|
||||||
|
|
||||||
|
View::render('components.two-column-detail', [
|
||||||
|
'left' => 'Pest',
|
||||||
|
'right' => 'Installed in Laravel',
|
||||||
|
]);
|
||||||
|
|
||||||
|
View::render('components.new-line');
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isLaravelInstalled(): bool
|
||||||
|
{
|
||||||
|
return InstalledVersions::isInstalled('laravel/laravel');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
7
stubs/init/TestCase.php
Normal file
7
stubs/init/TestCase.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests;
|
||||||
|
|
||||||
|
class TestCase extends \PHPUnit\Framework\TestCase
|
||||||
|
{
|
||||||
|
}
|
||||||
5
stubs/init/Unit/ExampleTest.php
Normal file
5
stubs/init/Unit/ExampleTest.php
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
test('example', function () {
|
||||||
|
expect(true)->toBeTrue();
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user