Completed
Branch master (bae7d3)
by Dzmitry
05:41 queued 02:34
created

testGetParamsReturnsEscapedParamsByDefault()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
use ivol\Config\ConfigurationFactory;
4
use ivol\ExecParams;
5
6
class ExecParamsTest  extends PHPUnit_Framework_TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
Coding Style introduced by
Expected 1 space after class name; 2 found
Loading history...
Coding Style introduced by
Expected 1 space before extends keyword; 2 found
Loading history...
7
{
8
    /** @var  ExecParams */
9
    private $sut;
10
11
    protected function setUp()
12
    {
13
        $this->sut = new ExecParams('echo ? %s', array("'123"));
14
    }
15
16
    public function testGetParamsReturnsEscapedParamsByDefault()
17
    {
18
        $this->assertEquals(["''\''123'"], $this->sut->getParams());
19
    }
20
21
    public function testGetParamsReturnsNotEscapedParamsIfConfigured()
22
    {
23
        $this->sut->setConfig(['escape_shell_args' => false]);
24
25
        $this->assertEquals(["'123"], $this->sut->getParams());
26
    }
27
28
    public function testGetFullCommandReturnsEscapedCommandByDefault()
29
    {
30
        $this->assertEquals("echo \? ''\\\\''123\'", $this->sut->getFullCommand());
31
    }
32
33
    public function testGetFullCommandReturnsNotEscapedCommandIfConfigured()
34
    {
35
        $this->sut->setConfig(ConfigurationFactory::createFromArray(['escape_shell_cmd' => false]));
36
37
        $this->assertEquals("echo ? ''\''123'", $this->sut->getFullCommand());
38
    }
39
40
    public function testGetFullCommandReturnsNotEscapedCommandAndArgsIfConfigured()
41
    {
42
        $this->sut->setConfig(ConfigurationFactory::createFromArray(['escape_shell_cmd' => false, 'escape_shell_args' => false]));
43
44
        $this->assertEquals("echo ? '123", $this->sut->getFullCommand());
45
    }
46
47
}