Completed
Push — master ( 5e7886...331704 )
by Greg
03:33
created

ConfigurationInjectionTest::testWithConfigLoader()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
use Robo\Robo;
3
4
use Robo\Config\ConfigProcessor;
5
use Robo\Config\YamlConfigLoader;
6
7
class ConfigurationInjectionTest extends \Codeception\TestCase\Test
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...
8
{
9
    /**
10
     * @var \Robo\Runner
11
     */
12
    private $runner;
13
14
    /**
15
     * @var \CodeGuy
16
     */
17
    protected $guy;
18
19
    public function _before()
20
    {
21
        $this->runner = new \Robo\Runner('\Robo\RoboFileFixture');
22
    }
23
24 View Code Duplication
    public function testNoOptionsNoConfiguration()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
25
    {
26
        // Run without any config and without any options
27
        $argv = ['placeholder', 'test:simple-list'];
28
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
29
30
        $this->guy->seeInOutput("a: '1'");
31
        $this->guy->seeInOutput("b: '2'");
32
    }
33
34 View Code Duplication
    public function testOptionsButNoConfiguration()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36
        // Set one option, but provide no config
37
        $argv = ['placeholder', 'test:simple-list', '--b=3'];
38
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
39
40
        $this->guy->seeInOutput("a: '1'");
41
        $this->guy->seeInOutput("b: '3'");
42
    }
43
44 View Code Duplication
    public function testWithConfigurationButNoOptions()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
45
    {
46
        \Robo\Robo::config()->set('command.test.simple-list.options.a', '4');
47
        \Robo\Robo::config()->set('command.test.simple-list.options.b', '5');
48
49
        $argv = ['placeholder', 'test:simple-list'];
50
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
51
52
        $this->guy->seeInOutput("a: '4'");
53
        $this->guy->seeInOutput("b: '5'");
54
    }
55
56 View Code Duplication
    public function testWithConfigurationAndOptionOverride()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
57
    {
58
        \Robo\Robo::config()->set('command.test.simple-list.options.a', '4');
59
        \Robo\Robo::config()->set('command.test.simple-list.options.b', '5');
60
61
        $argv = ['placeholder', 'test:simple-list', '--b=6'];
62
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
63
64
        $this->guy->seeInOutput("a: '4'");
65
        $this->guy->seeInOutput("b: '6'");
66
    }
67
68 View Code Duplication
    public function testSettingConfigurationFromCommandOptions()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        $argv = ['placeholder', 'test:simple-list', '-D', 'config.key=value'];
71
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
72
73
        $this->guy->seeInOutput("a: '1'");
74
        $this->guy->seeInOutput("b: '2'");
75
76
        $actual = \Robo\Robo::config()->get('config.key');
77
        $this->assertEquals('value', $actual);
78
    }
79
80 View Code Duplication
    public function testWithConfigLoader()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
81
    {
82
        $loader = new YamlConfigLoader();
83
        $loader->load(dirname(__DIR__) . '/_data/robo.yml');
84
85
        \Robo\Robo::config()->import($loader->export());
86
87
        $argv = ['placeholder', 'test:simple-list'];
88
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
89
90
        $this->guy->seeInOutput("a: '12'");
91
        $this->guy->seeInOutput("b: '13'");
92
    }
93
94 View Code Duplication
    public function testWithConfigLoaderAndCliOverride()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
95
    {
96
        $loader = new YamlConfigLoader();
97
        $loader->load(dirname(__DIR__) . '/_data/robo.yml');
98
99
        \Robo\Robo::config()->import($loader->export());
100
101
        $argv = ['placeholder', 'test:simple-list', '--b=3'];
102
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
103
104
        $this->guy->seeInOutput("a: '12'");
105
        $this->guy->seeInOutput("b: '3'");
106
    }
107
108
    public function testWithConfigProcessor()
109
    {
110
        $processor = new ConfigProcessor();
111
        $loader = new YamlConfigLoader();
112
        $processor->extend($loader->load(dirname(__DIR__) . '/_data/robo.yml'));
113
        $processor->extend($loader->load(dirname(__DIR__) . '/_data/robo2.yml'));
114
        \Robo\Robo::config()->import($processor->export());
115
116
        $argv = ['placeholder', 'test:simple-list'];
117
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
118
119
        $this->guy->seeInOutput("a: '112'");
120
        $this->guy->seeInOutput("b: '13'");
121
    }
122
123 View Code Duplication
    public function testCommandWithTaskConfiguration()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
124
    {
125
        $loader = new YamlConfigLoader();
126
        $loader->load(dirname(__DIR__) . '/_data/robo.yml');
127
128
        \Robo\Robo::config()->import($loader->export());
129
130
        $argv = ['placeholder', 'test:exec', '--simulate'];
131
        $result = $this->runner->execute($argv, null, null, $this->guy->capturedOutputStream());
0 ignored issues
show
Unused Code introduced by
$result is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
132
133
        // `task.Exec.settings.dir` is defined in loaded robo.yml configuration file.
134
        $this->guy->seeInOutput("->dir('/some/dir')");
135
    }
136
}
137