8
8
use \Magento \Framework \View \Asset \MergeStrategy \Checksum ;
9
9
10
10
use Magento \Framework \App \Filesystem \DirectoryList ;
11
+ use Magento \Framework \View \Asset \Source ;
11
12
12
13
class ChecksumTest extends \PHPUnit_Framework_TestCase
13
14
{
@@ -31,17 +32,24 @@ class ChecksumTest extends \PHPUnit_Framework_TestCase
31
32
*/
32
33
private $ resultAsset ;
33
34
35
+ /**
36
+ * @var Source|\PHPUnit_Framework_MockObject_MockObject
37
+ */
38
+ private $ assetSource ;
39
+
34
40
/**
35
41
* @var \Magento\Framework\View\Asset\MergeStrategy\Checksum
36
42
*/
37
43
private $ checksum ;
38
44
39
45
protected function setUp ()
40
46
{
41
- $ this ->mergerMock = $ this ->getMockForAbstractClass ('\Magento\Framework\View\Asset\MergeStrategyInterface ' );
42
- $ this ->sourceDir = $ this ->getMockForAbstractClass ('\Magento\Framework\Filesystem\Directory\ReadInterface ' );
43
- $ this ->targetDir = $ this ->getMockForAbstractClass ('\Magento\Framework\Filesystem\Directory\WriteInterface ' );
44
- $ filesystem = $ this ->getMock ('\Magento\Framework\Filesystem ' , [], [], '' , false );
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 (
50
+ \Magento \Framework \Filesystem \Directory \WriteInterface::class
51
+ );
52
+ $ filesystem = $ this ->getMock (\Magento \Framework \Filesystem::class, [], [], '' , false );
45
53
$ filesystem ->expects ($ this ->once ())
46
54
->method ('getDirectoryRead ' )
47
55
->with (DirectoryList::ROOT )
@@ -51,7 +59,16 @@ protected function setUp()
51
59
->with (DirectoryList::STATIC_VIEW )
52
60
->will ($ this ->returnValue ($ this ->targetDir ));
53
61
$ this ->checksum = new Checksum ($ this ->mergerMock , $ filesystem );
54
- $ this ->resultAsset = $ this ->getMock ('\Magento\Framework\View\Asset\File ' , [], [], '' , false );
62
+ $ this ->assetSource = $ this ->getMockBuilder (Source::class)
63
+ ->disableOriginalConstructor ()
64
+ ->getMock ();
65
+
66
+ $ reflection = new \ReflectionClass (Checksum::class);
67
+ $ reflectionProperty = $ reflection ->getProperty ('assetSource ' );
68
+ $ reflectionProperty ->setAccessible (true );
69
+ $ reflectionProperty ->setValue ($ this ->checksum , $ this ->assetSource );
70
+
71
+ $ this ->resultAsset = $ this ->getMock (\Magento \Framework \View \Asset \File::class, [], [], '' , false );
55
72
}
56
73
57
74
public function testMergeNoAssets ()
@@ -111,10 +128,18 @@ public function testMergeMtimeUnchanged()
111
128
*/
112
129
private function getAssetsToMerge ()
113
130
{
114
- $ one = $ this ->getMock ('\Magento\Framework\View\Asset\File ' , [], [], '' , false );
115
- $ one ->expects ($ this ->once ())->method ('getSourceFile ' )->will ($ this ->returnValue ('/dir/file/one.txt ' ));
116
- $ two = $ this ->getMock ('\Magento\Framework\View\Asset\File ' , [], [], '' , false );
117
- $ two ->expects ($ this ->once ())->method ('getSourceFile ' )->will ($ this ->returnValue ('/dir/file/two.txt ' ));
131
+ $ one = $ this ->getMock (\Magento \Framework \View \Asset \File::class, [], [], '' , false );
132
+ $ two = $ this ->getMock (\Magento \Framework \View \Asset \File::class, [], [], '' , false );
133
+ $ one ->expects ($ this ->never ())
134
+ ->method ('getSourceFile ' );
135
+ $ two ->expects ($ this ->never ())
136
+ ->method ('getSourceFile ' );
137
+
138
+ $ this ->assetSource ->expects ($ this ->exactly (2 ))
139
+ ->method ('findSource ' )
140
+ ->withConsecutive ([$ one ], [$ two ])
141
+ ->willReturnOnConsecutiveCalls ('/dir/file/one.txt ' , '/dir/file/two.txt ' );
142
+
118
143
$ this ->sourceDir ->expects ($ this ->exactly (2 ))
119
144
->method ('getRelativePath ' )
120
145
->will ($ this ->onConsecutiveCalls ('file/one.txt ' , 'file/two.txt ' ));
0 commit comments