21 use Psr\Log\LoggerInterface;
22 use PHPUnit_Framework_MockObject_MockObject as MockObject;
37 private $responseMock;
47 private $publisherMock;
52 private $assetRepoMock;
57 private $moduleListMock;
62 private $objectManagerMock;
67 private $configLoaderMock;
77 private $deploymentConfigMock;
86 $this->stateMock = $this->createMock(State::class);
87 $this->responseMock = $this->getMockForAbstractClass(FileInterface::class);
88 $this->requestMock = $this->createMock(HttpRequest::class);
89 $this->publisherMock = $this->createMock(Publisher::class);
90 $this->assetRepoMock = $this->createMock(Repository::class);
91 $this->moduleListMock = $this->createMock(ModuleList::class);
92 $this->objectManagerMock = $this->getMockForAbstractClass(ObjectManagerInterface::class);
93 $this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
94 $this->configLoaderMock = $this->createMock(ConfigLoader::class);
95 $this->deploymentConfigMock = $this->createMock(DeploymentConfig::class);
100 $this->publisherMock,
101 $this->assetRepoMock,
102 $this->moduleListMock,
103 $this->objectManagerMock,
104 $this->configLoaderMock,
105 $this->deploymentConfigMock
111 $this->stateMock->expects($this->once())
114 $this->responseMock->expects($this->once())
115 ->method(
'setHttpResponseCode')
117 $this->responseMock->expects($this->never())
118 ->method(
'setFilePath');
119 $this->stateMock->expects($this->never())->method(
'setAreaCode');
120 $this->configLoaderMock->expects($this->never())->method(
'load');
121 $this->objectManagerMock->expects($this->never())->method(
'configure');
122 $this->requestMock->expects($this->never())->method(
'get');
123 $this->moduleListMock->expects($this->never())->method(
'has');
124 $asset = $this->getMockForAbstractClass(\
Magento\Framework\
View\Asset\LocalInterface::class);
125 $asset->expects($this->never())->method(
'getSourceFile');
126 $this->assetRepoMock->expects($this->never())->method(
'createAsset');
127 $this->publisherMock->expects($this->never())->method(
'publish');
128 $this->responseMock->expects($this->never())->method(
'setFilePath');
129 $this->
object->launch();
150 array $expectedParams,
151 $getConfigDataExpects,
152 $staticContentOmDemandInProduction
154 $this->deploymentConfigMock->expects($this->exactly($getConfigDataExpects))
155 ->method(
'getConfigData')
157 ->willReturn($staticContentOmDemandInProduction);
158 $this->stateMock->expects($this->once())
161 $this->stateMock->expects($this->once())
162 ->method(
'setAreaCode')
164 $this->configLoaderMock->expects($this->once())
167 ->willReturn([
'config']);
168 $this->objectManagerMock->expects($this->once())
169 ->method(
'configure')
171 $this->requestMock->expects($this->once())
174 ->willReturn($requestedPath);
175 $this->moduleListMock->expects($this->any())
177 ->with($requestedModule)
178 ->willReturn($moduleExists);
179 $asset = $this->getMockForAbstractClass(\
Magento\Framework\
View\Asset\LocalInterface::class);
180 $asset->expects($this->once())
181 ->method(
'getSourceFile')
182 ->willReturn(
'resource/file.css');
183 $this->assetRepoMock->expects($this->once())
184 ->method(
'createAsset')
185 ->with($expectedFile, $expectedParams)
186 ->willReturn($asset);
187 $this->publisherMock->expects($this->once())
190 $this->responseMock->expects($this->once())
191 ->method(
'setFilePath')
192 ->with(
'resource/file.css');
193 $this->
object->launch();
202 'developer mode with non-modular resource' => [
204 'area/Magento/theme/locale/dir/file.js',
208 [
'area' =>
'area',
'locale' =>
'locale',
'module' =>
'',
'theme' =>
'Magento/theme'],
212 'default mode with modular resource' => [
214 'area/Magento/theme/locale/Namespace_Module/dir/file.js',
219 'area' =>
'area',
'locale' =>
'locale',
'module' =>
'Namespace_Module',
'theme' =>
'Magento/theme' 224 'production mode with static_content_on_demand_in_production and with non-modular resource' => [
226 'area/Magento/theme/locale/dir/file.js',
230 [
'area' =>
'area',
'locale' =>
'locale',
'module' =>
'',
'theme' =>
'Magento/theme'],
234 'production mode with static_content_on_demand_in_production and with modular resource' => [
236 'area/Magento/theme/locale/Namespace_Module/dir/file.js',
241 'area' =>
'area',
'locale' =>
'locale',
'module' =>
'Namespace_Module',
'theme' =>
'Magento/theme' 255 $this->stateMock->expects($this->once())
258 $this->requestMock->expects($this->once())
261 ->willReturn(
'short/path.js');
262 $this->
object->launch();
267 $this->objectManagerMock->expects($this->once())
269 ->with(\Psr\
Log\LoggerInterface::class)
270 ->willReturn($this->loggerMock);
271 $this->loggerMock->expects($this->once())
272 ->method(
'critical');
273 $bootstrap = $this->getMockBuilder(Bootstrap::class)
274 ->disableOriginalConstructor()
277 ->method(
'isDeveloperMode')
279 $exception = new \Exception(
'Error: nothing works');
280 $this->responseMock->expects($this->once())
281 ->method(
'setHttpResponseCode')
283 $this->responseMock->expects($this->once())
284 ->method(
'sendResponse');
285 $this->assertTrue($this->object->catchException(
$bootstrap, $exception));
293 $path =
'frontend/..\..\folder_above/././Magento_Ui/template/messages.html';
294 $this->stateMock->expects($this->once())
297 $this->requestMock->expects($this->once())
300 ->willReturn(
'frontend/..\..\folder_above/././Magento_Ui/template/messages.html');
301 $this->expectExceptionMessage(
"Requested path '$path' is wrong.");
303 $this->
object->launch();
testLaunchProductionMode()
const CONFIG_PATH_SCD_ON_DEMAND_IN_PRODUCTION
if(defined('TESTS_MAGENTO_INSTALLATION') &&TESTS_MAGENTO_INSTALLATION==='enabled') $bootstrap
if($exist=($block->getProductCollection() && $block->getProductCollection() ->getSize())) $mode
testLaunch( $mode, $requestedPath, $requestedModule, $moduleExists, $expectedFile, array $expectedParams, $getConfigDataExpects, $staticContentOmDemandInProduction)
testCatchExceptionDeveloperMode()