mirror of
https://github.com/pestphp/pest.git
synced 2026-03-10 17:57:23 +01:00
refactor
This commit is contained in:
@ -4,14 +4,13 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Pest\Plugins;
|
namespace Pest\Plugins;
|
||||||
|
|
||||||
use App\Console\Kernel;
|
|
||||||
use Composer\InstalledVersions;
|
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;
|
||||||
use Pest\TestSuite;
|
use Pest\TestSuite;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @internal
|
* @internal
|
||||||
@ -109,63 +108,38 @@ final class Init implements HandlesArguments
|
|||||||
|
|
||||||
private function initLaravel(): int
|
private function initLaravel(): int
|
||||||
{
|
{
|
||||||
View::render('components.badge', [
|
$command = [
|
||||||
'type' => 'INFO',
|
'composer', 'require',
|
||||||
'content' => 'Laravel installation detected, pest-plugin-laravel will be installed.',
|
'pestphp/pest-plugin-laravel 2.x-dev',
|
||||||
]);
|
'--dev',
|
||||||
|
];
|
||||||
|
|
||||||
exec('composer require pestphp/pest-plugin-laravel 2.x-dev', result_code: $result);
|
$result = (new Process($command, $this->testSuite->rootPath, ['COMPOSER_MEMORY_LIMIT' => '-1']))
|
||||||
|
->setTimeout(null)
|
||||||
|
->run(function ($type, $output): void {
|
||||||
|
$this->output->write($output);
|
||||||
|
});
|
||||||
|
|
||||||
/** @var int $result */
|
|
||||||
if ($result > 0) {
|
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;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
View::render('components.badge', [
|
$command = [
|
||||||
'type' => 'INFO',
|
'php', 'artisan',
|
||||||
'content' => 'Running artisan command to install Pest.',
|
'pest:install',
|
||||||
]);
|
'--no-interaction',
|
||||||
|
];
|
||||||
|
|
||||||
$app = require $this->testSuite->rootPath.'/bootstrap/app.php';
|
return (new Process($command, $this->testSuite->rootPath, ['COMPOSER_MEMORY_LIMIT' => '-1']))
|
||||||
/** @phpstan-ignore-next-line */
|
->setTimeout(null)
|
||||||
$app->make(Kernel::class)->bootstrap();
|
->run(function ($type, $output): void {
|
||||||
|
$this->output->write($output);
|
||||||
/** @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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if laravel is installed through Composer
|
||||||
|
*/
|
||||||
private function isLaravelInstalled(): bool
|
private function isLaravelInstalled(): bool
|
||||||
{
|
{
|
||||||
return InstalledVersions::isInstalled('laravel/laravel');
|
return InstalledVersions::isInstalled('laravel/laravel');
|
||||||
|
|||||||
Reference in New Issue
Block a user