5
5
*/
6
6
namespace Magento \Framework \App \Test \Unit \View \Deployment ;
7
7
8
- use \Magento \Framework \App \View \Deployment \Version ;
8
+ use Magento \Framework \App \View \Deployment \Version ;
9
+ use Magento \Framework \Exception \FileSystemException ;
9
10
10
11
/**
11
12
* Class VersionTest
@@ -18,29 +19,39 @@ class VersionTest extends \PHPUnit_Framework_TestCase
18
19
private $ object ;
19
20
20
21
/**
21
- * @var \PHPUnit_Framework_MockObject_MockObject
22
+ * @var \Magento\Framework\App\State|\ PHPUnit_Framework_MockObject_MockObject
22
23
*/
23
- private $ appState ;
24
+ private $ appStateMock ;
24
25
25
26
/**
26
- * @var \PHPUnit_Framework_MockObject_MockObject
27
+ * @var \Magento\Framework\App\View\Deployment\Version\StorageInterface|\ PHPUnit_Framework_MockObject_MockObject
27
28
*/
28
- private $ versionStorage ;
29
+ private $ versionStorageMock ;
30
+
31
+ /**
32
+ * @var \Psr\Log\LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
33
+ */
34
+ private $ loggerMock ;
29
35
30
36
protected function setUp ()
31
37
{
32
- $ this ->appState = $ this ->getMock (\Magento \Framework \App \State::class, [], [], '' , false );
33
- $ this ->versionStorage = $ this ->getMock (\Magento \Framework \App \View \Deployment \Version \StorageInterface::class);
34
- $ this ->object = new Version ($ this ->appState , $ this ->versionStorage );
38
+ $ objectManager = new \Magento \Framework \TestFramework \Unit \Helper \ObjectManager ($ this );
39
+ $ this ->appStateMock = $ this ->getMock (\Magento \Framework \App \State::class, [], [], '' , false );
40
+ $ this ->versionStorageMock = $ this ->getMock (
41
+ \Magento \Framework \App \View \Deployment \Version \StorageInterface::class
42
+ );
43
+ $ this ->loggerMock = $ this ->getMock (\Psr \Log \LoggerInterface::class);
44
+ $ this ->object = new Version ($ this ->appStateMock , $ this ->versionStorageMock );
45
+ $ objectManager ->setBackwardCompatibleProperty ($ this ->object , 'logger ' , $ this ->loggerMock );
35
46
}
36
47
37
48
public function testGetValueDeveloperMode ()
38
49
{
39
- $ this ->appState
50
+ $ this ->appStateMock
40
51
->expects ($ this ->once ())
41
52
->method ('getMode ' )
42
53
->will ($ this ->returnValue (\Magento \Framework \App \State::MODE_DEVELOPER ));
43
- $ this ->versionStorage ->expects ($ this ->never ())->method ($ this ->anything ());
54
+ $ this ->versionStorageMock ->expects ($ this ->never ())->method ($ this ->anything ());
44
55
$ this ->assertInternalType ('integer ' , $ this ->object ->getValue ());
45
56
$ this ->object ->getValue (); // Ensure computation occurs only once and result is cached in memory
46
57
}
@@ -51,12 +62,12 @@ public function testGetValueDeveloperMode()
51
62
*/
52
63
public function testGetValueFromStorage ($ appMode )
53
64
{
54
- $ this ->appState
65
+ $ this ->appStateMock
55
66
->expects ($ this ->once ())
56
67
->method ('getMode ' )
57
68
->will ($ this ->returnValue ($ appMode ));
58
- $ this ->versionStorage ->expects ($ this ->once ())->method ('load ' )->will ($ this ->returnValue ('123 ' ));
59
- $ this ->versionStorage ->expects ($ this ->never ())->method ('save ' );
69
+ $ this ->versionStorageMock ->expects ($ this ->once ())->method ('load ' )->will ($ this ->returnValue ('123 ' ));
70
+ $ this ->versionStorageMock ->expects ($ this ->never ())->method ('save ' );
60
71
$ this ->assertEquals ('123 ' , $ this ->object ->getValue ());
61
72
$ this ->object ->getValue (); // Ensure caching in memory
62
73
}
@@ -70,20 +81,106 @@ public function getValueFromStorageDataProvider()
70
81
];
71
82
}
72
83
73
- public function testGetValueDefaultModeSaving ()
74
- {
84
+ /**
85
+ * $param bool $isUnexpectedValueExceptionThrown
86
+ * $param bool $isFileSystemExceptionThrown
87
+ * @dataProvider getValueDefaultModeDataProvider
88
+ */
89
+ public function testGetValueDefaultMode (
90
+ $ isUnexpectedValueExceptionThrown ,
91
+ $ isFileSystemExceptionThrown = null
92
+ ) {
75
93
$ versionType = 'integer ' ;
76
- $ this ->appState
94
+ $ this ->appStateMock
77
95
->expects ($ this ->once ())
78
96
->method ('getMode ' )
79
- ->will ($ this ->returnValue (\Magento \Framework \App \State::MODE_DEFAULT ));
80
- $ storageException = new \UnexpectedValueException ('Does not exist in the storage ' );
81
- $ this ->versionStorage
82
- ->expects ($ this ->once ())
83
- ->method ('load ' )
84
- ->will ($ this ->throwException ($ storageException ));
85
- $ this ->versionStorage ->expects ($ this ->once ())->method ('save ' )->with ($ this ->isType ($ versionType ));
97
+ ->willReturn (\Magento \Framework \App \State::MODE_DEFAULT );
98
+ if ($ isUnexpectedValueExceptionThrown ) {
99
+ $ storageException = new \UnexpectedValueException ('Does not exist in the storage ' );
100
+ $ this ->versionStorageMock
101
+ ->expects ($ this ->once ())
102
+ ->method ('load ' )
103
+ ->will ($ this ->throwException ($ storageException ));
104
+ $ this ->versionStorageMock ->expects ($ this ->once ())
105
+ ->method ('save ' )
106
+ ->with ($ this ->isType ($ versionType ));
107
+ if ($ isFileSystemExceptionThrown ) {
108
+ $ fileSystemException = new FileSystemException (
109
+ new \Magento \Framework \Phrase ('Can not load static content version ' )
110
+ );
111
+ $ this ->versionStorageMock
112
+ ->expects ($ this ->once ())
113
+ ->method ('save ' )
114
+ ->will ($ this ->throwException ($ fileSystemException ));
115
+ $ this ->loggerMock ->expects ($ this ->once ())
116
+ ->method ('critical ' )
117
+ ->with ('Can not save static content version. ' );
118
+ } else {
119
+ $ this ->loggerMock ->expects ($ this ->never ())
120
+ ->method ('critical ' );
121
+ }
122
+ } else {
123
+ $ this ->versionStorageMock
124
+ ->expects ($ this ->once ())
125
+ ->method ('load ' )
126
+ ->willReturn (1475779229 );
127
+ $ this ->loggerMock ->expects ($ this ->never ())
128
+ ->method ('critical ' );
129
+ }
86
130
$ this ->assertInternalType ($ versionType , $ this ->object ->getValue ());
87
- $ this ->object ->getValue (); // Ensure caching in memory
131
+ $ this ->object ->getValue ();
132
+ }
133
+
134
+ /**
135
+ * @return array
136
+ */
137
+ public function getValueDefaultModeDataProvider ()
138
+ {
139
+ return [
140
+ [false ],
141
+ [true , false ],
142
+ [true , true ]
143
+ ];
144
+ }
145
+
146
+ /**
147
+ * @param bool $isUnexpectedValueExceptionThrown
148
+ * @dataProvider getValueProductionModeDataProvider
149
+ */
150
+ public function testGetValueProductionMode (
151
+ $ isUnexpectedValueExceptionThrown
152
+ ) {
153
+ $ this ->appStateMock
154
+ ->expects ($ this ->once ())
155
+ ->method ('getMode ' )
156
+ ->willReturn (\Magento \Framework \App \State::MODE_PRODUCTION );
157
+ if ($ isUnexpectedValueExceptionThrown ) {
158
+ $ storageException = new \UnexpectedValueException ('Does not exist in the storage ' );
159
+ $ this ->versionStorageMock
160
+ ->expects ($ this ->once ())
161
+ ->method ('load ' )
162
+ ->will ($ this ->throwException ($ storageException ));
163
+ $ this ->loggerMock ->expects ($ this ->once ())
164
+ ->method ('critical ' )
165
+ ->with ('Can not load static content version. ' );
166
+ } else {
167
+ $ this ->versionStorageMock
168
+ ->expects ($ this ->once ())
169
+ ->method ('load ' )
170
+ ->willReturn (1475779229 );
171
+ }
172
+ $ this ->assertInternalType ('integer ' , $ this ->object ->getValue ());
173
+ $ this ->object ->getValue ();
174
+ }
175
+
176
+ /**
177
+ * @return array
178
+ */
179
+ public function getValueProductionModeDataProvider ()
180
+ {
181
+ return [
182
+ [false ],
183
+ [true ],
184
+ ];
88
185
}
89
186
}
0 commit comments