|
14 | 14 | use PHPUnit_Framework_MockObject_MockObject as Mock;
|
15 | 15 | use Symfony\Component\Console\Input\InputInterface;
|
16 | 16 | use Symfony\Component\Console\Output\OutputInterface;
|
| 17 | +use Magento\Framework\Config\File\ConfigFilePool; |
| 18 | +use Magento\Framework\Exception\LocalizedException; |
17 | 19 |
|
18 | 20 | /**
|
19 | 21 | * @inheritdoc
|
@@ -96,4 +98,72 @@ public function testGetMode()
|
96 | 98 | $this->assertSame(null, $this->model->getMode());
|
97 | 99 | $this->assertSame(State::MODE_DEVELOPER, $this->model->getMode());
|
98 | 100 | }
|
| 101 | + |
| 102 | + /** |
| 103 | + * Test that production mode will be enabled before static generation call. |
| 104 | + * We need this to be sure that "min" files will be generated. |
| 105 | + */ |
| 106 | + public function testEnableProductionMode() |
| 107 | + { |
| 108 | + $mode = State::MODE_DEVELOPER; |
| 109 | + $modeModel = $this->model; |
| 110 | + $dataStorage = [ |
| 111 | + ConfigFilePool::APP_ENV => [ |
| 112 | + State::PARAM_MODE => State::MODE_DEVELOPER, |
| 113 | + ], |
| 114 | + ]; |
| 115 | + $this->writerMock->expects($this->once()) |
| 116 | + ->method("saveConfig") |
| 117 | + ->willReturnCallback(function($data) use (&$dataStorage){ |
| 118 | + $dataStorage = $data; |
| 119 | + }); |
| 120 | + $this->readerMock->expects($this->any()) |
| 121 | + ->method('load') |
| 122 | + ->willReturnCallback(function() use (&$dataStorage){ |
| 123 | + return $dataStorage[ConfigFilePool::APP_ENV]; |
| 124 | + }); |
| 125 | + $this->filesystemMock->expects($this->once()) |
| 126 | + ->method("regenerateStatic") |
| 127 | + ->willReturnCallback(function() use (&$modeModel, &$mode){ |
| 128 | + $mode = $modeModel->getMode(); |
| 129 | + }); |
| 130 | + $this->model->enableProductionMode(); |
| 131 | + $this->assertEquals(State::MODE_PRODUCTION, $mode); |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * Test that previous mode will be enabled after error during static generation call. |
| 136 | + * We need this to be sure that mode will be reverted to it previous tate. |
| 137 | + * |
| 138 | + * @expectedException \Magento\Framework\Exception\LocalizedException |
| 139 | + */ |
| 140 | + public function testEnableDeveloperModeOnFail() |
| 141 | + { |
| 142 | + $mode = State::MODE_DEVELOPER; |
| 143 | + $modeModel = $this->model; |
| 144 | + $dataStorage = [ |
| 145 | + ConfigFilePool::APP_ENV => [ |
| 146 | + State::PARAM_MODE => State::MODE_DEVELOPER, |
| 147 | + ], |
| 148 | + ]; |
| 149 | + $this->writerMock->expects($this->exactly(2)) |
| 150 | + ->method("saveConfig") |
| 151 | + ->withConsecutive( |
| 152 | + [$this->equalTo([ConfigFilePool::APP_ENV => [State::PARAM_MODE => State::MODE_PRODUCTION]])], |
| 153 | + [$this->equalTo([ConfigFilePool::APP_ENV => [State::PARAM_MODE => State::MODE_DEVELOPER]])] |
| 154 | + ) |
| 155 | + ->willReturnCallback(function($data) use (&$dataStorage){ |
| 156 | + $dataStorage = $data; |
| 157 | + }); |
| 158 | + $this->readerMock->expects($this->any()) |
| 159 | + ->method('load') |
| 160 | + ->willReturnCallback(function() use (&$dataStorage){ |
| 161 | + return $dataStorage[ConfigFilePool::APP_ENV]; |
| 162 | + }); |
| 163 | + $this->filesystemMock->expects($this->once()) |
| 164 | + ->method("regenerateStatic") |
| 165 | + ->willThrowException(new LocalizedException(__('Exception'))); |
| 166 | + $this->model->enableProductionMode(); |
| 167 | + $this->assertEquals(State::MODE_PRODUCTION, $mode); |
| 168 | + } |
99 | 169 | }
|
0 commit comments