11 use Psr\Log\LoggerInterface;
30 private $mergeStrategy;
50 private $versionStorage;
54 $this->assetJsOne = $this->getMockForAbstractClass(MergeableInterface::class);
55 $this->assetJsOne->expects($this->any())
56 ->method(
'getContentType')
58 $this->assetJsOne->expects($this->any())
60 ->willReturn(
'script_one.js');
62 $this->assetJsTwo = $this->getMockForAbstractClass(MergeableInterface::class);
63 $this->assetJsTwo->expects($this->any())
64 ->method(
'getContentType')
66 $this->assetJsTwo->expects($this->any())
68 ->willReturn(
'script_two.js');
70 $this->logger = $this->createMock(LoggerInterface::class);
71 $this->mergeStrategy = $this->createMock(MergeStrategyInterface::class);
72 $this->assetRepo = $this->getMockBuilder(AssetRepository::class)
73 ->disableOriginalConstructor()
75 $this->versionStorage = $this->createMock(StorageInterface::class);
84 new \Magento\Framework\View\Asset\Merged(
99 $assetUrl = new \Magento\Framework\View\Asset\Remote(
'http://example.com/style.css',
'css');
102 'logger' => $this->logger,
103 'mergeStrategy' => $this->mergeStrategy,
104 'assetRepo' => $this->assetRepo,
105 'assets' => [$this->assetJsOne, $assetUrl],
106 'versionStorage' => $this->versionStorage,
116 $assetCss = $this->getMockForAbstractClass(MergeableInterface::class);
117 $assetCss->expects($this->any())
118 ->method(
'getContentType')
122 'logger' => $this->logger,
123 'mergeStrategy' => $this->mergeStrategy,
124 'assetRepo' => $this->assetRepo,
125 'assets' => [$this->assetJsOne, $assetCss],
126 'versionStorage' => $this->versionStorage,
130 public function testIteratorInterfaceMerge()
132 $assets = [$this->assetJsOne, $this->assetJsTwo];
134 $this->logger->expects($this->never())->method(
'critical');
137 $merged = (
new ObjectManager($this))->getObject(Merged::class, [
138 'logger' => $this->logger,
139 'mergeStrategy' => $this->mergeStrategy,
140 'assetRepo' => $this->assetRepo,
142 'versionStorage' => $this->versionStorage,
145 $mergedAsset = $this->createMock(\
Magento\Framework\View\
Asset\File::class);
147 ->expects($this->once())
149 ->with($assets, $mergedAsset)
151 $this->assetRepo->expects($this->once())
152 ->method(
'createArbitrary')
153 ->willReturn($mergedAsset);
154 $expectedResult = [$mergedAsset];
160 public function testIteratorInterfaceMergeFailure()
162 $mergeError = new \Exception(
'File not found');
163 $assetBroken = $this->getMockForAbstractClass(MergeableInterface::class);
164 $assetBroken->expects($this->any())
165 ->method(
'getContentType')
167 $assetBroken->expects($this->any())
169 ->willThrowException($mergeError);
172 $merged = (
new ObjectManager($this))->getObject(Merged::class, [
173 'logger' => $this->logger,
174 'mergeStrategy' => $this->mergeStrategy,
175 'assetRepo' => $this->assetRepo,
176 'assets' => [$this->assetJsOne, $this->assetJsTwo, $assetBroken],
177 'versionStorage' => $this->versionStorage,
180 $this->logger->expects($this->once())->method(
'critical')->with($this->identicalTo($mergeError));
182 $expectedResult = [$this->assetJsOne, $this->assetJsTwo, $assetBroken];
196 foreach ($actual as $actualItem) {
197 $actualItems[] = $actualItem;
199 $this->assertEquals($expectedItems, $actualItems);
assertIteratorEquals(array $expectedItems, \Iterator $actual)
testConstructorIncompatibleContentTypes()
testConstructorRequireMergeInterface()
testConstructorNothingToMerge()