Completed
Push — master ( 9fb870...82b988 )
by Michiel
18:47
created

CommandlineArgumentTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetline() 0 10 1
A testGetParts() 0 10 2
A testSetEscape() 0 8 1
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