Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SensitiveConfigSetFacadeTest.php
Go to the documentation of this file.
1 <?php
7 
20 use PHPUnit_Framework_MockObject_MockObject as MockObject;
21 use Symfony\Component\Console\Input\InputInterface;
22 use Symfony\Component\Console\Output\OutputInterface;
23 
27 class SensitiveConfigSetFacadeTest extends \PHPUnit\Framework\TestCase
28 {
32  private $configFilePoolMock;
33 
37  private $commentParserMock;
38 
42  private $configWriterMock;
43 
47  private $scopeValidatorMock;
48 
52  private $collectorFactoryMock;
53 
57  private $command;
58 
62  private $inputMock;
63 
67  private $outputMock;
68 
72  public function setUp()
73  {
74  $this->configFilePoolMock = $this->getMockBuilder(ConfigFilePool::class)
75  ->disableOriginalConstructor()
76  ->getMock();
77  $this->commentParserMock = $this->getMockBuilder(CommentParserInterface::class)
78  ->getMockForAbstractClass();
79  $this->configWriterMock = $this->getMockBuilder(ConfigWriter::class)
80  ->disableOriginalConstructor()
81  ->getMock();
82  $this->scopeValidatorMock = $this->getMockBuilder(ValidatorInterface::class)
83  ->getMockForAbstractClass();
84  $this->collectorFactoryMock = $this->getMockBuilder(CollectorFactory::class)
85  ->disableOriginalConstructor()
86  ->getMock();
87  $this->inputMock = $this->getMockBuilder(InputInterface::class)
88  ->getMockForAbstractClass();
89  $this->outputMock = $this->getMockBuilder(OutputInterface::class)
90  ->getMockForAbstractClass();
91 
92  $this->command = new SensitiveConfigSetFacade(
93  $this->configFilePoolMock,
94  $this->commentParserMock,
95  $this->configWriterMock,
96  $this->scopeValidatorMock,
97  $this->collectorFactoryMock
98  );
99  }
100 
105  public function testConfigFileNotExist()
106  {
107  $this->inputMock->expects($this->any())
108  ->method('getOption')
109  ->with()
110  ->willReturnMap([
112  ]);
113  $this->configFilePoolMock->expects($this->once())
114  ->method('getPath')
116  ->willReturn('config.php');
117  $this->scopeValidatorMock->expects($this->once())
118  ->method('isValid')
119  ->with('default', '')
120  ->willReturn(true);
121  $this->commentParserMock->expects($this->any())
122  ->method('execute')
123  ->willThrowException(new FileSystemException(new Phrase('some message')));
124 
125  $this->command->process(
126  $this->inputMock,
127  $this->outputMock
128  );
129  }
130 
135  public function testWriterException()
136  {
137  $exceptionMessage = 'Some exception';
138  $this->inputMock->expects($this->any())
139  ->method('getOption')
140  ->with()
141  ->willReturnMap([
143  ]);
144  $this->scopeValidatorMock->expects($this->once())
145  ->method('isValid')
146  ->with('default', '')
147  ->willReturn(true);
148  $this->commentParserMock->expects($this->once())
149  ->method('execute')
150  ->willReturn([
151  'some/config/path1',
152  'some/config/path2'
153  ]);
154  $collectorMock = $this->getMockBuilder(CollectorInterface::class)
155  ->getMockForAbstractClass();
156  $collectorMock->expects($this->once())
157  ->method('getValues')
158  ->willReturn(['some/config/pathNotExist' => 'value']);
159  $this->collectorFactoryMock->expects($this->once())
160  ->method('create')
162  ->willReturn($collectorMock);
163  $this->configWriterMock->expects($this->once())
164  ->method('save')
165  ->willThrowException(new LocalizedException(__($exceptionMessage)));
166 
167  $this->command->process(
168  $this->inputMock,
169  $this->outputMock
170  );
171  }
172 
177  public function testEmptyConfigPaths()
178  {
179  $this->inputMock->expects($this->any())
180  ->method('getOption')
181  ->with()
182  ->willReturnMap([
184  ]);
185  $this->scopeValidatorMock->expects($this->once())
186  ->method('isValid')
187  ->with('default', '')
188  ->willReturn(true);
189  $this->commentParserMock->expects($this->once())
190  ->method('execute')
191  ->willReturn([]);
192 
193  $this->command->process(
194  $this->inputMock,
195  $this->outputMock
196  );
197  }
198 
199  public function testExecute()
200  {
201  $collectedValues = ['some/config/path1' => 'value'];
202  $this->inputMock->expects($this->any())
203  ->method('getOption')
204  ->with()
205  ->willReturnMap([
207  ]);
208  $this->scopeValidatorMock->expects($this->once())
209  ->method('isValid')
210  ->with('default', '')
211  ->willReturn(true);
212  $this->commentParserMock->expects($this->once())
213  ->method('execute')
214  ->willReturn([
215  'some/config/path1',
216  'some/config/path2'
217  ]);
218  $collectorMock = $this->getMockBuilder(CollectorInterface::class)
219  ->getMockForAbstractClass();
220  $collectorMock->expects($this->once())
221  ->method('getValues')
222  ->willReturn($collectedValues);
223  $this->collectorFactoryMock->expects($this->once())
224  ->method('create')
226  ->willReturn($collectorMock);
227  $this->configWriterMock->expects($this->once())
228  ->method('save')
229  ->with($collectedValues, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, '');
230 
231  $this->command->process(
232  $this->inputMock,
233  $this->outputMock
234  );
235  }
236 
237  public function testExecuteInteractive()
238  {
239  $collectedValues = ['some/config/path1' => 'value'];
240  $this->inputMock->expects($this->any())
241  ->method('getOption')
242  ->with()
243  ->willReturnMap([
246  ]);
247  $this->scopeValidatorMock->expects($this->once())
248  ->method('isValid')
249  ->with('default', '')
250  ->willReturn(true);
251  $this->commentParserMock->expects($this->once())
252  ->method('execute')
253  ->willReturn([
254  'some/config/path1',
255  'some/config/path2',
256  'some/config/path3'
257  ]);
258  $collectorMock = $this->getMockBuilder(CollectorInterface::class)
259  ->getMockForAbstractClass();
260  $collectorMock->expects($this->once())
261  ->method('getValues')
262  ->willReturn($collectedValues);
263  $this->collectorFactoryMock->expects($this->once())
264  ->method('create')
266  ->willReturn($collectorMock);
267  $this->configWriterMock->expects($this->once())
268  ->method('save')
269  ->with($collectedValues, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, '');
270 
271  $this->command->process(
272  $this->inputMock,
273  $this->outputMock
274  );
275  }
276 }
__()
Definition: __.php:13