Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
LockConfigProcessorTest.php
Go to the documentation of this file.
1 <?php
7 
18 use PHPUnit_Framework_MockObject_MockObject as Mock;
19 
26 class LockConfigProcessorTest extends \PHPUnit\Framework\TestCase
27 {
31  private $model;
32 
36  private $preparedValueFactory;
37 
41  private $deploymentConfigWriterMock;
42 
46  private $arrayManagerMock;
47 
51  private $configPathResolver;
52 
56  private $valueMock;
57 
61  protected function setUp()
62  {
63  $this->preparedValueFactory = $this->getMockBuilder(PreparedValueFactory::class)
64  ->disableOriginalConstructor()
65  ->getMock();
66  $this->deploymentConfigWriterMock = $this->getMockBuilder(DeploymentConfig\Writer::class)
67  ->disableOriginalConstructor()
68  ->getMock();
69  $this->arrayManagerMock = $this->getMockBuilder(ArrayManager::class)
70  ->disableOriginalConstructor()
71  ->getMock();
72  $this->configPathResolver = $this->getMockBuilder(ConfigPathResolver::class)
73  ->disableOriginalConstructor()
74  ->getMock();
75  $this->valueMock = $this->getMockBuilder(Value::class)
76  ->setMethods(['validateBeforeSave', 'beforeSave', 'setValue', 'getValue', 'afterSave'])
77  ->disableOriginalConstructor()
78  ->getMock();
79 
80  $this->model = new LockProcessor(
81  $this->preparedValueFactory,
82  $this->deploymentConfigWriterMock,
83  $this->arrayManagerMock,
84  $this->configPathResolver,
86  );
87  }
88 
98  public function testProcess($path, $value, $scope, $scopeCode)
99  {
100  $this->preparedValueFactory->expects($this->once())
101  ->method('create')
102  ->with($path, $value, $scope, $scopeCode)
103  ->willReturn($this->valueMock);
104  $this->configPathResolver->expects($this->once())
105  ->method('resolve')
106  ->willReturn('system/default/test/test/test');
107  $this->arrayManagerMock->expects($this->once())
108  ->method('set')
109  ->with('system/default/test/test/test', [], $value)
110  ->willReturn([
111  'system' => [
112  'default' => [
113  'test' => [
114  'test' => [
115  'test' => $value
116  ]
117  ]
118  ]
119  ]
120  ]);
121  $this->valueMock->expects($this->once())
122  ->method('getValue')
123  ->willReturn($value);
124  $this->deploymentConfigWriterMock->expects($this->once())
125  ->method('saveConfig')
126  ->with(
127  [
129  'system' => [
130  'default' => [
131  'test' => [
132  'test' => [
133  'test' => $value
134  ]
135  ]
136  ]
137  ]
138  ]
139  ],
140  false
141  );
142  $this->valueMock->expects($this->once())
143  ->method('validateBeforeSave');
144  $this->valueMock->expects($this->once())
145  ->method('beforeSave');
146  $this->valueMock->expects($this->once())
147  ->method('afterSave');
148 
149  $this->model->process($path, $value, $scope, $scopeCode);
150  }
151 
155  public function processDataProvider()
156  {
157  return [
158  ['test/test/test', 'value', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null],
159  ['test/test/test', 'value', ScopeInterface::SCOPE_WEBSITE, 'base'],
160  ['test/test/test', 'value', ScopeInterface::SCOPE_STORE, 'test'],
161  ];
162  }
163 
168  public function testProcessNotReadableFs()
169  {
170  $path = 'test/test/test';
171  $value = 'value';
172 
173  $this->preparedValueFactory->expects($this->once())
174  ->method('create')
175  ->willReturn($this->valueMock);
176  $this->valueMock->expects($this->once())
177  ->method('getValue')
178  ->willReturn($value);
179  $this->configPathResolver->expects($this->once())
180  ->method('resolve')
181  ->willReturn('system/default/test/test/test');
182  $this->arrayManagerMock->expects($this->once())
183  ->method('set')
184  ->with('system/default/test/test/test', [], $value)
185  ->willReturn(null);
186  $this->deploymentConfigWriterMock->expects($this->once())
187  ->method('saveConfig')
188  ->willThrowException(new FileSystemException(__('Filesystem is not writable.')));
189 
190  $this->model->process($path, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
191  }
192 
197  public function testCustomException()
198  {
199  $path = 'test/test/test';
200  $value = 'value';
201 
202  $this->configPathResolver->expects($this->once())
203  ->method('resolve')
204  ->willReturn('system/default/test/test/test');
205  $this->preparedValueFactory->expects($this->once())
206  ->method('create')
207  ->willReturn($this->valueMock);
208  $this->arrayManagerMock->expects($this->never())
209  ->method('set');
210  $this->valueMock->expects($this->once())
211  ->method('getValue');
212  $this->valueMock->expects($this->once())
213  ->method('afterSave')
214  ->willThrowException(new \Exception('Invalid values'));
215  $this->deploymentConfigWriterMock->expects($this->never())
216  ->method('saveConfig');
217 
218  $this->model->process($path, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
219  }
220 }
__()
Definition: __.php:13
$value
Definition: gender.phtml:16