-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathHostProcessFactoryTest.php
More file actions
88 lines (70 loc) · 2.89 KB
/
HostProcessFactoryTest.php
File metadata and controls
88 lines (70 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
namespace PhpSchool\PhpWorkshopTest\Process;
use PhpSchool\PhpWorkshop\Process\ProcessInput;
use PhpSchool\PhpWorkshop\Process\ProcessNotFoundException;
use Symfony\Component\Process\ExecutableFinder;
use PhpSchool\PhpWorkshop\Process\HostProcessFactory;
use PHPUnit\Framework\TestCase;
class HostProcessFactoryTest extends TestCase
{
public function testCreateThrowsExceptionIfExecutableNotFound(): void
{
static::expectException(ProcessNotFoundException::class);
$finder = $this->createMock(ExecutableFinder::class);
$finder->expects($this->once())
->method('find')
->with('composer')
->willReturn(null);
$factory = new HostProcessFactory($finder);
$input = new ProcessInput('composer', [], __DIR__, []);
$factory->create($input);
}
public function testCreate(): void
{
$finder = $this->createMock(ExecutableFinder::class);
$finder->expects($this->once())
->method('find')
->with('composer')
->willReturn('/usr/local/bin/composer');
$factory = new HostProcessFactory($finder);
$input = new ProcessInput('composer', [], __DIR__, []);
$process = $factory->create($input);
static::assertSame("'/usr/local/bin/composer'", $process->getCommandLine());
}
public function testCreateWithArgs(): void
{
$finder = $this->createMock(ExecutableFinder::class);
$finder->expects($this->once())
->method('find')
->with('composer')
->willReturn('/usr/local/bin/composer');
$factory = new HostProcessFactory($finder);
$input = new ProcessInput('composer', ['one', 'two'], __DIR__, []);
$process = $factory->create($input);
static::assertSame("'/usr/local/bin/composer' 'one' 'two'", $process->getCommandLine());
}
public function testCreateWithEnv(): void
{
$finder = $this->createMock(ExecutableFinder::class);
$finder->expects($this->once())
->method('find')
->with('composer')
->willReturn('/usr/local/bin/composer');
$factory = new HostProcessFactory($finder);
$input = new ProcessInput('composer', ['one', 'two'], __DIR__, ['SOME_VAR' => 'value']);
$process = $factory->create($input);
static::assertSame(['SOME_VAR' => 'value'], $process->getEnv());
}
public function testWithInput(): void
{
$finder = $this->createMock(ExecutableFinder::class);
$finder->expects($this->once())
->method('find')
->with('composer')
->willReturn('/usr/local/bin/composer');
$factory = new HostProcessFactory($finder);
$input = new ProcessInput('composer', [], __DIR__, [], 'someinput');
$process = $factory->create($input);
static::assertSame('someinput', $process->getInput());
}
}