1
|
|
|
<?php |
2
|
|
|
class CommandlineArgumentTest extends \PHPUnit\Framework\TestCase |
3
|
|
|
{ |
4
|
|
|
/** |
5
|
|
|
* Test the one 'getter' method of the CommandlineArgument class |
6
|
|
|
* |
7
|
|
|
* @return void |
8
|
|
|
*/ |
9
|
|
|
public function testGetParts() |
10
|
|
|
{ |
11
|
|
|
$command = "usblamp -s -r 5 red green blue off"; |
12
|
|
|
$exploded = explode(" ", "-s -r 5 red green blue off"); |
13
|
|
|
$commandline = new Commandline($command); |
14
|
|
|
$arguments = ($commandline->arguments); |
15
|
|
|
foreach ($arguments as $counter => $argument) { |
16
|
|
|
$parts = $argument->getParts(); |
17
|
|
|
$this->assertEquals($exploded[$counter], $parts[0]); |
18
|
|
|
$this->assertEquals(false, $argument->escape); |
19
|
|
|
} |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testSetEscape() |
23
|
|
|
{ |
24
|
|
|
$command = "usblamp -s -r 5 red green blue off"; |
25
|
|
|
$commandline = new Commandline($command); |
26
|
|
|
$argument = new CommandlineArgument($commandline); |
27
|
|
|
$this->assertEquals($argument->escape, false); |
28
|
|
|
$argument->setEscape(true); |
29
|
|
|
$this->assertEquals($argument->escape, true); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testSetline() |
33
|
|
|
{ |
34
|
|
|
$commandline = new Commandline(); |
35
|
|
|
$argument = new CommandlineArgument($commandline); |
36
|
|
|
$argument->setLine(null); |
37
|
|
|
$parts = $argument->getParts(); |
38
|
|
|
$this->assertEquals($parts, []); |
39
|
|
|
$argument->setLine("perl -pie 's/foo/bar/g' test.txt"); |
40
|
|
|
$parts = $argument->getParts(); |
41
|
|
|
$this->assertNotEquals($parts, []); |
42
|
|
|
|
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|