Passed
Push — main ( 7eec51...1c69be )
by Michiel
07:26
created

CommandlineArgumentTest::testSetEscape()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Phing\Test\Type;
4
5
use Phing\Type\Commandline;
6
use Phing\Type\CommandlineArgument;
7
use PHPUnit\Framework\TestCase;
8
9
/**
10
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
11
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
12
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
14
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
15
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
16
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
17
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
18
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
19
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
20
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21
 *
22
 * This software consists of voluntary contributions made by many individuals
23
 * and is licensed under the LGPL. For more information please see
24
 * <http://phing.info>.
25
 *
26
 * @internal
27
 */
28
class CommandlineArgumentTest extends TestCase
29
{
30
    /**
31
     * Test the one 'getter' method of the CommandlineArgument class.
32
     */
33
    public function testGetParts(): void
34
    {
35
        $command = 'usblamp -s -r 5 red green blue off';
36
        $exploded = explode(' ', '-s -r 5 red green blue off');
37
        $commandline = new Commandline($command);
38
        $arguments = ($commandline->arguments);
39
        foreach ($arguments as $counter => $argument) {
40
            $parts = $argument->getParts();
41
            $this->assertEquals($exploded[$counter], $parts[0]);
42
        }
43
    }
44
45
    public function testSetline(): void
46
    {
47
        $commandline = new Commandline();
48
        $argument = new CommandlineArgument($commandline);
49
        $argument->setLine(null);
50
        $parts = $argument->getParts();
51
        $this->assertEquals([], $parts);
52
        $argument->setLine("perl -pie 's/foo/bar/g' test.txt");
53
        $parts = $argument->getParts();
54
        $this->assertNotEquals([], $parts);
55
    }
56
}
57