From 08e3c551958573f847b7309dd642f243ec1a7e8e Mon Sep 17 00:00:00 2001 From: Duncan McClean Date: Tue, 23 Apr 2024 20:38:16 +0100 Subject: [PATCH] [4.x] Fix missing composer binary (starter kits couldn't install) (#9950) Co-authored-by: Jason Varga --- src/Console/Processes/Composer.php | 10 +++++++++- .../Commands/Concerns/BacksUpComposerJson.php | 20 +++++++++++++++++++ .../Concerns/CleansUpGeneratedPaths.php | 1 + tests/Console/Commands/MakeActionTest.php | 5 ++++- tests/Console/Commands/MakeAddonTest.php | 5 ++++- tests/Console/Commands/MakeFieldtypeTest.php | 5 ++++- tests/Console/Commands/MakeFilterTest.php | 5 ++++- tests/Console/Commands/MakeModifierTest.php | 5 ++++- tests/Console/Commands/MakeScopeTest.php | 5 ++++- tests/Console/Commands/MakeTagTest.php | 5 ++++- tests/Console/Commands/MakeWidgetTest.php | 5 ++++- 11 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 tests/Console/Commands/Concerns/BacksUpComposerJson.php diff --git a/src/Console/Processes/Composer.php b/src/Console/Processes/Composer.php index 0157feb377..090eee82ee 100644 --- a/src/Console/Processes/Composer.php +++ b/src/Console/Processes/Composer.php @@ -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. * diff --git a/tests/Console/Commands/Concerns/BacksUpComposerJson.php b/tests/Console/Commands/Concerns/BacksUpComposerJson.php new file mode 100644 index 0000000000..5e1233daf7 --- /dev/null +++ b/tests/Console/Commands/Concerns/BacksUpComposerJson.php @@ -0,0 +1,20 @@ +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')); + } +} diff --git a/tests/Console/Commands/Concerns/CleansUpGeneratedPaths.php b/tests/Console/Commands/Concerns/CleansUpGeneratedPaths.php index 8c4ce47397..c72fb1dcc3 100644 --- a/tests/Console/Commands/Concerns/CleansUpGeneratedPaths.php +++ b/tests/Console/Commands/Concerns/CleansUpGeneratedPaths.php @@ -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) { diff --git a/tests/Console/Commands/MakeActionTest.php b/tests/Console/Commands/MakeActionTest.php index fc1b8d148a..f1311ba695 100644 --- a/tests/Console/Commands/MakeActionTest.php +++ b/tests/Console/Commands/MakeActionTest.php @@ -8,7 +8,8 @@ class MakeActionTest extends TestCase { - use Concerns\CleansUpGeneratedPaths; + use Concerns\BacksUpComposerJson, + Concerns\CleansUpGeneratedPaths; private $files; @@ -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(); } diff --git a/tests/Console/Commands/MakeAddonTest.php b/tests/Console/Commands/MakeAddonTest.php index 6f281f0bab..53545f8f36 100644 --- a/tests/Console/Commands/MakeAddonTest.php +++ b/tests/Console/Commands/MakeAddonTest.php @@ -8,7 +8,8 @@ class MakeAddonTest extends TestCase { - use Concerns\CleansUpGeneratedPaths; + use Concerns\BacksUpComposerJson, + Concerns\CleansUpGeneratedPaths; private $files; @@ -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(); } diff --git a/tests/Console/Commands/MakeFieldtypeTest.php b/tests/Console/Commands/MakeFieldtypeTest.php index 2675e4459a..bc05e1e4d6 100644 --- a/tests/Console/Commands/MakeFieldtypeTest.php +++ b/tests/Console/Commands/MakeFieldtypeTest.php @@ -8,7 +8,8 @@ class MakeFieldtypeTest extends TestCase { - use Concerns\CleansUpGeneratedPaths; + use Concerns\BacksUpComposerJson, + Concerns\CleansUpGeneratedPaths; private $files; @@ -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(); } diff --git a/tests/Console/Commands/MakeFilterTest.php b/tests/Console/Commands/MakeFilterTest.php index aa65029f9d..e614dc8aa8 100644 --- a/tests/Console/Commands/MakeFilterTest.php +++ b/tests/Console/Commands/MakeFilterTest.php @@ -8,7 +8,8 @@ class MakeFilterTest extends TestCase { - use Concerns\CleansUpGeneratedPaths; + use Concerns\BacksUpComposerJson, + Concerns\CleansUpGeneratedPaths; private $files; @@ -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(); } diff --git a/tests/Console/Commands/MakeModifierTest.php b/tests/Console/Commands/MakeModifierTest.php index bc53f891c1..c345970ade 100644 --- a/tests/Console/Commands/MakeModifierTest.php +++ b/tests/Console/Commands/MakeModifierTest.php @@ -8,7 +8,8 @@ class MakeModifierTest extends TestCase { - use Concerns\CleansUpGeneratedPaths; + use Concerns\BacksUpComposerJson, + Concerns\CleansUpGeneratedPaths; private $files; @@ -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(); } diff --git a/tests/Console/Commands/MakeScopeTest.php b/tests/Console/Commands/MakeScopeTest.php index 943535947c..58ad64a99e 100644 --- a/tests/Console/Commands/MakeScopeTest.php +++ b/tests/Console/Commands/MakeScopeTest.php @@ -8,7 +8,8 @@ class MakeScopeTest extends TestCase { - use Concerns\CleansUpGeneratedPaths; + use Concerns\BacksUpComposerJson, + Concerns\CleansUpGeneratedPaths; private $files; @@ -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(); } diff --git a/tests/Console/Commands/MakeTagTest.php b/tests/Console/Commands/MakeTagTest.php index 3830c25bdc..9c5ef5a0a1 100644 --- a/tests/Console/Commands/MakeTagTest.php +++ b/tests/Console/Commands/MakeTagTest.php @@ -8,7 +8,8 @@ class MakeTagTest extends TestCase { - use Concerns\CleansUpGeneratedPaths; + use Concerns\BacksUpComposerJson, + Concerns\CleansUpGeneratedPaths; private $files; @@ -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(); } diff --git a/tests/Console/Commands/MakeWidgetTest.php b/tests/Console/Commands/MakeWidgetTest.php index 18d1b126ca..f51334341a 100644 --- a/tests/Console/Commands/MakeWidgetTest.php +++ b/tests/Console/Commands/MakeWidgetTest.php @@ -8,7 +8,8 @@ class MakeWidgetTest extends TestCase { - use Concerns\CleansUpGeneratedPaths; + use Concerns\BacksUpComposerJson, + Concerns\CleansUpGeneratedPaths; private $files; @@ -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(); }