42 private $lockerProcessMock;
47 private $assetBuilderMock;
52 private $alternativeSourceMock;
57 private $assetSourceMock;
64 $this->lockerProcessMock = $this->getMockBuilder(LockerProcessInterface::class)
65 ->getMockForAbstractClass();
66 $this->assetBuilderMock = $this->getMockBuilder(AssetBuilder::class)
67 ->disableOriginalConstructor()
69 $this->alternativeSourceMock = $this->getMockBuilder(AlternativeSourceInterface::class)
70 ->getMockForAbstractClass();
71 $this->assetSourceMock = $this->getMockBuilder(Source::class)
72 ->disableOriginalConstructor()
81 $this->lockerProcessMock->expects(self::once())
82 ->method(
'lockProcess')
83 ->with(self::isType(
'string'));
84 $this->lockerProcessMock->expects(self::once())
85 ->method(
'unlockProcess');
87 $this->alternativeSourceMock->expects(self::once())
88 ->method(
'getAlternativesExtensionsNames')
89 ->willReturn([
'less']);
91 $this->assetBuilderMock->expects(self::once())
95 $this->assetBuilderMock->expects(self::once())
99 $this->assetBuilderMock->expects(self::once())
100 ->method(
'setLocale')
103 $this->assetBuilderMock->expects(self::once())
104 ->method(
'setModule')
107 $this->assetBuilderMock->expects(self::once())
109 ->with(self::FILE_PATH)
111 $this->assetBuilderMock->expects(self::once())
113 ->willThrowException(
new \Exception());
115 $this->assetSourceMock->expects(self::never())
116 ->method(
'getContent');
119 $this->assetSourceMock,
120 $this->assetBuilderMock,
121 $this->alternativeSourceMock,
122 $this->lockerProcessMock,
127 $frontendCompilation->process($this->getChainMockExpects(
'', 0, 1));
128 }
catch (\Exception $e) {
129 self::assertInstanceOf(
'\Exception', $e);
138 $newContentType =
'less';
140 $this->lockerProcessMock->expects(self::once())
141 ->method(
'lockProcess')
142 ->with(self::isType(
'string'));
143 $this->lockerProcessMock->expects(self::once())
144 ->method(
'unlockProcess');
146 $assetMock = $this->getAssetNew();
148 $this->assetBuilderMock->expects(self::once())
152 $this->assetBuilderMock->expects(self::once())
156 $this->assetBuilderMock->expects(self::once())
157 ->method(
'setLocale')
160 $this->assetBuilderMock->expects(self::once())
161 ->method(
'setModule')
164 $this->assetBuilderMock->expects(self::once())
166 ->with(self::FILE_PATH)
168 $this->assetBuilderMock->expects(self::once())
170 ->willReturn($assetMock);
172 $this->alternativeSourceMock->expects(self::once())
173 ->method(
'getAlternativesExtensionsNames')
174 ->willReturn([$newContentType]);
176 $this->assetSourceMock->expects(self::once())
177 ->method(
'getContent')
179 ->willReturn(self::NEW_CONTENT);
182 $this->assetSourceMock,
183 $this->assetBuilderMock,
184 $this->alternativeSourceMock,
185 $this->lockerProcessMock,
189 $frontendCompilation->process($this->getChainMockExpects(
'', 1, 1, $newContentType));
195 private function getChainMock()
197 $chainMock = $this->getMockBuilder(Chain::class)
198 ->disableOriginalConstructor()
211 private function getChainMockExpects(
$content =
'', $contentExactly = 1, $pathExactly = 1, $newContentType =
'')
213 $chainMock = $this->getChainMock();
215 $chainMock->expects(self::once())
216 ->method(
'getContent')
218 $chainMock->expects(self::exactly(3))
220 ->willReturn($this->getAssetMockExpects($pathExactly));
221 $chainMock->expects(self::exactly($contentExactly))
222 ->method(
'setContent')
223 ->with(self::NEW_CONTENT);
224 $chainMock->expects(self::exactly($contentExactly))
225 ->method(
'setContentType')
226 ->with($newContentType);
234 private function getAssetNew()
236 $assetMock = $this->getMockBuilder(File::class)
237 ->disableOriginalConstructor()
246 private function getAssetMock()
248 $assetMock = $this->getMockBuilder(LocalInterface::class)
249 ->disableOriginalConstructor()
259 private function getAssetMockExpects($pathExactly = 1)
261 $assetMock = $this->getAssetMock();
263 $assetMock->expects(self::once())
264 ->method(
'getContext')
265 ->willReturn($this->getContextMock());
266 $assetMock->expects(self::exactly($pathExactly))
267 ->method(
'getFilePath')
268 ->willReturn(self::FILE_PATH);
269 $assetMock->expects(self::once())
270 ->method(
'getModule')
271 ->willReturn(self::MODULE);
279 private function getContextMock()
281 $contextMock = $this->getMockBuilder(FallbackContext::class)
282 ->disableOriginalConstructor()
285 $contextMock->expects(self::once())
286 ->method(
'getAreaCode')
287 ->willReturn(self::AREA);
288 $contextMock->expects(self::once())
289 ->method(
'getThemePath')
290 ->willReturn(self::THEME);
291 $contextMock->expects(self::once())
292 ->method(
'getLocale')
293 ->willReturn(self::LOCALE);