public function testProcessException() { $chain = new \Magento\Framework\View\Asset\PreProcessor\Chain($this->asset, '//@magento_import "some/file.css";', 'css', 'path'); $exception = new \LogicException('Error happened'); $this->assetRepo->expects($this->once())->method('createRelated')->will($this->throwException($exception)); $this->errorHandler->expects($this->once())->method('processException')->with($exception); $this->object->process($chain); $this->assertEquals('', $chain->getContent()); $this->assertEquals('css', $chain->getContentType()); }
/** * Replace @magento_import to @import instructions * * @param array $matchedContent * @param LocalInterface $asset * @return string */ protected function replace(array $matchedContent, LocalInterface $asset) { $importsContent = ''; try { $matchedFileId = $matchedContent['path']; $isReference = !empty($matchedContent['reference']); $relatedAsset = $this->assetRepo->createRelated($matchedFileId, $asset); $resolvedPath = $relatedAsset->getFilePath(); $importFiles = $this->fileSource->getFiles($this->getTheme($relatedAsset), $resolvedPath); /** @var $importFile \Magento\Framework\View\File */ foreach ($importFiles as $importFile) { $referenceString = $isReference ? '(reference) ' : ''; $importsContent .= $importFile->getModule() ? "@import {$referenceString}'{$importFile->getModule()}::{$resolvedPath}';\n" : "@import {$referenceString}'{$matchedFileId}';\n"; } } catch (\LogicException $e) { $this->errorHandler->processException($e); } return $importsContent; }