testGetFullCommandReturnsNotEscapedCommandIfConfigured()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
namespace ivol\tests;
3
4
use ivol\Config\ConfigurationFactory;
5
use ivol\ExecutionContext;
6
7
class ExecutionContextTest extends \PHPUnit_Framework_TestCase
8
{
9
    /** @var  ExecutionContext */
10
    private $sut;
11
12
    protected function setUp()
13
    {
14
        $this->sut = new ExecutionContext('echo ? %s', array("'123"));
15
    }
16
17
    public function testGetParamsReturnsEscapedParamsByDefault()
18
    {
19
        $this->assertEquals(["''\''123'"], $this->sut->getParams());
20
    }
21
22
    public function testGetParamsReturnsNotEscapedParamsIfConfigured()
23
    {
24
        $this->sut->setConfig(['escape_shell_args' => false]);
25
26
        $this->assertEquals(["'123"], $this->sut->getParams());
27
    }
28
29
    public function testGetFullCommandReturnsEscapedCommandByDefault()
30
    {
31
        $this->assertEquals("echo \? ''\\\\''123\'", $this->sut->getFullCommand());
32
    }
33
34
    public function testGetFullCommandReturnsNotEscapedCommandIfConfigured()
35
    {
36
        $this->sut->setConfig(ConfigurationFactory::createFromArray(['escape_shell_cmd' => false]));
37
38
        $this->assertEquals("echo ? ''\''123'", $this->sut->getFullCommand());
39
    }
40
41
    public function testGetFullCommandReturnsNotEscapedCommandAndArgsIfConfigured()
42
    {
43
        $this->sut->setConfig(ConfigurationFactory::createFromArray(['escape_shell_cmd' => false, 'escape_shell_args' => false]));
44
45
        $this->assertEquals("echo ? '123", $this->sut->getFullCommand());
46
    }
47
48
}