Skip to content

Commit a1506ae

Browse files
authored
Merge pull request #48 from botman/composer-install
Fix process parameters.
2 parents 3c42a8f + adb4c87 commit a1506ae

File tree

2 files changed

+68
-3
lines changed

2 files changed

+68
-3
lines changed

src/Composer.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace BotMan\Studio;
44

5+
use Illuminate\Foundation\Application;
56
use Illuminate\Support\Composer as BaseComposer;
67

78
class Composer extends BaseComposer
@@ -14,12 +15,30 @@ class Composer extends BaseComposer
1415
*/
1516
public function install($package, callable $callback)
1617
{
17-
$process = $this->getProcess();
18-
19-
$process->setCommandLine(trim($this->findComposer().' require '.$package));
18+
$process = $this->installationCommandProcess($package);
2019

2120
$process->run($callback);
2221

2322
return $process->isSuccessful();
2423
}
24+
25+
/**
26+
* Get installation command for process.
27+
*
28+
* @param string $package
29+
* @return \Symfony\Component\Process\Process
30+
*/
31+
protected function installationCommandProcess($package)
32+
{
33+
if (version_compare(Application::VERSION, '5.8.0', '<')) {
34+
$process = $this->getProcess();
35+
36+
return $process->setCommandLine(trim($this->findComposer().' require '.$package));
37+
}
38+
39+
$command = $this->findComposer();
40+
array_push($command, 'require', $package);
41+
42+
return $this->getProcess($command);
43+
}
2544
}

tests/ComposerTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
use Illuminate\Filesystem\Filesystem;
4+
use Illuminate\Foundation\Application;
5+
use Mockery as m;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class ComposerTest extends TestCase
9+
{
10+
protected function tearDown(): void
11+
{
12+
m::close();
13+
}
14+
15+
/** @test */
16+
public function it_install_package()
17+
{
18+
$composer = $this->getMockedComposer();
19+
20+
$composer->install('foo/bar', function () {
21+
$this->assertTrue(true);
22+
});
23+
}
24+
25+
protected function getMockedComposer()
26+
{
27+
$composer = m::mock('BotMan\Studio\Composer[getProcess]', [new Filesystem(), __DIR__])
28+
->shouldAllowMockingProtectedMethods();
29+
$process = m::mock('Symfony\Component\Process\Process');
30+
31+
if (version_compare(Application::VERSION, '5.8.0', '<')) {
32+
$process->shouldReceive('setCommandLine')->with('composer require foo/bar')->andReturnSelf();
33+
$composer->shouldReceive('getProcess')->once()->andReturn($process);
34+
} else {
35+
$composer->shouldReceive('getProcess')->once()->with(['composer', 'require', 'foo/bar'])->andReturn($process);
36+
}
37+
38+
$process->shouldReceive('run')->once()->with(m::type('Closure'))->andReturnUsing(function ($callable) {
39+
$callable();
40+
41+
return 0;
42+
})->shouldReceive('isSuccessful')->once()->andReturnTrue();
43+
44+
return $composer;
45+
}
46+
}

0 commit comments

Comments
 (0)