7
7
8
8
use Magento \Config \App \Config \Type \System ;
9
9
use Magento \Config \Console \Command \ConfigSet \DefaultProcessor ;
10
+ use Magento \Config \Model \Config ;
11
+ use Magento \Config \Model \Config \Factory as ConfigFactory ;
10
12
use Magento \Framework \App \Config \ConfigPathResolver ;
11
13
use Magento \Framework \App \Config \ScopeConfigInterface ;
12
14
use Magento \Framework \App \DeploymentConfig ;
13
15
use Magento \Store \Model \ScopeInterface ;
14
16
use Magento \Config \Model \PreparedValueFactory ;
15
17
use Magento \Framework \App \Config \Value ;
16
- use Magento \Framework \App \Config \ValueInterface ;
17
18
use Magento \Framework \Model \ResourceModel \Db \AbstractDb ;
18
19
use PHPUnit_Framework_MockObject_MockObject as Mock ;
19
20
@@ -55,17 +56,18 @@ class DefaultProcessorTest extends \PHPUnit\Framework\TestCase
55
56
*/
56
57
private $ resourceModelMock ;
57
58
59
+ /**
60
+ * @var ConfigFactory|Mock
61
+ */
62
+ private $ configFactory ;
63
+
58
64
/**
59
65
* @inheritdoc
60
66
*/
61
67
protected function setUp ()
62
68
{
63
- $ this ->deploymentConfigMock = $ this ->getMockBuilder (DeploymentConfig::class)
64
- ->disableOriginalConstructor ()
65
- ->getMock ();
66
- $ this ->configPathResolverMock = $ this ->getMockBuilder (ConfigPathResolver::class)
67
- ->disableOriginalConstructor ()
68
- ->getMock ();
69
+ $ this ->deploymentConfigMock = $ this ->createMock (DeploymentConfig::class);
70
+ $ this ->configPathResolverMock = $ this ->createMock (ConfigPathResolver::class);
69
71
$ this ->resourceModelMock = $ this ->getMockBuilder (AbstractDb::class)
70
72
->disableOriginalConstructor ()
71
73
->setMethods (['save ' ])
@@ -74,14 +76,14 @@ protected function setUp()
74
76
->disableOriginalConstructor ()
75
77
->setMethods (['getResource ' ])
76
78
->getMock ();
77
- $ this ->preparedValueFactoryMock = $ this ->getMockBuilder (PreparedValueFactory::class)
78
- ->disableOriginalConstructor ()
79
- ->getMock ();
79
+ $ this ->preparedValueFactoryMock = $ this ->createMock (PreparedValueFactory::class);
80
+ $ this ->configFactory = $ this ->createMock (ConfigFactory::class);
80
81
81
82
$ this ->model = new DefaultProcessor (
82
83
$ this ->preparedValueFactoryMock ,
83
84
$ this ->deploymentConfigMock ,
84
- $ this ->configPathResolverMock
85
+ $ this ->configPathResolverMock ,
86
+ $ this ->configFactory
85
87
);
86
88
}
87
89
@@ -98,15 +100,16 @@ public function testProcess($path, $value, $scope, $scopeCode)
98
100
{
99
101
$ this ->configMockForProcessTest ($ path , $ scope , $ scopeCode );
100
102
101
- $ this ->preparedValueFactoryMock ->expects ($ this ->once ())
103
+ $ config = $ this ->createMock (Config::class);
104
+ $ this ->configFactory ->expects ($ this ->once ())
102
105
->method ('create ' )
103
- ->willReturn ($ this ->valueMock );
104
- $ this ->valueMock ->expects ($ this ->once ())
105
- ->method ('getResource ' )
106
- ->willReturn ($ this ->resourceModelMock );
107
- $ this ->resourceModelMock ->expects ($ this ->once ())
106
+ ->with (['scope ' => $ scope , 'scope_code ' => $ scopeCode ])
107
+ ->willReturn ($ config );
108
+ $ config ->expects ($ this ->once ())
109
+ ->method ('setDataByPath ' )
110
+ ->with ($ path , $ value );
111
+ $ config ->expects ($ this ->once ())
108
112
->method ('save ' )
109
- ->with ($ this ->valueMock )
110
113
->willReturnSelf ();
111
114
112
115
$ this ->model ->process ($ path , $ value , $ scope , $ scopeCode );
@@ -124,28 +127,6 @@ public function processDataProvider()
124
127
];
125
128
}
126
129
127
- public function testProcessWithWrongValueInstance ()
128
- {
129
- $ path = 'test/test/test ' ;
130
- $ scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT ;
131
- $ scopeCode = null ;
132
- $ value = 'value ' ;
133
- $ valueInterfaceMock = $ this ->getMockBuilder (ValueInterface::class)
134
- ->getMockForAbstractClass ();
135
-
136
- $ this ->configMockForProcessTest ($ path , $ scope , $ scopeCode );
137
-
138
- $ this ->preparedValueFactoryMock ->expects ($ this ->once ())
139
- ->method ('create ' )
140
- ->willReturn ($ valueInterfaceMock );
141
- $ this ->valueMock ->expects ($ this ->never ())
142
- ->method ('getResource ' );
143
- $ this ->resourceModelMock ->expects ($ this ->never ())
144
- ->method ('save ' );
145
-
146
- $ this ->model ->process ($ path , $ value , $ scope , $ scopeCode );
147
- }
148
-
149
130
/**
150
131
* @param string $path
151
132
* @param string $scope
@@ -185,6 +166,9 @@ public function testProcessLockedValue()
185
166
->method ('resolve ' )
186
167
->willReturn ('system/default/test/test/test ' );
187
168
169
+ $ this ->configFactory ->expects ($ this ->never ())
170
+ ->method ('create ' );
171
+
188
172
$ this ->model ->process ($ path , $ value , ScopeConfigInterface::SCOPE_TYPE_DEFAULT , null );
189
173
}
190
174
}
0 commit comments