From 027ff2d03d9082cef2f7d74f791096144ca15b82 Mon Sep 17 00:00:00 2001 From: QWp6t Date: Fri, 4 Sep 2020 09:25:11 +0800 Subject: [PATCH 1/4] Fix process parameters. Signed-off-by: Mior Muhammad Zaki --- src/Composer.php | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Composer.php b/src/Composer.php index be46dfc..4186cc9 100644 --- a/src/Composer.php +++ b/src/Composer.php @@ -2,6 +2,7 @@ namespace BotMan\Studio; +use Illuminate\Foundation\Application; use Illuminate\Support\Composer as BaseComposer; class Composer extends BaseComposer @@ -14,12 +15,30 @@ class Composer extends BaseComposer */ public function install($package, callable $callback) { - $process = $this->getProcess(); - - $process->setCommandLine(trim($this->findComposer().' require '.$package)); + $process = $this->installationCommandProcess($package); $process->run($callback); return $process->isSuccessful(); } + + /** + * Get installation command for process. + * + * @param string $package + * @return \Symfony\Component\Process\Process + */ + protected function installationCommandProcess($package) + { + if (version_compare(Application::version, '5.8.0', '<')) { + $process = $this->getProcess(); + + return $process->setCommandLine(trim($this->findComposer().' require '.$package)); + } + + $command = $this->findComposer(); + array_push($command, 'require', $package); + + return $this->getProcess($command); + } } From 63c6905f8ae067c47ca95b10be9306de0bd081ce Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 4 Sep 2020 09:30:12 +0800 Subject: [PATCH 2/4] Fixes constant name. Signed-off-by: Mior Muhammad Zaki --- src/Composer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Composer.php b/src/Composer.php index 4186cc9..c41dbed 100644 --- a/src/Composer.php +++ b/src/Composer.php @@ -30,7 +30,7 @@ public function install($package, callable $callback) */ protected function installationCommandProcess($package) { - if (version_compare(Application::version, '5.8.0', '<')) { + if (version_compare(Application::VERSION, '5.8.0', '<')) { $process = $this->getProcess(); return $process->setCommandLine(trim($this->findComposer().' require '.$package)); From 3c4f131af16497da16c0e6510e50cf272d09a4c7 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 4 Sep 2020 09:51:34 +0800 Subject: [PATCH 3/4] Add composer tests. Signed-off-by: Mior Muhammad Zaki --- tests/ComposerTest.php | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/ComposerTest.php diff --git a/tests/ComposerTest.php b/tests/ComposerTest.php new file mode 100644 index 0000000..89c34ba --- /dev/null +++ b/tests/ComposerTest.php @@ -0,0 +1,45 @@ +getMockedComposer(); + + $composer->install('foo/bar', function () { + $this->assertTrue(true); + }); + } + + protected function getMockedComposer() + { + $composer = m::mock('BotMan\Studio\Composer[getProcess]', [new Filesystem(), __DIR__]) + ->shouldAllowMockingProtectedMethods(); + $process = m::mock('Symfony\Component\Process\Process'); + + if (version_compare(Application::VERSION, '5.8.0', '<')) { + $process->shouldReceive('setCommandLine')->with('composer require foo/bar')->andReturnSelf(); + $composer->shouldReceive('getProcess')->once()->andReturn($process); + } else { + $composer->shouldReceive('getProcess')->once()->with(['composer', 'require', 'foo/bar'])->andReturn($process); + } + + $process->shouldReceive('run')->once()->with(m::type('Closure'))->andReturnUsing(function ($callable) { + $callable(); + return 0; + })->shouldReceive('isSuccessful')->once()->andReturnTrue(); + + return $composer; + } +} From adb4c87ee4aa79c0fab48d3f351c47d58a43c799 Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Fri, 4 Sep 2020 09:52:24 +0800 Subject: [PATCH 4/4] Fixes CS. Signed-off-by: Mior Muhammad Zaki --- tests/ComposerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/ComposerTest.php b/tests/ComposerTest.php index 89c34ba..ffff72e 100644 --- a/tests/ComposerTest.php +++ b/tests/ComposerTest.php @@ -37,6 +37,7 @@ protected function getMockedComposer() $process->shouldReceive('run')->once()->with(m::type('Closure'))->andReturnUsing(function ($callable) { $callable(); + return 0; })->shouldReceive('isSuccessful')->once()->andReturnTrue();