|
7 | 7 | namespace Magento\Framework\App\Test\Unit\DeploymentConfig;
|
8 | 8 |
|
9 | 9 | use Magento\Framework\App\DeploymentConfig;
|
| 10 | +use Magento\Framework\App\DeploymentConfig\Reader; |
10 | 11 | use Magento\Framework\App\DeploymentConfig\Writer;
|
| 12 | +use Magento\Framework\App\DeploymentConfig\Writer\FormatterInterface; |
11 | 13 | use Magento\Framework\App\Filesystem\DirectoryList;
|
12 | 14 | use Magento\Framework\Config\File\ConfigFilePool;
|
| 15 | +use Magento\Framework\Exception\FileSystemException; |
| 16 | +use Magento\Framework\Filesystem; |
| 17 | +use Magento\Framework\Filesystem\Directory\ReadInterface; |
| 18 | +use Magento\Framework\Filesystem\Directory\WriteInterface; |
| 19 | +use Magento\Framework\Phrase; |
13 | 20 |
|
14 | 21 | class WriterTest extends \PHPUnit_Framework_TestCase
|
15 | 22 | {
|
16 |
| - /** |
17 |
| - * @var Writer |
18 |
| - */ |
| 23 | + /** @var Writer */ |
19 | 24 | private $object;
|
20 | 25 |
|
21 |
| - /** |
22 |
| - * @var \PHPUnit_Framework_MockObject_MockObject |
23 |
| - */ |
| 26 | + /** @var \PHPUnit_Framework_MockObject_MockObject */ |
24 | 27 | private $reader;
|
25 | 28 |
|
26 |
| - /** |
27 |
| - * @var \PHPUnit_Framework_MockObject_MockObject |
28 |
| - */ |
| 29 | + /** @var \PHPUnit_Framework_MockObject_MockObject */ |
29 | 30 | private $dirWrite;
|
30 | 31 |
|
31 |
| - /** |
32 |
| - * @var \PHPUnit_Framework_MockObject_MockObject |
33 |
| - */ |
| 32 | + /** @var \PHPUnit_Framework_MockObject_MockObject */ |
34 | 33 | private $dirRead;
|
35 | 34 |
|
36 |
| - /** |
37 |
| - * @var \PHPUnit_Framework_MockObject_MockObject |
38 |
| - */ |
| 35 | + /** @var \PHPUnit_Framework_MockObject_MockObject */ |
39 | 36 | protected $formatter;
|
40 | 37 |
|
41 |
| - /** |
42 |
| - * @var ConfigFilePool |
43 |
| - */ |
| 38 | + /** @var ConfigFilePool */ |
44 | 39 | private $configFilePool;
|
45 | 40 |
|
46 |
| - /** |
47 |
| - * @var DeploymentConfig |
48 |
| - */ |
| 41 | + /** @var DeploymentConfig */ |
49 | 42 | private $deploymentConfig;
|
50 | 43 |
|
| 44 | + /** @var Filesystem */ |
| 45 | + private $filesystem; |
| 46 | + |
51 | 47 | protected function setUp()
|
52 | 48 | {
|
53 |
| - $this->reader = $this->getMock('Magento\Framework\App\DeploymentConfig\Reader', [], [], '', false); |
54 |
| - $filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false); |
55 |
| - $this->formatter = $this->getMockForAbstractClass( |
56 |
| - 'Magento\Framework\App\DeploymentConfig\Writer\FormatterInterface' |
57 |
| - ); |
58 |
| - $this->configFilePool = $this->getMock('Magento\Framework\Config\File\ConfigFilePool', [], [], '', false); |
59 |
| - $this->deploymentConfig = $this->getMock('Magento\Framework\App\DeploymentConfig', [], [], '', false); |
| 49 | + $this->reader = $this->getMock(Reader::class, [], [], '', false); |
| 50 | + $this->filesystem = $this->getMock(Filesystem::class, [], [], '', false); |
| 51 | + $this->formatter = $this->getMockForAbstractClass(FormatterInterface::class); |
| 52 | + $this->configFilePool = $this->getMock(ConfigFilePool::class, [], [], '', false); |
| 53 | + $this->deploymentConfig = $this->getMock(DeploymentConfig::class, [], [], '', false); |
60 | 54 | $this->object = new Writer(
|
61 | 55 | $this->reader,
|
62 |
| - $filesystem, |
| 56 | + $this->filesystem, |
63 | 57 | $this->configFilePool,
|
64 | 58 | $this->deploymentConfig,
|
65 | 59 | $this->formatter
|
66 | 60 | );
|
67 | 61 | $this->reader->expects($this->any())->method('getFiles')->willReturn('test.php');
|
68 |
| - $this->dirWrite = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\WriteInterface'); |
69 |
| - $this->dirRead = $this->getMockForAbstractClass('Magento\Framework\Filesystem\Directory\ReadInterface'); |
| 62 | + $this->dirWrite = $this->getMockForAbstractClass(WriteInterface::class); |
| 63 | + $this->dirRead = $this->getMockForAbstractClass(ReadInterface::class); |
70 | 64 | $this->dirRead->expects($this->any())
|
71 | 65 | ->method('getAbsolutePath');
|
72 |
| - $filesystem->expects($this->any()) |
| 66 | + $this->filesystem->expects($this->any()) |
73 | 67 | ->method('getDirectoryWrite')
|
74 | 68 | ->with(DirectoryList::CONFIG)
|
75 | 69 | ->willReturn($this->dirWrite);
|
76 |
| - $filesystem->expects($this->any()) |
| 70 | + $this->filesystem->expects($this->any()) |
77 | 71 | ->method('getDirectoryRead')
|
78 | 72 | ->with(DirectoryList::CONFIG)
|
79 | 73 | ->willReturn($this->dirRead);
|
@@ -179,4 +173,16 @@ public function testSaveConfigOverride()
|
179 | 173 |
|
180 | 174 | $this->object->saveConfig($testSetUpdate, true);
|
181 | 175 | }
|
| 176 | + |
| 177 | + /** |
| 178 | + * @expectedException \Magento\Framework\Exception\FileSystemException |
| 179 | + * @expectedExceptionMessage Deployment config file env.php is not writable. |
| 180 | + */ |
| 181 | + public function testSaveConfigException() |
| 182 | + { |
| 183 | + $this->configFilePool->method('getPaths')->willReturn([ConfigFilePool::APP_ENV => 'env.php']); |
| 184 | + $exception = new FileSystemException(new Phrase('error when writing file config file')); |
| 185 | + $this->dirWrite->method('writeFile')->willThrowException($exception); |
| 186 | + $this->object->saveConfig([ConfigFilePool::APP_ENV => ['key' => 'value']]); |
| 187 | + } |
182 | 188 | }
|
0 commit comments