12
12
13
13
class DirectTest extends \PHPUnit \Framework \TestCase
14
14
{
15
+ /**
16
+ * @var \Magento\Framework\Math\Random|\PHPUnit_Framework_MockObject_MockObject
17
+ */
18
+ protected $ mathRandomMock ;
15
19
/**
16
20
* @var \Magento\Framework\View\Asset\MergeStrategy\Direct
17
21
*/
@@ -50,30 +54,42 @@ protected function setUp()
50
54
[DirectoryList::TMP , \Magento \Framework \Filesystem \DriverPool::FILE , $ this ->tmpDir ],
51
55
]);
52
56
$ this ->resultAsset = $ this ->createMock (\Magento \Framework \View \Asset \File::class);
53
- $ this ->object = new Direct ($ filesystem , $ this ->cssUrlResolver );
57
+ $ this ->mathRandomMock = $ this ->getMockBuilder (\Magento \Framework \Math \Random::class)
58
+ ->disableOriginalConstructor ()
59
+ ->getMock ();
60
+ $ this ->object = new Direct ($ filesystem , $ this ->cssUrlResolver , $ this ->mathRandomMock );
54
61
}
55
62
56
63
public function testMergeNoAssets ()
57
64
{
65
+ $ uniqId = '_b3bf82fa6e140594420fa90982a8e877 ' ;
58
66
$ this ->resultAsset ->expects ($ this ->once ())->method ('getPath ' )->will ($ this ->returnValue ('foo/result ' ));
59
67
$ this ->staticDir ->expects ($ this ->never ())->method ('writeFile ' );
60
- $ this ->tmpDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' , '' );
61
- $ this ->tmpDir ->expects ($ this ->once ())->method ('renameFile ' )->with ('foo/result ' , 'foo/result ' , $ this ->staticDir );
68
+ $ this ->mathRandomMock ->expects ($ this ->once ())
69
+ ->method ('getUniqueHash ' )
70
+ ->willReturn ($ uniqId );
71
+ $ this ->tmpDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' . $ uniqId , '' );
72
+ $ this ->tmpDir ->expects ($ this ->once ())->method ('renameFile ' )->with ('foo/result ' . $ uniqId , 'foo/result ' , $ this ->staticDir );
62
73
$ this ->object ->merge ([], $ this ->resultAsset );
63
74
}
64
75
65
76
public function testMergeGeneric ()
66
77
{
78
+ $ uniqId = '_be50ccf992fd81818c1a2645d1a29e92 ' ;
67
79
$ this ->resultAsset ->expects ($ this ->once ())->method ('getPath ' )->will ($ this ->returnValue ('foo/result ' ));
68
80
$ assets = $ this ->prepareAssetsToMerge ([' one ' , 'two ' ]); // note leading space intentionally
69
81
$ this ->staticDir ->expects ($ this ->never ())->method ('writeFile ' );
70
- $ this ->tmpDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' , 'onetwo ' );
71
- $ this ->tmpDir ->expects ($ this ->once ())->method ('renameFile ' )->with ('foo/result ' , 'foo/result ' , $ this ->staticDir );
82
+ $ this ->mathRandomMock ->expects ($ this ->once ())
83
+ ->method ('getUniqueHash ' )
84
+ ->willReturn ($ uniqId );
85
+ $ this ->tmpDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' . $ uniqId , 'onetwo ' );
86
+ $ this ->tmpDir ->expects ($ this ->once ())->method ('renameFile ' )->with ('foo/result ' . $ uniqId , 'foo/result ' , $ this ->staticDir );
72
87
$ this ->object ->merge ($ assets , $ this ->resultAsset );
73
88
}
74
89
75
90
public function testMergeCss ()
76
91
{
92
+ $ uniqId = '_f929c374767e00712449660ea673f2f5 ' ;
77
93
$ this ->resultAsset ->expects ($ this ->exactly (3 ))
78
94
->method ('getPath ' )
79
95
->will ($ this ->returnValue ('foo/result ' ));
@@ -86,9 +102,12 @@ public function testMergeCss()
86
102
->method ('aggregateImportDirectives ' )
87
103
->with ('12 ' )
88
104
->will ($ this ->returnValue ('1020 ' ));
105
+ $ this ->mathRandomMock ->expects ($ this ->once ())
106
+ ->method ('getUniqueHash ' )
107
+ ->willReturn ($ uniqId );
89
108
$ this ->staticDir ->expects ($ this ->never ())->method ('writeFile ' );
90
- $ this ->tmpDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' , '1020 ' );
91
- $ this ->tmpDir ->expects ($ this ->once ())->method ('renameFile ' )->with ('foo/result ' , 'foo/result ' , $ this ->staticDir );
109
+ $ this ->tmpDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' . $ uniqId , '1020 ' );
110
+ $ this ->tmpDir ->expects ($ this ->once ())->method ('renameFile ' )->with ('foo/result ' . $ uniqId , 'foo/result ' , $ this ->staticDir );
92
111
$ this ->object ->merge ($ assets , $ this ->resultAsset );
93
112
}
94
113
0 commit comments