5
5
*/
6
6
namespace Magento \Framework \View \Test \Unit \Asset ;
7
7
8
+ use Magento \Framework \App \State ;
9
+ use Magento \Framework \Filesystem ;
10
+ use Magento \Framework \ObjectManagerInterface ;
11
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
12
+ use Magento \Framework \View \Asset \AssetInterface ;
13
+ use Magento \Framework \View \Asset \Merged ;
14
+ use Magento \Framework \View \Asset \MergeService ;
15
+ use Magento \Framework \View \Asset \ConfigInterface ;
16
+ use Magento \Framework \View \Asset \MergeStrategy \Checksum ;
17
+ use Magento \Framework \View \Asset \MergeStrategy \FileExists ;
18
+
19
+ /**
20
+ * Class MergeServiceTest
21
+ */
8
22
class MergeServiceTest extends \PHPUnit_Framework_TestCase
9
23
{
10
24
/**
11
- * @var \Magento\Framework\View\Asset\ MergeService
25
+ * @var MergeService
12
26
*/
13
- protected $ _object ;
27
+ private $ object ;
14
28
15
29
/**
16
- * @var \PHPUnit_Framework_MockObject_MockObject
30
+ * @var ObjectManagerInterface| \PHPUnit_Framework_MockObject_MockObject
17
31
*/
18
- protected $ _objectManager ;
32
+ private $ objectManagerMock ;
19
33
20
34
/**
21
- * @var \PHPUnit_Framework_MockObject_MockObject
35
+ * @var ConfigInterface| \PHPUnit_Framework_MockObject_MockObject
22
36
*/
23
- protected $ _config ;
37
+ private $ configMock ;
24
38
25
39
/**
26
- * @var \PHPUnit_Framework_MockObject_MockObject
40
+ * @var Filesystem| \PHPUnit_Framework_MockObject_MockObject
27
41
*/
28
- protected $ _filesystem ;
42
+ private $ filesystemMock ;
29
43
30
44
/**
31
- * @var \PHPUnit_Framework_MockObject_MockObject
45
+ * @var Filesystem\Directory\Write| \PHPUnit_Framework_MockObject_MockObject
32
46
*/
33
- protected $ _directory ;
47
+ protected $ directoryMock ;
34
48
35
49
/**
36
- * @var \PHPUnit_Framework_MockObject_MockObject
50
+ * @var State| \PHPUnit_Framework_MockObject_MockObject
37
51
*/
38
- protected $ _state ;
52
+ protected $ stateMock ;
39
53
40
54
protected function setUp ()
41
55
{
42
- $ this ->_objectManager = $ this ->getMock ('Magento\Framework\ObjectManagerInterface ' );
43
- $ this ->_config = $ this ->getMock ('Magento\Framework\View\Asset\ConfigInterface ' , [], [], '' , false );
44
- $ this ->_filesystem = $ this ->getMock ('Magento\Framework\Filesystem ' , [], [], '' , false );
45
- $ this ->_directory = $ this ->getMock (
46
- '\Magento\Framework\Filesystem\Directory\Write ' ,
47
- [],
48
- [],
49
- '' ,
50
- false
51
- );
52
- $ this ->_state = $ this ->getMock ('Magento\Framework\App\State ' , [], [], '' , false );
53
- $ this ->_filesystem ->expects (
54
- $ this ->any ()
55
- )->method (
56
- 'getDirectoryWrite '
57
- )->will (
58
- $ this ->returnValue ($ this ->_directory )
59
- );
60
-
61
- $ this ->_object = new \Magento \Framework \View \Asset \MergeService (
62
- $ this ->_objectManager ,
63
- $ this ->_config ,
64
- $ this ->_filesystem ,
65
- $ this ->_state
66
- );
56
+ $ this ->objectManagerMock = $ this ->getMockBuilder (ObjectManagerInterface::class)
57
+ ->getMockForAbstractClass ();
58
+ $ this ->configMock = $ this ->getMockBuilder (ConfigInterface::class)
59
+ ->getMockForAbstractClass ();
60
+ $ this ->filesystemMock = $ this ->getMockBuilder (Filesystem::class)
61
+ ->disableOriginalConstructor ()
62
+ ->getMock ();
63
+ $ this ->directoryMock = $ this ->getMockBuilder (Filesystem \Directory \Write::class)
64
+ ->disableOriginalConstructor ()
65
+ ->getMock ();
66
+ $ this ->stateMock = $ this ->getMockBuilder (State::class)
67
+ ->disableOriginalConstructor ()
68
+ ->getMock ();
69
+ $ this ->filesystemMock ->expects ($ this ->any ())
70
+ ->method ('getDirectoryWrite ' )
71
+ ->willReturn ($ this ->directoryMock );
72
+
73
+ $ this ->object = (new ObjectManager ($ this ))->getObject (MergeService::class, [
74
+ 'objectManager ' => $ this ->objectManagerMock ,
75
+ 'config ' => $ this ->configMock ,
76
+ 'filesystem ' => $ this ->filesystemMock ,
77
+ 'state ' => $ this ->stateMock ,
78
+ ]);
67
79
}
68
80
69
81
/**
@@ -72,7 +84,7 @@ protected function setUp()
72
84
*/
73
85
public function testGetMergedAssetsWrongContentType ()
74
86
{
75
- $ this ->_object ->getMergedAssets ([], 'unknown ' );
87
+ $ this ->object ->getMergedAssets ([], 'unknown ' );
76
88
}
77
89
78
90
/**
@@ -84,34 +96,25 @@ public function testGetMergedAssetsWrongContentType()
84
96
*/
85
97
public function testGetMergedAssets (array $ assets , $ contentType , $ appMode , $ mergeStrategy )
86
98
{
87
- $ mergedAsset = $ this ->getMock ('Magento\Framework\View\Asset\AssetInterface ' );
88
- $ this ->_config ->expects ($ this ->once ())->method ('isMergeCssFiles ' )->will ($ this ->returnValue (true ));
89
- $ this ->_config ->expects ($ this ->once ())->method ('isMergeJsFiles ' )->will ($ this ->returnValue (true ));
90
-
99
+ $ mergedAsset = $ this ->getMock (AssetInterface::class);
91
100
$ mergeStrategyMock = $ this ->getMock ($ mergeStrategy , [], [], '' , false );
92
101
93
- $ this ->_objectManager ->expects (
94
- $ this ->once ()
95
- )->method (
96
- 'create '
97
- )->with (
98
- 'Magento\Framework\View\Asset\Merged ' ,
99
- ['assets ' => $ assets , 'mergeStrategy ' => $ mergeStrategyMock ]
100
- )->will (
101
- $ this ->returnValue ($ mergedAsset )
102
- );
103
-
104
- $ this ->_objectManager ->expects (
105
- $ this ->once ()
106
- )->method (
107
- 'get '
108
- )->with (
109
- $ mergeStrategy
110
- )->will (
111
- $ this ->returnValue ($ mergeStrategyMock )
112
- );
113
- $ this ->_state ->expects ($ this ->once ())->method ('getMode ' )->will ($ this ->returnValue ($ appMode ));
114
- $ this ->assertSame ($ mergedAsset , $ this ->_object ->getMergedAssets ($ assets , $ contentType ));
102
+ $ this ->configMock ->expects ($ this ->once ())->method ('isMergeCssFiles ' )->willReturn (true );
103
+ $ this ->configMock ->expects ($ this ->once ())->method ('isMergeJsFiles ' )->willReturn (true );
104
+
105
+ $ this ->objectManagerMock ->expects ($ this ->once ())
106
+ ->method ('create ' )
107
+ ->with (Merged::class, ['assets ' => $ assets , 'mergeStrategy ' => $ mergeStrategyMock ])
108
+ ->willReturn ($ mergedAsset );
109
+ $ this ->objectManagerMock ->expects ($ this ->once ())
110
+ ->method ('get ' )
111
+ ->with ($ mergeStrategy )
112
+ ->willReturn ($ mergeStrategyMock );
113
+ $ this ->stateMock ->expects ($ this ->once ())
114
+ ->method ('getMode ' )
115
+ ->willReturn ($ appMode );
116
+
117
+ $ this ->assertSame ($ mergedAsset , $ this ->object ->getMergedAssets ($ assets , $ contentType ));
115
118
}
116
119
117
120
public static function getMergedAssetsDataProvider ()
@@ -128,47 +131,50 @@ public static function getMergedAssetsDataProvider()
128
131
'js production mode ' => [
129
132
$ jsAssets ,
130
133
'js ' ,
131
- \ Magento \ Framework \ App \ State::MODE_PRODUCTION ,
132
- ' Magento\Framework\View\Asset\MergeStrategy\ FileExists' ,
134
+ State::MODE_PRODUCTION ,
135
+ FileExists::class ,
133
136
],
134
137
'css production mode ' => [
135
138
$ cssAssets ,
136
139
'css ' ,
137
- \ Magento \ Framework \ App \ State::MODE_PRODUCTION ,
138
- ' Magento\Framework\View\Asset\MergeStrategy\ FileExists' ,
140
+ State::MODE_PRODUCTION ,
141
+ FileExists::class ,
139
142
],
140
143
'js default mode ' => [
141
144
$ jsAssets ,
142
145
'js ' ,
143
- \ Magento \ Framework \ App \ State::MODE_DEFAULT ,
144
- ' Magento\Framework\View\Asset\MergeStrategy\ FileExists' ,
146
+ State::MODE_DEFAULT ,
147
+ FileExists::class ,
145
148
],
146
149
'css default mode ' => [
147
150
$ cssAssets ,
148
151
'js ' ,
149
- \ Magento \ Framework \ App \ State::MODE_DEFAULT ,
150
- ' Magento\Framework\View\Asset\MergeStrategy\ FileExists' ,
152
+ State::MODE_DEFAULT ,
153
+ FileExists::class ,
151
154
],
152
155
'js developer mode ' => [
153
156
$ jsAssets ,
154
157
'js ' ,
155
- \ Magento \ Framework \ App \ State::MODE_DEVELOPER ,
156
- ' Magento\Framework\View\Asset\MergeStrategy\ Checksum' ,
158
+ State::MODE_DEVELOPER ,
159
+ Checksum::class ,
157
160
],
158
161
'css developer mode ' => [
159
162
$ cssAssets ,
160
163
'css ' ,
161
164
\Magento \Framework \App \State::MODE_DEVELOPER ,
162
- ' Magento\Framework\View\Asset\MergeStrategy\ Checksum' ,
165
+ Checksum::class ,
163
166
]
164
167
];
165
168
}
166
169
167
170
public function testCleanMergedJsCss ()
168
171
{
169
172
$ mergedDir = \Magento \Framework \View \Asset \Merged::getRelativeDir ();
170
- $ this ->_directory ->expects ($ this ->once ())->method ('delete ' )->with ($ mergedDir );
171
173
172
- $ this ->_object ->cleanMergedJsCss ();
174
+ $ this ->directoryMock ->expects ($ this ->once ())
175
+ ->method ('delete ' )
176
+ ->with ($ mergedDir );
177
+
178
+ $ this ->object ->cleanMergedJsCss ();
173
179
}
174
180
}
0 commit comments