5
5
*/
6
6
namespace Magento \Config \Test \Unit \Console \Command ;
7
7
8
- use Magento \Config \Console \Command \ConfigSet \ConfigSetProcessorFactory ;
9
- use Magento \Config \Console \Command \ConfigSet \ConfigSetProcessorInterface ;
8
+ use Magento \Config \Console \Command \ConfigSet \ProcessorFacade ;
9
+ use Magento \Config \Console \Command \ConfigSet \ProcessorFacadeFactory ;
10
10
use Magento \Config \Console \Command \ConfigSetCommand ;
11
- use Magento \Config \Model \Config \PathValidator ;
12
- use Magento \Config \Model \Config \PathValidatorFactory ;
13
- use Magento \Framework \App \Scope \ValidatorInterface ;
11
+ use Magento \Framework \App \State ;
14
12
use Magento \Framework \Config \ScopeInterface ;
15
13
use Magento \Framework \Console \Cli ;
16
- use Magento \Framework \Exception \LocalizedException ;
17
14
use Magento \Framework \Exception \ValidatorException ;
18
15
use PHPUnit_Framework_MockObject_MockObject as Mock ;
19
16
use Symfony \Component \Console \Tester \CommandTester ;
22
19
* Test for ConfigSetCommand.
23
20
*
24
21
* @see ConfigSetCommand
25
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26
22
*/
27
23
class ConfigSetCommandTest extends \PHPUnit_Framework_TestCase
28
24
{
@@ -32,129 +28,59 @@ class ConfigSetCommandTest extends \PHPUnit_Framework_TestCase
32
28
private $ command ;
33
29
34
30
/**
35
- * @var ConfigSetProcessorFactory|Mock
36
- */
37
- private $ configSetProcessorFactoryMock ;
38
-
39
- /**
40
- * @var ValidatorInterface|Mock
41
- */
42
- private $ validatorMock ;
43
-
44
- /**
45
- * @var ConfigSetProcessorInterface|Mock
31
+ * @var ScopeInterface|Mock
46
32
*/
47
- private $ processorMock ;
33
+ private $ scopeMock ;
48
34
49
35
/**
50
- * @var ScopeInterface |Mock
36
+ * @var State |Mock
51
37
*/
52
- private $ scopeMock ;
38
+ private $ stateMock ;
53
39
54
40
/**
55
- * @var PathValidatorFactory |Mock
41
+ * @var ProcessorFacadeFactory |Mock
56
42
*/
57
- private $ pathValidatorFactoryMock ;
43
+ private $ processorFacadeFactoryMock ;
58
44
59
45
/**
60
- * @var PathValidator |Mock
46
+ * @var ProcessorFacade |Mock
61
47
*/
62
- private $ pathValidator ;
48
+ private $ processorFacadeMock ;
63
49
64
50
/**
65
51
* @inheritdoc
66
52
*/
67
53
protected function setUp ()
68
54
{
69
- $ this ->configSetProcessorFactoryMock = $ this ->getMockBuilder (ConfigSetProcessorFactory::class)
70
- ->disableOriginalConstructor ()
71
- ->setMethods (['create ' ])
72
- ->getMock ();
73
- $ this ->validatorMock = $ this ->getMockBuilder (ValidatorInterface::class)
74
- ->getMockForAbstractClass ();
75
- $ this ->processorMock = $ this ->getMockBuilder (ConfigSetProcessorInterface::class)
76
- ->getMockForAbstractClass ();
77
55
$ this ->scopeMock = $ this ->getMockBuilder (ScopeInterface::class)
78
56
->getMockForAbstractClass ();
79
- $ this ->pathValidatorFactoryMock = $ this ->getMockBuilder (PathValidatorFactory::class)
57
+ $ this ->stateMock = $ this ->getMockBuilder (State::class)
58
+ ->disableOriginalConstructor ()
59
+ ->getMock ();
60
+ $ this ->processorFacadeFactoryMock = $ this ->getMockBuilder (ProcessorFacadeFactory::class)
80
61
->disableOriginalConstructor ()
81
- ->setMethods (['create ' ])
82
62
->getMock ();
83
- $ this ->pathValidator = $ this ->getMockBuilder (PathValidator ::class)
63
+ $ this ->processorFacadeMock = $ this ->getMockBuilder (ProcessorFacade ::class)
84
64
->disableOriginalConstructor ()
85
65
->getMock ();
86
66
87
- $ this ->pathValidatorFactoryMock ->expects ($ this ->any ())
67
+ $ this ->processorFacadeFactoryMock ->expects ($ this ->any ())
88
68
->method ('create ' )
89
- ->willReturn ($ this ->pathValidator );
69
+ ->willReturn ($ this ->processorFacadeMock );
90
70
91
71
$ this ->command = new ConfigSetCommand (
92
- $ this ->configSetProcessorFactoryMock ,
93
- $ this ->validatorMock ,
94
72
$ this ->scopeMock ,
95
- $ this ->pathValidatorFactoryMock
73
+ $ this ->stateMock ,
74
+ $ this ->processorFacadeFactoryMock
96
75
);
97
76
}
98
77
99
- public function testExecute ()
100
- {
101
- $ this ->validatorMock ->expects ($ this ->once ())
102
- ->method ('isValid ' )
103
- ->willReturn (true );
104
- $ this ->configSetProcessorFactoryMock ->expects ($ this ->once ())
105
- ->method ('create ' )
106
- ->with (ConfigSetProcessorFactory::TYPE_DEFAULT )
107
- ->willReturn ($ this ->processorMock );
108
-
109
- $ tester = new CommandTester ($ this ->command );
110
- $ tester ->execute ([
111
- ConfigSetCommand::ARG_PATH => 'test/test/test ' ,
112
- ConfigSetCommand::ARG_VALUE => 'value '
113
- ]);
114
- }
115
-
116
- public function testExecuteLock ()
117
- {
118
- $ this ->validatorMock ->expects ($ this ->once ())
119
- ->method ('isValid ' )
120
- ->willReturn (true );
121
- $ this ->configSetProcessorFactoryMock ->expects ($ this ->once ())
122
- ->method ('create ' )
123
- ->with (ConfigSetProcessorFactory::TYPE_LOCK )
124
- ->willReturn ($ this ->processorMock );
125
-
126
- $ tester = new CommandTester ($ this ->command );
127
- $ tester ->execute ([
128
- ConfigSetCommand::ARG_PATH => 'test/test/test ' ,
129
- ConfigSetCommand::ARG_VALUE => 'value ' ,
130
- '-- ' . ConfigSetCommand::OPTION_LOCK => true
131
- ]);
132
- }
133
-
134
- public function testExecuteNotValidScope ()
135
- {
136
- $ this ->validatorMock ->expects ($ this ->once ())
137
- ->method ('isValid ' )
138
- ->willThrowException (new LocalizedException (__ ('Test exception ' )));
139
-
140
- $ tester = new CommandTester ($ this ->command );
141
- $ tester ->execute ([
142
- ConfigSetCommand::ARG_PATH => 'test/test/test ' ,
143
- ConfigSetCommand::ARG_VALUE => 'value '
144
- ]);
145
-
146
- $ this ->assertSame (Cli::RETURN_FAILURE , $ tester ->getStatusCode ());
147
- }
148
-
149
78
public function testExecuteWithException ()
150
79
{
151
- $ this ->validatorMock ->expects ($ this ->once ())
152
- ->method ('isValid ' )
153
- ->willReturn (true );
154
- $ this ->pathValidator ->expects ($ this ->once ())
155
- ->method ('validate ' )
80
+ $ this ->stateMock ->expects ($ this ->once ())
81
+ ->method ('emulateAreaCode ' )
156
82
->willThrowException (new ValidatorException (__ ('The "test/test/test" path does not exists ' )));
157
- $ this ->configSetProcessorFactoryMock ->expects ($ this ->never ())
83
+ $ this ->processorFacadeFactoryMock ->expects ($ this ->never ())
158
84
->method ('create ' );
159
85
160
86
$ tester = new CommandTester ($ this ->command );
0 commit comments