Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.x] Fix missing composer binary (starter kits couldn't be installed) #9950

Merged
merged 14 commits into from
Apr 23, 2024
10 changes: 9 additions & 1 deletion src/Console/Processes/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,19 @@ private function prepareProcessArguments($parts)
return array_merge([
$this->phpBinary(),
"-d memory_limit={$this->memoryLimit}",
'vendor/bin/composer',
$this->composerBinary(),
$this->colorized ? '--ansi' : '--no-ansi',
], $parts);
}

/**
* Absolute path to the Composer binary.
*/
private function composerBinary(): string
{
return $this->run(DIRECTORY_SEPARATOR === '\\' ? 'where composer' : 'which composer');
}

/**
* Sometimes composer returns versions with a 'v', sometimes it doesn't.
*
Expand Down
20 changes: 20 additions & 0 deletions tests/Console/Commands/Concerns/BacksUpComposerJson.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Tests\Console\Commands\Concerns;

use Illuminate\Filesystem\Filesystem;

trait BacksUpComposerJson
{
protected function backupComposerJson()
{
app(Filesystem::class)->copy(base_path('composer.json'), base_path('composer.json.bak'));
}

protected function restoreComposerJson()
{
$files = app(Filesystem::class);
$files->copy(base_path('composer.json.bak'), base_path('composer.json'));
$files->delete(base_path('composer.json.bak'));
}
}
1 change: 1 addition & 0 deletions tests/Console/Commands/Concerns/CleansUpGeneratedPaths.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ protected function cleanupPaths()
base_path('app/Tags'),
base_path('app/Widgets'),
resource_path('js/components'),
base_path('vendor'),
];

foreach ($dirs as $dir) {
Expand Down
5 changes: 4 additions & 1 deletion tests/Console/Commands/MakeActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class MakeActionTest extends TestCase
{
use Concerns\CleansUpGeneratedPaths;
use Concerns\BacksUpComposerJson,
Concerns\CleansUpGeneratedPaths;

private $files;

Expand All @@ -17,11 +18,13 @@ public function setUp(): void
parent::setUp();

$this->files = app(Filesystem::class);
$this->backupComposerJson();
}

public function tearDown(): void
{
$this->cleanupPaths();
$this->restoreComposerJson();

parent::tearDown();
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Console/Commands/MakeAddonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class MakeAddonTest extends TestCase
{
use Concerns\CleansUpGeneratedPaths;
use Concerns\BacksUpComposerJson,
Concerns\CleansUpGeneratedPaths;

private $files;

Expand All @@ -19,11 +20,13 @@ public function setUp(): void
$this->markTestSkippedInWindows();

$this->files = app(Filesystem::class);
$this->backupComposerJson();
}

public function tearDown(): void
{
$this->cleanupPaths();
$this->restoreComposerJson();

parent::tearDown();
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Console/Commands/MakeFieldtypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class MakeFieldtypeTest extends TestCase
{
use Concerns\CleansUpGeneratedPaths;
use Concerns\BacksUpComposerJson,
Concerns\CleansUpGeneratedPaths;

private $files;

Expand All @@ -17,11 +18,13 @@ public function setUp(): void
parent::setUp();

$this->files = app(Filesystem::class);
$this->backupComposerJson();
}

public function tearDown(): void
{
$this->cleanupPaths();
$this->restoreComposerJson();

parent::tearDown();
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Console/Commands/MakeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class MakeFilterTest extends TestCase
{
use Concerns\CleansUpGeneratedPaths;
use Concerns\BacksUpComposerJson,
Concerns\CleansUpGeneratedPaths;

private $files;

Expand All @@ -17,11 +18,13 @@ public function setUp(): void
parent::setUp();

$this->files = app(Filesystem::class);
$this->backupComposerJson();
}

public function tearDown(): void
{
$this->cleanupPaths();
$this->restoreComposerJson();

parent::tearDown();
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Console/Commands/MakeModifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class MakeModifierTest extends TestCase
{
use Concerns\CleansUpGeneratedPaths;
use Concerns\BacksUpComposerJson,
Concerns\CleansUpGeneratedPaths;

private $files;

Expand All @@ -17,11 +18,13 @@ public function setUp(): void
parent::setUp();

$this->files = app(Filesystem::class);
$this->backupComposerJson();
}

public function tearDown(): void
{
$this->cleanupPaths();
$this->restoreComposerJson();

parent::tearDown();
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Console/Commands/MakeScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class MakeScopeTest extends TestCase
{
use Concerns\CleansUpGeneratedPaths;
use Concerns\BacksUpComposerJson,
Concerns\CleansUpGeneratedPaths;

private $files;

Expand All @@ -17,11 +18,13 @@ public function setUp(): void
parent::setUp();

$this->files = app(Filesystem::class);
$this->backupComposerJson();
}

public function tearDown(): void
{
$this->cleanupPaths();
$this->restoreComposerJson();

parent::tearDown();
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Console/Commands/MakeTagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class MakeTagTest extends TestCase
{
use Concerns\CleansUpGeneratedPaths;
use Concerns\BacksUpComposerJson,
Concerns\CleansUpGeneratedPaths;

private $files;

Expand All @@ -17,11 +18,13 @@ public function setUp(): void
parent::setUp();

$this->files = app(Filesystem::class);
$this->backupComposerJson();
}

public function tearDown(): void
{
$this->cleanupPaths();
$this->restoreComposerJson();

parent::tearDown();
}
Expand Down
5 changes: 4 additions & 1 deletion tests/Console/Commands/MakeWidgetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

class MakeWidgetTest extends TestCase
{
use Concerns\CleansUpGeneratedPaths;
use Concerns\BacksUpComposerJson,
Concerns\CleansUpGeneratedPaths;

private $files;

Expand All @@ -17,11 +18,13 @@ public function setUp(): void
parent::setUp();

$this->files = app(Filesystem::class);
$this->backupComposerJson();
}

public function tearDown(): void
{
$this->cleanupPaths();
$this->restoreComposerJson();

parent::tearDown();
}
Expand Down
Loading