diff --git a/src/Composer.php b/src/Composer.php index be46dfc..c41dbed 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); + } } diff --git a/tests/ComposerTest.php b/tests/ComposerTest.php new file mode 100644 index 0000000..ffff72e --- /dev/null +++ b/tests/ComposerTest.php @@ -0,0 +1,46 @@ +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; + } +}