11 use Magento\Config\Model\Config\StructureFactory;
21 use PHPUnit_Framework_MockObject_MockObject as Mock;
33 private $structureFactoryMock;
38 private $valueFactoryMock;
48 private $structureMock;
63 private $scopeResolverPoolMock;
68 private $scopeResolverMock;
78 private $scopeTypeNormalizer;
83 private $preparedValueFactory;
90 $this->structureFactoryMock = $this->getMockBuilder(StructureFactory::class)
91 ->disableOriginalConstructor()
92 ->setMethods([
'create'])
94 $this->valueFactoryMock = $this->getMockBuilder(BackendFactory::class)
95 ->disableOriginalConstructor()
96 ->setMethods([
'create'])
98 $this->structureMock = $this->getMockBuilder(Structure::class)
99 ->disableOriginalConstructor()
101 $this->fieldMock = $this->getMockBuilder(Field::class)
102 ->disableOriginalConstructor()
104 $this->valueMock = $this->getMockBuilder(Value::class)
105 ->disableOriginalConstructor()
107 'setPath',
'setScope',
'setScopeId',
'setValue',
'setField',
108 'setGroupId',
'setFieldConfig',
'setScopeCode' 111 $this->configMock = $this->getMockBuilder(ScopeConfigInterface::class)
112 ->getMockForAbstractClass();
113 $this->scopeResolverPoolMock = $this->getMockBuilder(ScopeResolverPool::class)
114 ->disableOriginalConstructor()
116 $this->scopeResolverMock = $this->getMockBuilder(ScopeResolver::class)
117 ->disableOriginalConstructor()
119 $this->scopeMock = $this->getMockBuilder(ScopeInterface::class)
120 ->getMockForAbstractClass();
121 $this->scopeTypeNormalizer = $this->getMockBuilder(ScopeTypeNormalizer::class)
122 ->disableOriginalConstructor()
126 $this->scopeResolverPoolMock,
127 $this->structureFactoryMock,
128 $this->valueFactoryMock,
130 $this->scopeTypeNormalizer
143 public function testCreate(
151 $groupPath =
'some/group';
154 $fieldData = [
'backend_model' =>
'some_model'];
157 $this->scopeResolverPoolMock->expects($this->once())
160 ->willReturn($this->scopeResolverMock);
161 $this->scopeResolverMock->expects($this->once())
164 ->willReturn($this->scopeMock);
165 $this->scopeMock->expects($this->once())
167 ->willReturn($scopeId);
170 $groupMock = $this->getMockBuilder(Group::class)
171 ->disableOriginalConstructor()
173 $groupMock->expects($this->once())
177 $this->scopeTypeNormalizer->expects($this->once())
178 ->method(
'normalize')
180 ->willReturnArgument(0);
181 $this->structureFactoryMock->expects($this->once())
183 ->willReturn($this->structureMock);
184 $this->structureMock->expects($this->once())
185 ->method(
'getElementByConfigPath')
186 ->willReturn($this->fieldMock);
187 $this->structureMock->expects($this->once())
188 ->method(
'getElement')
190 ->willReturn($groupMock);
191 $this->fieldMock->expects($this->once())
192 ->method(
'hasBackendModel')
195 ->method(
'getConfigPath')
196 ->willReturn($configPath);
202 ->willReturn($fieldData);
203 $this->fieldMock->expects($this->once())
204 ->method(
'getGroupPath')
205 ->willReturn($groupPath);
206 $this->valueFactoryMock->expects($this->once())
208 ->willReturn($this->valueMock);
209 $this->valueMock->expects($this->once())
211 ->with($configPath ?:
$path)
213 $this->valueMock->expects($this->once())
217 $this->valueMock->expects($this->once())
218 ->method(
'setScopeId')
221 $this->valueMock->expects($this->once())
222 ->method(
'setScopeCode')
225 $this->valueMock->expects($this->once())
229 $this->valueMock->expects($this->once())
233 $this->valueMock->expects($this->once())
234 ->method(
'setGroupId')
237 $this->valueMock->expects($this->once())
238 ->method(
'setFieldConfig')
242 $this->assertInstanceOf(
244 $this->preparedValueFactory->create(
$path,
$value, $scope, $scopeCode)
262 'standard flow with custom config path' => [
264 '/custom/config_path',
271 'default scope flow' => [
280 'website scope flow' => [
283 StoreScopeInterface::SCOPE_WEBSITE,
284 StoreScopeInterface::SCOPE_WEBSITES,
288 'websites scope flow' => [
291 StoreScopeInterface::SCOPE_WEBSITES,
292 StoreScopeInterface::SCOPE_WEBSITES,
296 'store scope flow' => [
299 StoreScopeInterface::SCOPE_STORE,
300 StoreScopeInterface::SCOPE_STORES,
304 'stores scope flow' => [
307 StoreScopeInterface::SCOPE_STORES,
308 StoreScopeInterface::SCOPE_STORES,
326 $this->scopeResolverPoolMock->expects($this->never())
328 $this->scopeResolverMock->expects($this->never())
329 ->method(
'getScope');
330 $this->scopeMock->expects($this->never())
335 $this->structureFactoryMock->expects($this->once())
337 ->willReturn($this->structureMock);
338 $this->structureMock->expects($this->once())
339 ->method(
'getElementByConfigPath')
340 ->willReturn($this->fieldMock);
341 $this->fieldMock->expects($this->once())
342 ->method(
'hasBackendModel')
344 $this->fieldMock->expects($this->never())
345 ->method(
'getBackendModel');
346 $this->valueFactoryMock->expects($this->once())
349 $this->valueMock->expects($this->never())
351 $this->valueMock->expects($this->never())
352 ->method(
'setScope');
353 $this->valueMock->expects($this->never())
354 ->method(
'setScopeId');
355 $this->valueMock->expects($this->never())
356 ->method(
'setValue');
360 $this->preparedValueFactory->create(
$path,
$value, $scope, $scopeCode)
376 'default scope flow' => [
390 $this->structureFactoryMock->expects($this->once())
392 ->willThrowException(
new \Exception(
'Some exception'));
createNotInstanceOfValueDataProvider()
testCreateWithException()
testCreateNotInstanceOfValue( $path, $scope, $scopeCode)