5
5
*/
6
6
namespace Magento \Framework \View \Test \Unit \Asset \MergeStrategy ;
7
7
8
+ use Magento \Framework \Filesystem \Directory \WriteInterface ;
8
9
use \Magento \Framework \View \Asset \MergeStrategy \Direct ;
9
10
10
11
use Magento \Framework \App \Filesystem \DirectoryList ;
@@ -22,9 +23,14 @@ class DirectTest extends \PHPUnit_Framework_TestCase
22
23
protected $ cssUrlResolver ;
23
24
24
25
/**
25
- * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Filesystem\Directory\ WriteInterface
26
+ * @var \PHPUnit_Framework_MockObject_MockObject|WriteInterface
26
27
*/
27
- protected $ writeDir ;
28
+ protected $ staticDir ;
29
+
30
+ /**
31
+ * @var \PHPUnit_Framework_MockObject_MockObject|WriteInterface
32
+ */
33
+ protected $ tmpDir ;
28
34
29
35
/**
30
36
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\Asset\LocalInterface
@@ -33,29 +39,36 @@ class DirectTest extends \PHPUnit_Framework_TestCase
33
39
34
40
protected function setUp ()
35
41
{
36
- $ this ->cssUrlResolver = $ this ->getMock ('\Magento\Framework\View\Url\CssResolver ' );
37
- $ filesystem = $ this ->getMock ('\Magento\Framework\Filesystem ' , [], [], '' , false );
38
- $ this ->writeDir = $ this ->getMockForAbstractClass ('\Magento\Framework\Filesystem\Directory\WriteInterface ' );
42
+ $ this ->cssUrlResolver = $ this ->getMock (\Magento \Framework \View \Url \CssResolver::class);
43
+ $ filesystem = $ this ->getMock (\Magento \Framework \Filesystem::class, [], [], '' , false );
44
+ $ this ->staticDir = $ this ->getMockBuilder (WriteInterface::class)->getMockForAbstractClass ();
45
+ $ this ->tmpDir = $ this ->getMockBuilder (WriteInterface::class)->getMockForAbstractClass ();
39
46
$ filesystem ->expects ($ this ->any ())
40
47
->method ('getDirectoryWrite ' )
41
- ->with (DirectoryList::STATIC_VIEW )
42
- ->will ($ this ->returnValue ($ this ->writeDir ));
43
- $ this ->resultAsset = $ this ->getMock ('\Magento\Framework\View\Asset\File ' , [], [], '' , false );
48
+ ->willReturnMap ([
49
+ [DirectoryList::STATIC_VIEW , \Magento \Framework \Filesystem \DriverPool::FILE , $ this ->staticDir ],
50
+ [DirectoryList::TMP , \Magento \Framework \Filesystem \DriverPool::FILE , $ this ->tmpDir ],
51
+ ]);
52
+ $ this ->resultAsset = $ this ->getMock (\Magento \Framework \View \Asset \File::class, [], [], '' , false );
44
53
$ this ->object = new Direct ($ filesystem , $ this ->cssUrlResolver );
45
54
}
46
55
47
56
public function testMergeNoAssets ()
48
57
{
49
58
$ this ->resultAsset ->expects ($ this ->once ())->method ('getPath ' )->will ($ this ->returnValue ('foo/result ' ));
50
- $ this ->writeDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' , '' );
59
+ $ 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 );
51
62
$ this ->object ->merge ([], $ this ->resultAsset );
52
63
}
53
64
54
65
public function testMergeGeneric ()
55
66
{
56
67
$ this ->resultAsset ->expects ($ this ->once ())->method ('getPath ' )->will ($ this ->returnValue ('foo/result ' ));
57
68
$ assets = $ this ->prepareAssetsToMerge ([' one ' , 'two ' ]); // note leading space intentionally
58
- $ this ->writeDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' , 'onetwo ' );
69
+ $ 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 );
59
72
$ this ->object ->merge ($ assets , $ this ->resultAsset );
60
73
}
61
74
@@ -73,7 +86,9 @@ public function testMergeCss()
73
86
->method ('aggregateImportDirectives ' )
74
87
->with ('12 ' )
75
88
->will ($ this ->returnValue ('1020 ' ));
76
- $ this ->writeDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' , '1020 ' );
89
+ $ 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 );
77
92
$ this ->object ->merge ($ assets , $ this ->resultAsset );
78
93
}
79
94
@@ -87,7 +102,7 @@ private function prepareAssetsToMerge(array $data)
87
102
{
88
103
$ result = [];
89
104
foreach ($ data as $ content ) {
90
- $ asset = $ this ->getMockForAbstractClass (' Magento\Framework\View\Asset\LocalInterface ' );
105
+ $ asset = $ this ->getMockForAbstractClass (\ Magento \Framework \View \Asset \LocalInterface::class );
91
106
$ asset ->expects ($ this ->once ())->method ('getContent ' )->will ($ this ->returnValue ($ content ));
92
107
$ result [] = $ asset ;
93
108
}
0 commit comments