2424 */
2525class DirectTest extends TestCase
2626{
27- /**
28- * @var Random|MockObject
29- */
30- protected $ mathRandomMock ;
3127 /**
3228 * @var Direct
3329 */
34- protected $ object ;
30+ private $ model ;
3531
3632 /**
37- * @var MockObject|CssResolver
33+ * @var Random|MockObject
3834 */
39- protected $ cssUrlResolver ;
35+ private $ mathRandomMock ;
4036
4137 /**
42- * @var MockObject|WriteInterface
38+ * @var MockObject|CssResolver
4339 */
44- protected $ staticDir ;
40+ private $ cssUrlResolverMock ;
4541
4642 /**
4743 * @var MockObject|WriteInterface
4844 */
49- protected $ tmpDir ;
45+ private $ staticDirMock ;
5046
5147 /**
5248 * @var MockObject|LocalInterface
5349 */
54- protected $ resultAsset ;
50+ private $ resultAssetMock ;
5551
52+ /**
53+ * @inheridoc
54+ */
5655 protected function setUp (): void
5756 {
58- $ this ->cssUrlResolver = $ this ->createMock (CssResolver::class);
59- $ filesystem = $ this ->createMock (Filesystem::class);
60- $ this ->staticDir = $ this ->getMockBuilder (WriteInterface::class)
61- ->getMockForAbstractClass ();
62- $ this ->tmpDir = $ this ->getMockBuilder (WriteInterface::class)
63- ->getMockForAbstractClass ();
64- $ filesystem ->expects ($ this ->any ())
57+ $ this ->cssUrlResolverMock = $ this ->createMock (CssResolver::class);
58+ $ this ->staticDirMock = $ this ->getMockForAbstractClass (WriteInterface::class);
59+ $ tmpDir = $ this ->getMockForAbstractClass (WriteInterface::class);
60+
61+ $ filesystemMock = $ this ->createMock (Filesystem::class);
62+ $ filesystemMock ->expects ($ this ->any ())
6563 ->method ('getDirectoryWrite ' )
6664 ->willReturnMap ([
67- [DirectoryList::STATIC_VIEW , DriverPool::FILE , $ this ->staticDir ],
68- [DirectoryList::TMP , DriverPool::FILE , $ this -> tmpDir ],
65+ [DirectoryList::STATIC_VIEW , DriverPool::FILE , $ this ->staticDirMock ],
66+ [DirectoryList::TMP , DriverPool::FILE , $ tmpDir ],
6967 ]);
70- $ this ->resultAsset = $ this ->createMock (File::class);
71- $ this ->mathRandomMock = $ this ->getMockBuilder (Random::class)
72- ->disableOriginalConstructor ()
73- ->getMock ();
74- $ this ->object = new Direct ($ filesystem , $ this ->cssUrlResolver , $ this ->mathRandomMock );
68+
69+ $ this ->resultAssetMock = $ this ->createMock (File::class);
70+ $ this ->mathRandomMock = $ this ->createMock (Random::class);
71+ $ this ->model = new Direct ($ filesystemMock , $ this ->cssUrlResolverMock , $ this ->mathRandomMock );
7572 }
7673
7774 public function testMergeNoAssets ()
7875 {
7976 $ uniqId = '_b3bf82fa6e140594420fa90982a8e877 ' ;
80- $ this ->resultAsset ->expects ($ this ->once ())->method ('getPath ' )->willReturn ('foo/result ' );
81- $ this ->staticDir ->expects ($ this ->never ())->method ('writeFile ' );
77+ $ this ->resultAssetMock ->expects ($ this ->once ())
78+ ->method ('getPath ' )
79+ ->willReturn ('foo/result ' );
8280 $ this ->mathRandomMock ->expects ($ this ->once ())
8381 ->method ('getUniqueHash ' )
8482 ->willReturn ($ uniqId );
85- $ this ->tmpDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' . $ uniqId , '' );
86- $ this ->tmpDir ->expects ($ this ->once ())->method ('renameFile ' )
87- ->with ('foo/result ' . $ uniqId , 'foo/result ' , $ this ->staticDir );
88- $ this ->object ->merge ([], $ this ->resultAsset );
83+ $ this ->staticDirMock ->expects ($ this ->once ())
84+ ->method ('writeFile ' )
85+ ->with ('foo/result ' . $ uniqId , '' );
86+ $ this ->staticDirMock ->expects ($ this ->once ())
87+ ->method ('renameFile ' )
88+ ->with ('foo/result ' . $ uniqId , 'foo/result ' , $ this ->staticDirMock );
89+
90+ $ this ->model ->merge ([], $ this ->resultAssetMock );
8991 }
9092
9193 public function testMergeGeneric ()
9294 {
9395 $ uniqId = '_be50ccf992fd81818c1a2645d1a29e92 ' ;
94- $ this ->resultAsset ->expects ($ this ->once ())->method ('getPath ' )->willReturn ('foo/result ' );
9596 $ assets = $ this ->prepareAssetsToMerge ([' one ' , 'two ' ]); // note leading space intentionally
96- $ this ->staticDir ->expects ($ this ->never ())->method ('writeFile ' );
97+
98+ $ this ->resultAssetMock ->expects ($ this ->once ())
99+ ->method ('getPath ' )
100+ ->willReturn ('foo/result ' );
101+
97102 $ this ->mathRandomMock ->expects ($ this ->once ())
98103 ->method ('getUniqueHash ' )
99104 ->willReturn ($ uniqId );
100- $ this ->tmpDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' . $ uniqId , 'onetwo ' );
101- $ this ->tmpDir ->expects ($ this ->once ())->method ('renameFile ' )
102- ->with ('foo/result ' . $ uniqId , 'foo/result ' , $ this ->staticDir );
103- $ this ->object ->merge ($ assets , $ this ->resultAsset );
105+
106+ $ this ->staticDirMock ->expects ($ this ->once ())
107+ ->method ('writeFile ' )
108+ ->with ('foo/result ' . $ uniqId , 'onetwo ' );
109+ $ this ->staticDirMock ->expects ($ this ->once ())
110+ ->method ('renameFile ' )
111+ ->with ('foo/result ' . $ uniqId , 'foo/result ' , $ this ->staticDirMock );
112+
113+ $ this ->model ->merge ($ assets , $ this ->resultAssetMock );
104114 }
105115
106116 public function testMergeCss ()
107117 {
108118 $ uniqId = '_f929c374767e00712449660ea673f2f5 ' ;
109- $ this ->resultAsset ->expects ($ this ->exactly (3 ))
119+ $ this ->resultAssetMock ->expects ($ this ->exactly (3 ))
110120 ->method ('getPath ' )
111121 ->willReturn ('foo/result ' );
112- $ this ->resultAsset ->expects ($ this ->any ())->method ('getContentType ' )->willReturn ('css ' );
122+ $ this ->resultAssetMock ->expects ($ this ->atLeastOnce ())
123+ ->method ('getContentType ' )
124+ ->willReturn ('css ' );
113125 $ assets = $ this ->prepareAssetsToMerge (['one ' , 'two ' ]);
114- $ this ->cssUrlResolver ->expects ($ this ->exactly (2 ))
126+ $ this ->cssUrlResolverMock ->expects ($ this ->exactly (2 ))
115127 ->method ('relocateRelativeUrls ' )
116128 ->will ($ this ->onConsecutiveCalls ('1 ' , '2 ' ));
117- $ this ->cssUrlResolver ->expects ($ this ->once ())
129+ $ this ->cssUrlResolverMock ->expects ($ this ->once ())
118130 ->method ('aggregateImportDirectives ' )
119131 ->with ('12 ' )
120132 ->willReturn ('1020 ' );
121133 $ this ->mathRandomMock ->expects ($ this ->once ())
122134 ->method ('getUniqueHash ' )
123135 ->willReturn ($ uniqId );
124- $ this ->staticDir ->expects ($ this ->never ())->method ('writeFile ' );
125- $ this ->tmpDir ->expects ($ this ->once ())->method ('writeFile ' )->with ('foo/result ' . $ uniqId , '1020 ' );
126- $ this ->tmpDir ->expects ($ this ->once ())->method ('renameFile ' )
127- ->with ('foo/result ' . $ uniqId , 'foo/result ' , $ this ->staticDir );
128- $ this ->object ->merge ($ assets , $ this ->resultAsset );
136+ $ this ->staticDirMock ->expects ($ this ->once ())
137+ ->method ('writeFile ' )
138+ ->with ('foo/result ' . $ uniqId , '1020 ' );
139+ $ this ->staticDirMock ->expects ($ this ->once ())
140+ ->method ('renameFile ' )
141+ ->with ('foo/result ' . $ uniqId , 'foo/result ' , $ this ->staticDirMock );
142+
143+ $ this ->model ->merge ($ assets , $ this ->resultAssetMock );
129144 }
130145
131146 /**
@@ -134,7 +149,7 @@ public function testMergeCss()
134149 * @param array $data
135150 * @return array
136151 */
137- private function prepareAssetsToMerge (array $ data )
152+ private function prepareAssetsToMerge (array $ data ): array
138153 {
139154 $ result = [];
140155 foreach ($ data as $ content ) {
0 commit comments