55 */
66namespace Magento \Deploy \Test \Unit \Model ;
77
8+ use Magento \Config \Console \Command \ConfigSet \ProcessorFacadeFactory ;
9+ use Magento \Config \Console \Command \ConfigSet \ProcessorFacade ;
10+ use Magento \Config \Console \Command \EmulatedAdminhtmlAreaProcessor ;
11+ use Magento \Deploy \App \Mode \ConfigProvider ;
812use Magento \Deploy \Model \Filesystem ;
913use Magento \Deploy \Model \Mode ;
14+ use Magento \Framework \App \Config \ScopeConfigInterface ;
1015use Magento \Framework \App \DeploymentConfig \Reader ;
1116use Magento \Framework \App \DeploymentConfig \Writer ;
1217use Magento \Framework \App \MaintenanceMode ;
1924
2025/**
2126 * @inheritdoc
27+ * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2228 */
2329class ModeTest extends \PHPUnit \Framework \TestCase
2430{
@@ -57,6 +63,26 @@ class ModeTest extends \PHPUnit\Framework\TestCase
5763 */
5864 private $ filesystemMock ;
5965
66+ /**
67+ * @var ConfigProvider|Mock
68+ */
69+ private $ configProvider ;
70+
71+ /**
72+ * @var ProcessorFacadeFactory|Mock
73+ */
74+ private $ processorFacadeFactory ;
75+
76+ /**
77+ * @var ProcessorFacade|Mock
78+ */
79+ private $ processorFacade ;
80+
81+ /**
82+ * @var EmulatedAdminhtmlAreaProcessor|Mock
83+ */
84+ private $ emulatedAreaProcessor ;
85+
6086 protected function setUp ()
6187 {
6288 $ this ->inputMock = $ this ->getMockBuilder (InputInterface::class)
@@ -75,14 +101,30 @@ protected function setUp()
75101 $ this ->filesystemMock = $ this ->getMockBuilder (Filesystem::class)
76102 ->disableOriginalConstructor ()
77103 ->getMock ();
104+ $ this ->configProvider = $ this ->getMockBuilder (ConfigProvider::class)
105+ ->disableOriginalConstructor ()
106+ ->getMock ();
107+ $ this ->processorFacadeFactory = $ this ->getMockBuilder (ProcessorFacadeFactory::class)
108+ ->disableOriginalConstructor ()
109+ ->setMethods (['create ' ])
110+ ->getMockForAbstractClass ();
111+ $ this ->processorFacade = $ this ->getMockBuilder (ProcessorFacade::class)
112+ ->disableOriginalConstructor ()
113+ ->getMock ();
114+ $ this ->emulatedAreaProcessor = $ this ->getMockBuilder (EmulatedAdminhtmlAreaProcessor::class)
115+ ->disableOriginalConstructor ()
116+ ->getMock ();
78117
79118 $ this ->model = new Mode (
80119 $ this ->inputMock ,
81120 $ this ->outputMock ,
82121 $ this ->writerMock ,
83122 $ this ->readerMock ,
84123 $ this ->maintenanceMock ,
85- $ this ->filesystemMock
124+ $ this ->filesystemMock ,
125+ $ this ->configProvider ,
126+ $ this ->processorFacadeFactory ,
127+ $ this ->emulatedAreaProcessor
86128 );
87129 }
88130
@@ -112,6 +154,9 @@ public function testEnableProductionMode()
112154 State::PARAM_MODE => State::MODE_DEVELOPER ,
113155 ],
114156 ];
157+ $ this ->configProvider ->expects ($ this ->any ())
158+ ->method ('getConfigs ' )
159+ ->willReturn ([]);
115160 $ this ->writerMock ->expects ($ this ->once ())
116161 ->method ("saveConfig " )
117162 ->willReturnCallback (function ($ data ) use (&$ dataStorage ) {
@@ -145,6 +190,12 @@ public function testEnableDeveloperModeOnFail()
145190 State::PARAM_MODE => State::MODE_DEVELOPER ,
146191 ],
147192 ];
193+ $ this ->readerMock ->expects ($ this ->any ())
194+ ->method ('load ' )
195+ ->willReturn ([State::PARAM_MODE => State::MODE_DEVELOPER ]);
196+ $ this ->configProvider ->expects ($ this ->any ())
197+ ->method ('getConfigs ' )
198+ ->willReturn ([]);
148199 $ this ->writerMock ->expects ($ this ->exactly (2 ))
149200 ->method ("saveConfig " )
150201 ->withConsecutive (
@@ -165,4 +216,41 @@ public function testEnableDeveloperModeOnFail()
165216 $ this ->model ->enableProductionMode ();
166217 $ this ->assertEquals (State::MODE_PRODUCTION , $ mode );
167218 }
219+
220+ public function testEnableProductionModeMinimal ()
221+ {
222+ $ this ->readerMock ->expects ($ this ->once ())
223+ ->method ('load ' )
224+ ->willReturn ([State::PARAM_MODE => State::MODE_DEVELOPER ]);
225+ $ this ->configProvider ->expects ($ this ->once ())
226+ ->method ('getConfigs ' )
227+ ->with ('developer ' , 'production ' )
228+ ->willReturn ([
229+ 'dev/debug/debug_logging ' => 0
230+ ]);
231+ $ this ->emulatedAreaProcessor ->expects ($ this ->once ())
232+ ->method ('process ' )
233+ ->willReturnCallback (function (\Closure $ closure ) {
234+ return $ closure ->call ($ this ->model );
235+ });
236+
237+ $ this ->processorFacadeFactory ->expects ($ this ->once ())
238+ ->method ('create ' )
239+ ->willReturn ($ this ->processorFacade );
240+ $ this ->processorFacade
241+ ->expects ($ this ->once ())
242+ ->method ('process ' )
243+ ->with (
244+ 'dev/debug/debug_logging ' ,
245+ 0 ,
246+ ScopeConfigInterface::SCOPE_TYPE_DEFAULT ,
247+ null ,
248+ true
249+ );
250+ $ this ->outputMock ->expects ($ this ->once ())
251+ ->method ('writeln ' )
252+ ->with ('Config "dev/debug/debug_logging = 0" has been saved. ' );
253+
254+ $ this ->model ->enableProductionModeMinimal ();
255+ }
168256}
0 commit comments