8 use Magento\Config\Console\Command\ConfigSet\ProcessorFacadeFactory;
20 use PHPUnit_Framework_MockObject_MockObject as Mock;
21 use Symfony\Component\Console\Input\InputInterface;
22 use Symfony\Component\Console\Output\OutputInterface;
30 class ModeTest extends \PHPUnit\Framework\TestCase
60 private $maintenanceMock;
65 private $filesystemMock;
70 private $configProvider;
75 private $processorFacadeFactory;
80 private $processorFacade;
85 private $emulatedAreaProcessor;
89 $this->inputMock = $this->getMockBuilder(InputInterface::class)
90 ->getMockForAbstractClass();
91 $this->outputMock = $this->getMockBuilder(OutputInterface::class)
92 ->getMockForAbstractClass();
93 $this->writerMock = $this->getMockBuilder(Writer::class)
94 ->disableOriginalConstructor()
96 $this->readerMock = $this->getMockBuilder(Reader::class)
97 ->disableOriginalConstructor()
99 $this->maintenanceMock = $this->getMockBuilder(MaintenanceMode::class)
100 ->disableOriginalConstructor()
102 $this->filesystemMock = $this->getMockBuilder(Filesystem::class)
103 ->disableOriginalConstructor()
105 $this->configProvider = $this->getMockBuilder(ConfigProvider::class)
106 ->disableOriginalConstructor()
108 $this->processorFacadeFactory = $this->getMockBuilder(ProcessorFacadeFactory::class)
109 ->disableOriginalConstructor()
110 ->setMethods([
'create'])
111 ->getMockForAbstractClass();
112 $this->processorFacade = $this->getMockBuilder(ProcessorFacade::class)
113 ->disableOriginalConstructor()
115 $this->emulatedAreaProcessor = $this->getMockBuilder(EmulatedAdminhtmlAreaProcessor::class)
116 ->disableOriginalConstructor()
119 $this->model =
new Mode(
124 $this->maintenanceMock,
125 $this->filesystemMock,
126 $this->configProvider,
127 $this->processorFacadeFactory,
128 $this->emulatedAreaProcessor,
135 $this->readerMock->expects($this->exactly(2))
137 ->willReturnOnConsecutiveCalls(
142 $this->assertSame(
null, $this->model->getMode());
153 $modeModel = $this->model;
159 $this->configProvider->expects($this->any())
160 ->method(
'getConfigs')
162 $this->writerMock->expects($this->once())
163 ->method(
"saveConfig")
164 ->willReturnCallback(
function (
$data) use (&$dataStorage) {
165 $dataStorage =
$data;
167 $this->readerMock->expects($this->any())
169 ->willReturnCallback(
function () use (&$dataStorage) {
172 $this->filesystemMock->expects($this->once())
173 ->method(
"regenerateStatic")
174 ->willReturnCallback(
function () use (&$modeModel, &
$mode) {
175 $mode = $modeModel->getMode();
177 $this->model->enableProductionMode();
195 $this->readerMock->expects($this->any())
198 $this->configProvider->expects($this->any())
199 ->method(
'getConfigs')
201 $this->writerMock->expects($this->exactly(2))
202 ->method(
"saveConfig")
207 ->willReturnCallback(
function (
$data) use (&$dataStorage) {
208 $dataStorage =
$data;
210 $this->readerMock->expects($this->any())
212 ->willReturnCallback(
function () use (&$dataStorage) {
215 $this->filesystemMock->expects($this->once())
216 ->method(
"regenerateStatic")
218 $this->model->enableProductionMode();
224 $this->readerMock->expects($this->once())
227 $this->configProvider->expects($this->once())
228 ->method(
'getConfigs')
229 ->with(
'developer',
'production')
231 'dev/debug/debug_logging' => 0,
233 $this->emulatedAreaProcessor->expects($this->once())
235 ->willReturnCallback(
function (\Closure $closure) {
236 return $closure->call($this->model);
239 $this->processorFacadeFactory->expects($this->once())
241 ->willReturn($this->processorFacade);
242 $this->processorFacade
243 ->expects($this->once())
244 ->method(
'processWithLockTarget')
246 'dev/debug/debug_logging',
252 $this->outputMock->expects($this->once())
254 ->with(
'Config "dev/debug/debug_logging = 0" has been saved.');
256 $this->model->enableProductionModeMinimal();
testEnableProductionModeMinimal()
testEnableDeveloperModeOnFail()
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
testEnableProductionMode()