8 use \Magento\Framework\View\Asset\MergeStrategy\Checksum;
47 $this->mergerMock = $this->getMockForAbstractClass(\
Magento\Framework\View\
Asset\MergeStrategyInterface::class);
48 $this->sourceDir = $this->getMockForAbstractClass(\
Magento\Framework\
Filesystem\Directory\ReadInterface::class);
49 $this->targetDir = $this->getMockForAbstractClass(
54 ->method(
'getDirectoryRead')
56 ->will($this->returnValue($this->sourceDir));
58 ->method(
'getDirectoryWrite')
60 ->will($this->returnValue($this->targetDir));
62 $this->assetSource = $this->getMockBuilder(Source::class)
63 ->disableOriginalConstructor()
66 $reflection = new \ReflectionClass(Checksum::class);
67 $reflectionProperty = $reflection->getProperty(
'assetSource');
68 $reflectionProperty->setAccessible(
true);
69 $reflectionProperty->setValue($this->checksum, $this->assetSource);
71 $this->resultAsset = $this->createMock(\
Magento\Framework\View\
Asset\File::class);
76 $this->mergerMock->expects($this->never())->method(
'merge');
77 $this->checksum->merge([], $this->resultAsset);
82 $this->targetDir->expects($this->once())
84 ->with(
'merged/result.txt.dat')
85 ->will($this->returnValue(
false));
86 $assets = $this->getAssetsToMerge();
87 $this->mergerMock->expects($this->once())->method(
'merge')->with($assets, $this->resultAsset);
88 $this->targetDir->expects($this->once())->method(
'writeFile')->with(
'merged/result.txt.dat',
'11');
89 $this->checksum->merge($assets, $this->resultAsset);
94 $this->targetDir->expects($this->once())
96 ->with(
'merged/result.txt.dat')
97 ->will($this->returnValue(
true));
98 $this->targetDir->expects($this->once())
100 ->with(
'merged/result.txt.dat')
101 ->will($this->returnValue(
'10'));
102 $assets = $this->getAssetsToMerge();
103 $this->mergerMock->expects($this->once())->method(
'merge')->with($assets, $this->resultAsset);
104 $this->targetDir->expects($this->once())->method(
'writeFile')->with(
'merged/result.txt.dat',
'11');
105 $this->checksum->merge($assets, $this->resultAsset);
110 $this->targetDir->expects($this->once())
112 ->with(
'merged/result.txt.dat')
113 ->will($this->returnValue(
true));
114 $this->targetDir->expects($this->once())
116 ->with(
'merged/result.txt.dat')
117 ->will($this->returnValue(
'11'));
118 $assets = $this->getAssetsToMerge();
119 $this->mergerMock->expects($this->never())->method(
'merge');
120 $this->targetDir->expects($this->never())->method(
'writeFile');
121 $this->checksum->merge($assets, $this->resultAsset);
129 private function getAssetsToMerge()
131 $one = $this->createMock(\
Magento\Framework\View\
Asset\File::class);
132 $two = $this->createMock(\
Magento\Framework\View\
Asset\File::class);
133 $one->expects($this->never())
134 ->method(
'getSourceFile');
135 $two->expects($this->never())
136 ->method(
'getSourceFile');
138 $this->assetSource->expects($this->exactly(2))
139 ->method(
'findSource')
140 ->withConsecutive([$one], [$two])
141 ->willReturnOnConsecutiveCalls(
'/dir/file/one.txt',
'/dir/file/two.txt');
143 $this->sourceDir->expects($this->exactly(2))
144 ->method(
'getRelativePath')
145 ->will($this->onConsecutiveCalls(
'file/one.txt',
'file/two.txt'));
146 $this->sourceDir->expects($this->exactly(2))->method(
'stat')->will($this->returnValue([
'mtime' =>
'1']));
147 $this->resultAsset->expects($this->once())
149 ->will($this->returnValue(
'merged/result.txt'));
testMergeMtimeUnchanged()