Completed
Push — master ( 29ee36...16ede1 )
by Tom
03:58
created

GetCommandTest::nullValues()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 47
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 47
rs 9.0303
cc 1
eloc 31
nc 1
nop 0
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
    public function provideFormatsWithNull()
61
    {
62
        return array(
63
            array(null, '| n98_magerun/foo/bar | default | 0        | NULL (NULL/"unkown" value) |'),
64
            array('csv', 'n98_magerun/foo/bar,default,0,NULL'),
65
            array('json', '"Value": null'),
66
            array('xml', '<Value>NULL</Value>'),
67
        );
68
    }
69
70
    /**
71
     * @test
72
     * @dataProvider provideFormatsWithNull
73
     */
74 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...
75
    {
76
        $this->assertDisplayContains(
77
            array(
78
                'command' => 'config:set',
79
                'path'    => 'n98_magerun/foo/bar',
80
                'value'   => 'NULL',
81
            ),
82
            'n98_magerun/foo/bar => NULL (NULL/"unkown" value)'
83
        );
84
85
        $this->assertDisplayContains(
86
            array(
87
                'command'  => 'config:get',
88
                '--format' => $format,
89
                'path'     => 'n98_magerun/foo/bar',
90
            ),
91
            $expected
92
        );
93
    }
94
95
    public function testExecute()
96
    {
97
        /**
98
         * Add a new entry (to test for it)
99
         */
100
        $this->assertDisplayContains(
101
            array(
102
                'command' => 'config:set',
103
                'path'    => 'n98_magerun/foo/bar',
104
                'value'   => '1234',
105
            ),
106
            'n98_magerun/foo/bar => 1234'
107
        );
108
109
        $this->assertDisplayContains(
110
            array(
111
                'command' => 'config:get',
112
                'path'    => 'n98_magerun/foo/bar',
113
            ),
114
            '| n98_magerun/foo/bar | default | 0        | 1234  |'
115
        );
116
117
        $this->assertDisplayContains(
118
            array(
119
                'command'         => 'config:get',
120
                'path'            => 'n98_magerun/foo/bar',
121
                '--update-script' => true,
122
            ),
123
            "\$installer->setConfigData('n98_magerun/foo/bar', '1234');"
124
        );
125
126
        $this->assertDisplayContains(
127
            array(
128
                'command'          => 'config:get',
129
                'path'             => 'n98_magerun/foo/bar',
130
                '--magerun-script' => true,
131
            ),
132
            "config:set --scope-id=0 --scope=default -- 'n98_magerun/foo/bar' '1234'"
133
        );
134
135
        /**
136
         * Dump CSV
137
         */
138
        $input = array(
139
            'command'  => 'config:get',
140
            'path'     => 'n98_magerun/foo/bar',
141
            '--format' => 'csv',
142
        );
143
        $this->assertDisplayContains($input, 'Path,Scope,Scope-ID,Value');
144
        $this->assertDisplayContains($input, 'n98_magerun/foo/bar,default,0,1234');
145
146
        /**
147
         * Dump XML
148
         */
149
        $input = array(
150
            'command'  => 'config:get',
151
            'path'     => 'n98_magerun/foo/bar',
152
            '--format' => 'xml',
153
        );
154
        $this->assertDisplayContains($input, '<table>');
155
        $this->assertDisplayContains($input, '<Value>1234</Value>');
156
157
        /**
158
         * Dump JSON
159
         */
160
        $this->assertDisplayRegExp(
161
            array(
162
                'command'  => 'config:get',
163
                'path'     => 'n98_magerun/foo/bar',
164
                '--format' => 'json',
165
            ),
166
            '/"Value":\s*"1234"/'
167
        );
168
    }
169
}
170