Skip to content

Commit

Permalink
Prevent error message and slow operation when PHPUnit has already bee…
Browse files Browse the repository at this point in the history
…n removed
  • Loading branch information
jessarcher committed Aug 8, 2023
1 parent e4fb42d commit 292cfe4
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/Console/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@ public function handle()
// Tests...
$stubs = $this->getTestStubsPath();

if ($this->option('pest')) {
$this->removeComposerDevPackages(['phpunit/phpunit']);
if ($this->option('pest') || $this->isUsingPest()) {
if ($this->hasComposerPackage('phpunit/phpunit')) {
$this->removeComposerDevPackages(['phpunit/phpunit']);
}

if (! $this->requireComposerDevPackages(['pestphp/pest:^2.0', 'pestphp/pest-plugin-laravel:^2.0'])) {
return 1;
Expand Down Expand Up @@ -732,6 +734,20 @@ protected function requireComposerDevPackages($packages)
}) === 0;
}

/**
* Determine if the given Composer Package is installed.
*
* @param string $package
* @return bool
*/
protected function hasComposerPackage($package)
{
$packages = json_decode(file_get_contents(base_path('composer.json')), true);

return array_key_exists($package, $packages['require'] ?? [])
|| array_key_exists($package, $packages['require-dev'] ?? []);
}

/**
* Update the "package.json" file.
*
Expand Down

0 comments on commit 292cfe4

Please sign in to comment.