Skip to content

Commit

Permalink
Improves installation of Pest (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
nunomaduro authored Jan 29, 2024
1 parent cdf6c0a commit e57c509
Showing 1 changed file with 22 additions and 40 deletions.
62 changes: 22 additions & 40 deletions src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -594,28 +594,30 @@ protected function validateStackOption(InputInterface $input)
*/
protected function installPest(string $directory, InputInterface $input, OutputInterface $output)
{
if ($this->removeComposerPackages(['phpunit/phpunit', '--no-update'], $output, true)
&& $this->requireComposerPackages(['pestphp/pest:^2.0', 'pestphp/pest-plugin-laravel:^2.0'], $output, true)) {
$commands = array_filter([
$this->phpBinary().' ./vendor/bin/pest --init',
]);

$this->runCommands($commands, $input, $output, workingPath: $directory, env: [
'PEST_NO_SUPPORT' => 'true',
]);

$this->replaceFile(
'pest/Feature.php',
$directory.'/tests/Feature/ExampleTest.php',
);
$composerBinary = $this->findComposer();

$this->replaceFile(
'pest/Unit.php',
$directory.'/tests/Unit/ExampleTest.php',
);
$commands = [
$composerBinary.' remove phpunit/phpunit --dev --no-update',
$composerBinary.' require pestphp/pest:^2.0 pestphp/pest-plugin-laravel:^2.0 --no-update --dev',
$composerBinary.' update',
$this->phpBinary().' ./vendor/bin/pest --init',
];

$this->commitChanges('Install Pest', $directory, $input, $output);
}
$this->runCommands($commands, $input, $output, workingPath: $directory, env: [
'PEST_NO_SUPPORT' => 'true',
]);

$this->replaceFile(
'pest/Feature.php',
$directory.'/tests/Feature/ExampleTest.php',
);

$this->replaceFile(
'pest/Unit.php',
$directory.'/tests/Unit/ExampleTest.php',
);

$this->commitChanges('Install Pest', $directory, $input, $output);
}

/**
Expand Down Expand Up @@ -769,26 +771,6 @@ protected function phpBinary()
: 'php';
}

/**
* Install the given Composer Packages into the application.
*
* @return bool
*/
protected function requireComposerPackages(array $packages, OutputInterface $output, bool $asDev = false)
{
return $this->composer->requirePackages($packages, $asDev, $output);
}

/**
* Remove the given Composer Packages from the application.
*
* @return bool
*/
protected function removeComposerPackages(array $packages, OutputInterface $output, bool $asDev = false)
{
return $this->composer->removePackages($packages, $asDev, $output);
}

/**
* Run the given commands.
*
Expand Down

0 comments on commit e57c509

Please sign in to comment.