24
24
*/
25
25
class DirectTest extends TestCase
26
26
{
27
- /**
28
- * @var Random|MockObject
29
- */
30
- protected $ mathRandomMock ;
31
27
/**
32
28
* @var Direct
33
29
*/
34
- protected $ object ;
30
+ private $ model ;
35
31
36
32
/**
37
- * @var MockObject|CssResolver
33
+ * @var Random|MockObject
38
34
*/
39
- protected $ cssUrlResolver ;
35
+ private $ mathRandomMock ;
40
36
41
37
/**
42
- * @var MockObject|WriteInterface
38
+ * @var MockObject|CssResolver
43
39
*/
44
- protected $ staticDir ;
40
+ private $ cssUrlResolverMock ;
45
41
46
42
/**
47
43
* @var MockObject|WriteInterface
48
44
*/
49
- protected $ tmpDir ;
45
+ private $ staticDirMock ;
50
46
51
47
/**
52
48
* @var MockObject|LocalInterface
53
49
*/
54
- protected $ resultAsset ;
50
+ private $ resultAssetMock ;
55
51
52
+ /**
53
+ * @inheridoc
54
+ */
56
55
protected function setUp (): void
57
56
{
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 ())
65
63
->method ('getDirectoryWrite ' )
66
64
->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 ],
69
67
]);
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 );
75
72
}
76
73
77
74
public function testMergeNoAssets ()
78
75
{
79
76
$ 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 ' );
82
80
$ this ->mathRandomMock ->expects ($ this ->once ())
83
81
->method ('getUniqueHash ' )
84
82
->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 );
89
91
}
90
92
91
93
public function testMergeGeneric ()
92
94
{
93
95
$ uniqId = '_be50ccf992fd81818c1a2645d1a29e92 ' ;
94
- $ this ->resultAsset ->expects ($ this ->once ())->method ('getPath ' )->willReturn ('foo/result ' );
95
96
$ 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
+
97
102
$ this ->mathRandomMock ->expects ($ this ->once ())
98
103
->method ('getUniqueHash ' )
99
104
->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 );
104
114
}
105
115
106
116
public function testMergeCss ()
107
117
{
108
118
$ uniqId = '_f929c374767e00712449660ea673f2f5 ' ;
109
- $ this ->resultAsset ->expects ($ this ->exactly (3 ))
119
+ $ this ->resultAssetMock ->expects ($ this ->exactly (3 ))
110
120
->method ('getPath ' )
111
121
->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 ' );
113
125
$ assets = $ this ->prepareAssetsToMerge (['one ' , 'two ' ]);
114
- $ this ->cssUrlResolver ->expects ($ this ->exactly (2 ))
126
+ $ this ->cssUrlResolverMock ->expects ($ this ->exactly (2 ))
115
127
->method ('relocateRelativeUrls ' )
116
128
->will ($ this ->onConsecutiveCalls ('1 ' , '2 ' ));
117
- $ this ->cssUrlResolver ->expects ($ this ->once ())
129
+ $ this ->cssUrlResolverMock ->expects ($ this ->once ())
118
130
->method ('aggregateImportDirectives ' )
119
131
->with ('12 ' )
120
132
->willReturn ('1020 ' );
121
133
$ this ->mathRandomMock ->expects ($ this ->once ())
122
134
->method ('getUniqueHash ' )
123
135
->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 );
129
144
}
130
145
131
146
/**
@@ -134,7 +149,7 @@ public function testMergeCss()
134
149
* @param array $data
135
150
* @return array
136
151
*/
137
- private function prepareAssetsToMerge (array $ data )
152
+ private function prepareAssetsToMerge (array $ data ): array
138
153
{
139
154
$ result = [];
140
155
foreach ($ data as $ content ) {
0 commit comments