Completed
Push — feature/config-import-null-208 ( 7e46bb...af0379 )
by Tom
04:26
created

GetCommandTest::testExecute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 74
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 74
rs 9.0335
cc 1
eloc 42
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace N98\Magento\Command\Config;
4
5
use N98\Magento\Command\TestCase;
6
7
class GetCommandTest extends TestCase
8
{
9
    /**
10
     * @test
11
     */
12
    public function nullValues()
13
    {
14
        $this->assertDisplayRegExp(
15
            array(
16
                'command'   => 'config:set',
17
                '--no-null' => null,
18
                'path'      => 'n98_magerun/foo/bar',
19
                'value'     => 'NULL',
20
            ),
21
            '~^n98_magerun/foo/bar => NULL$~'
22
        );
23
24
        $this->assertDisplayContains(
25
            array(
26
                'command'          => 'config:get',
27
                '--magerun-script' => null,
28
                'path'             => 'n98_magerun/foo/bar',
29
            ),
30
            'config:set --no-null --scope-id=0 --scope=default'
31
        );
32
33
        $this->assertDisplayContains(
34
            array(
35
                'command' => 'config:set',
36
                'path'    => 'n98_magerun/foo/bar',
37
                'value'   => 'NULL',
38
            ),
39
            'n98_magerun/foo/bar => NULL (NULL/"unkown" value)'
40
        );
41
42
        $this->assertDisplayContains(
43
            array(
44
                'command' => 'config:get',
45
                'path'    => 'n98_magerun/foo/bar',
46
            ),
47
            '| n98_magerun/foo/bar | default | 0        | NULL (NULL/"unkown" value) |'
48
        );
49
50
        $this->assertDisplayContains(
51
            array(
52
                'command'          => 'config:get',
53
                '--magerun-script' => true, # needed to not use the previous output cache
54
                'path'             => 'n98_magerun/foo/bar',
55
            ),
56
            'config:set --scope-id=0 --scope=default -- \'n98_magerun/foo/bar\' NULL'
57
        );
58
    }
59
60 View Code Duplication
    public function provideFormatsWithNull()
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...
61
    {
62
        return array(
63
            array('csv', 'n98_magerun/foo/bar,default,0,NULL'),
64
            array('json', '"Value": null'),
65
            array('xml', '<Value>NULL</Value>'),
66
        );
67
    }
68
69
    /**
70
     * @test
71
     * @dataProvider provideFormatsWithNull
72
     */
73 View Code Duplication
    public function nullWithFormat($format, $expected)
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...
74
    {
75
        $this->assertDisplayContains(
76
            array(
77
                'command' => 'config:set',
78
                'path'    => 'n98_magerun/foo/bar',
79
                'value'   => 'NULL',
80
            ),
81
            'n98_magerun/foo/bar => NULL (NULL/"unkown" value)'
82
        );
83
84
        $this->assertDisplayContains(
85
            array(
86
                'command'  => 'config:get',
87
                '--format' => $format,
88
                'path'     => 'n98_magerun/foo/bar',
89
            ),
90
            $expected
91
        );
92
    }
93
94
    public function testExecute()
95
    {
96
        /**
97
         * Add a new entry (to test for it)
98
         */
99
        $this->assertDisplayContains(
100
            array(
101
                'command' => 'config:set',
102
                'path'    => 'n98_magerun/foo/bar',
103
                'value'   => '1234',
104
            ),
105
            'n98_magerun/foo/bar => 1234'
106
        );
107
108
        $this->assertDisplayContains(
109
            array(
110
                'command' => 'config:get',
111
                'path'    => 'n98_magerun/foo/bar',
112
            ),
113
            '| n98_magerun/foo/bar | default | 0        | 1234  |'
114
        );
115
116
        $this->assertDisplayContains(
117
            array(
118
                'command'         => 'config:get',
119
                'path'            => 'n98_magerun/foo/bar',
120
                '--update-script' => true,
121
            ),
122
            "\$installer->setConfigData('n98_magerun/foo/bar', '1234');"
123
        );
124
125
        $this->assertDisplayContains(
126
            array(
127
                'command'          => 'config:get',
128
                'path'             => 'n98_magerun/foo/bar',
129
                '--magerun-script' => true,
130
            ),
131
            "config:set --scope-id=0 --scope=default -- 'n98_magerun/foo/bar' '1234'"
132
        );
133
134
        /**
135
         * Dump CSV
136
         */
137
        $input = array(
138
            'command'  => 'config:get',
139
            'path'     => 'n98_magerun/foo/bar',
140
            '--format' => 'csv',
141
        );
142
        $this->assertDisplayContains($input, 'Path,Scope,Scope-ID,Value');
143
        $this->assertDisplayContains($input, 'n98_magerun/foo/bar,default,0,1234');
144
145
        /**
146
         * Dump XML
147
         */
148
        $input = array(
149
            'command'  => 'config:get',
150
            'path'     => 'n98_magerun/foo/bar',
151
            '--format' => 'xml',
152
        );
153
        $this->assertDisplayContains($input, '<table>');
154
        $this->assertDisplayContains($input, '<Value>1234</Value>');
155
156
        /**
157
         * Dump JSON
158
         */
159
        $this->assertDisplayRegExp(
160
            array(
161
                'command'  => 'config:get',
162
                'path'     => 'n98_magerun/foo/bar',
163
                '--format' => 'json',
164
            ),
165
            '/"Value":\s*"1234"/'
166
        );
167
    }
168
}
169