Skip to content

Commit

Permalink
[4.x] Fix missing composer binary (starter kits couldn't install) (#9950
Browse files Browse the repository at this point in the history
)

Co-authored-by: Jason Varga <jason@pixelfear.com>
  • Loading branch information
duncanmcclean and jasonvarga authored Apr 23, 2024
1 parent e9e84bb commit 08e3c55
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 9 deletions.
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

0 comments on commit 08e3c55

Please sign in to comment.