Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ProcessorFacadeTest.php
Go to the documentation of this file.
1 <?php
7 
22 use PHPUnit_Framework_MockObject_MockObject as Mock;
23 
30 class ProcessorFacadeTest extends \PHPUnit\Framework\TestCase
31 {
35  private $model;
36 
40  private $scopeValidatorMock;
41 
45  private $pathValidatorMock;
46 
50  private $configSetProcessorFactoryMock;
51 
55  private $processorMock;
56 
60  private $hashMock;
61 
65  private $configMock;
66 
70  protected function setUp()
71  {
72  $this->scopeValidatorMock = $this->getMockBuilder(ValidatorInterface::class)
73  ->getMockForAbstractClass();
74  $this->pathValidatorMock = $this->getMockBuilder(PathValidator::class)
75  ->disableOriginalConstructor()
76  ->getMock();
77  $this->configSetProcessorFactoryMock = $this->getMockBuilder(ConfigSetProcessorFactory::class)
78  ->disableOriginalConstructor()
79  ->getMock();
80  $this->processorMock = $this->getMockBuilder(ConfigSetProcessorInterface::class)
81  ->getMockForAbstractClass();
82 
83  $this->configSetProcessorFactoryMock->expects($this->any())
84  ->method('create')
85  ->willReturn($this->processorMock);
86 
87  $this->hashMock = $this->getMockBuilder(Hash::class)
88  ->disableOriginalConstructor()
89  ->getMock();
90  $this->configMock = $this->getMockBuilder(Config::class)
91  ->disableOriginalConstructor()
92  ->getMock();
93 
94  $this->model = new ProcessorFacade(
95  $this->scopeValidatorMock,
96  $this->pathValidatorMock,
97  $this->configSetProcessorFactoryMock,
98  $this->hashMock,
99  $this->configMock
100  );
101  }
102 
103  public function testProcess()
104  {
105  $this->scopeValidatorMock->expects($this->once())
106  ->method('isValid')
107  ->willReturn(true);
108  $this->pathValidatorMock->expects($this->once())
109  ->method('validate')
110  ->willReturn(true);
111  $this->configSetProcessorFactoryMock->expects($this->once())
112  ->method('create')
114  ->willReturn($this->processorMock);
115  $this->processorMock->expects($this->once())
116  ->method('process')
117  ->with('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
118  $this->hashMock->expects($this->once())
119  ->method('regenerate')
120  ->with(System::CONFIG_TYPE);
121  $this->configMock->expects($this->once())
122  ->method('clean');
123 
124  $this->assertSame(
125  'Value was saved.',
126  $this->model->processWithLockTarget(
127  'test/test/test',
128  'test',
130  null,
131  false
132  )
133  );
134  }
135 
141  {
142  $this->expectException(ValidatorException::class);
143  $this->expectExceptionMessage('Some error');
144  $this->scopeValidatorMock->expects($this->once())
145  ->method('isValid')
146  ->willThrowException($exception);
147 
148  $this->model->processWithLockTarget(
149  'test/test/test',
150  'test',
152  null,
153  false
154  );
155  }
156 
161  {
162  return [
163  [new LocalizedException(__('Some error'))],
164  [new ValidatorException(__('Some error'))],
165  ];
166  }
167 
173  {
174  $this->scopeValidatorMock->expects($this->once())
175  ->method('isValid')
176  ->willReturn(true);
177  $this->pathValidatorMock->expects($this->once())
178  ->method('validate')
179  ->willReturn(true);
180  $this->configSetProcessorFactoryMock->expects($this->once())
181  ->method('create')
183  ->willThrowException(new ConfigurationMismatchException(__('Some error')));
184  $this->processorMock->expects($this->never())
185  ->method('process');
186  $this->configMock->expects($this->never())
187  ->method('clean');
188 
189  $this->model->processWithLockTarget(
190  'test/test/test',
191  'test',
193  null,
194  false
195  );
196  }
197 
203  {
204  $this->scopeValidatorMock->expects($this->once())
205  ->method('isValid')
206  ->willReturn(true);
207  $this->pathValidatorMock->expects($this->once())
208  ->method('validate')
209  ->willReturn(true);
210  $this->configSetProcessorFactoryMock->expects($this->once())
211  ->method('create')
213  ->willReturn($this->processorMock);
214  $this->processorMock->expects($this->once())
215  ->method('process')
216  ->with('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null)
217  ->willThrowException(new CouldNotSaveException(__('Some error')));
218  $this->configMock->expects($this->never())
219  ->method('clean');
220 
221  $this->model->processWithLockTarget(
222  'test/test/test',
223  'test',
225  null,
226  false
227  );
228  }
229 
230  public function testExecuteLockEnv()
231  {
232  $this->scopeValidatorMock->expects($this->once())
233  ->method('isValid')
234  ->willReturn(true);
235  $this->configSetProcessorFactoryMock->expects($this->once())
236  ->method('create')
238  ->willReturn($this->processorMock);
239  $this->processorMock->expects($this->once())
240  ->method('process')
241  ->with('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
242  $this->configMock->expects($this->once())
243  ->method('clean');
244 
245  $this->assertSame(
246  'Value was saved in app/etc/env.php and locked.',
247  $this->model->processWithLockTarget(
248  'test/test/test',
249  'test',
251  null,
252  true
253  )
254  );
255  }
256 
257  public function testExecuteLockConfig()
258  {
259  $this->scopeValidatorMock->expects($this->once())
260  ->method('isValid')
261  ->willReturn(true);
262  $this->configSetProcessorFactoryMock->expects($this->once())
263  ->method('create')
265  ->willReturn($this->processorMock);
266  $this->processorMock->expects($this->once())
267  ->method('process')
268  ->with('test/test/test', 'test', ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
269  $this->configMock->expects($this->once())
270  ->method('clean');
271 
272  $this->assertSame(
273  'Value was saved in app/etc/config.php and locked.',
274  $this->model->processWithLockTarget(
275  'test/test/test',
276  'test',
278  null,
279  true,
281  )
282  );
283  }
284 }
__()
Definition: __.php:13