-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathCommandProcessor.phpt
More file actions
120 lines (97 loc) · 2.99 KB
/
CommandProcessor.phpt
File metadata and controls
120 lines (97 loc) · 2.99 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?php
use Tester\Assert;
use CzProject\GitPhp\CommandProcessor;
use CzProject\GitPhp\CommitId;
use CzProject\GitPhp\InvalidArgumentException;
use CzProject\GitPhp\InvalidStateException;
require __DIR__ . '/bootstrap.php';
test(function () {
$options = [
'first',
[
'--second' => TRUE,
'--third' => '"go"',
],
];
$env = [
'ENV_1' => 'value1',
'ENV_2' => 'value2',
];
$processor = new CommandProcessor(CommandProcessor::MODE_WINDOWS);
Assert::same('set ENV_1=value1 && set ENV_2=value2 && git first --second 1 --third """go"""', $processor->process('git', $options, $env));
$processor = new CommandProcessor(CommandProcessor::MODE_NON_WINDOWS);
Assert::same('ENV_1=value1 ENV_2=value2 git first --second 1 --third \'"go"\'', $processor->process('git', $options, $env));
});
test(function () {
$options = [
'first',
[
'--second' => new CommitId('734713bc047d87bf7eac9674765ae793478c50d3'),
'--one' => TRUE,
'--two' => FALSE,
'--three' => NULL,
TRUE,
FALSE,
NULL,
],
NULL,
'arg',
new CommitId('734713bc047d87bf7eac9674765ae793478c50d3'),
];
$processor = new CommandProcessor(CommandProcessor::MODE_NON_WINDOWS);
Assert::same(implode(' ', [
'git',
'first',
'--second 734713bc047d87bf7eac9674765ae793478c50d3',
'--one 1',
'--two 0',
'1',
'0',
'arg',
'734713bc047d87bf7eac9674765ae793478c50d3',
]), $processor->process('git', $options));
});
test(function () {
$processor = new CommandProcessor(CommandProcessor::MODE_NON_WINDOWS);
Assert::exception(function () use ($processor) {
$processor->process('git', [
(object) [],
]);
}, InvalidStateException::class, 'Unknow argument type stdClass.');
Assert::exception(function () use ($processor) {
$processor->process('git', [
TRUE,
]);
}, InvalidStateException::class, 'Unknow argument type boolean.');
Assert::exception(function () use ($processor) {
$processor->process('git', [
FALSE,
]);
}, InvalidStateException::class, 'Unknow argument type boolean.');
Assert::exception(function () use ($processor) {
$processor->process('git', [
[
(object) [],
],
]);
}, InvalidStateException::class, 'Unknow option value type stdClass.');
});
test(function () {
Assert::exception(function () {
$processor = new CommandProcessor('INVALID');
}, InvalidArgumentException::class, "Invalid mode 'INVALID'.");
});
test(function () {
$processor = new CommandProcessor(CommandProcessor::MODE_NON_WINDOWS);
$processor->addConfig('core.sshCommand', "ssh -i '/path/to/private key file' -o StrictHostKeyChecking=no -o IdentitiesOnly=yes");
$processor->addConfig('test', NULL);
Assert::same(implode(' ', [
'git',
"-c core.sshCommand='ssh -i '\''/path/to/private key file'\'' -o StrictHostKeyChecking=no -o IdentitiesOnly=yes'",
'-c test',
'clone',
"'https://github.com/test/test.git'",
'test',
]), $processor->process('git', ['clone', 'https://github.com/test/test.git', 'test']));
print($processor->process('git', ['clone', 'https://github.com/test/test.git', 'test']));
});