File tree Expand file tree Collapse file tree 2 files changed +68
-3
lines changed Expand file tree Collapse file tree 2 files changed +68
-3
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace BotMan \Studio ;
4
4
5
+ use Illuminate \Foundation \Application ;
5
6
use Illuminate \Support \Composer as BaseComposer ;
6
7
7
8
class Composer extends BaseComposer
@@ -14,12 +15,30 @@ class Composer extends BaseComposer
14
15
*/
15
16
public function install ($ package , callable $ callback )
16
17
{
17
- $ process = $ this ->getProcess ();
18
-
19
- $ process ->setCommandLine (trim ($ this ->findComposer ().' require ' .$ package ));
18
+ $ process = $ this ->installationCommandProcess ($ package );
20
19
21
20
$ process ->run ($ callback );
22
21
23
22
return $ process ->isSuccessful ();
24
23
}
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
+ }
25
44
}
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments