13
13
use Magento \Catalog \Model \Product \Media \Config ;
14
14
use Magento \Framework \Config \View ;
15
15
use Magento \Framework \Encryption \EncryptorInterface ;
16
+ use Magento \Framework \Exception \FileSystemException ;
17
+ use Magento \Framework \Phrase ;
16
18
use Magento \Framework \Filesystem ;
17
19
use Magento \Framework \Filesystem \Directory \Write ;
18
20
use Magento \Framework \View \ConfigInterface ;
25
27
class RemoveDeletedImagesFromCacheTest extends TestCase
26
28
{
27
29
/**
28
- * @var RemoveDeletedImagesFromCache| MockObject
30
+ * @var MockObject|RemoveDeletedImagesFromCache
29
31
*/
30
- protected $ model ;
32
+ protected RemoveDeletedImagesFromCache | MockObject $ model ;
31
33
32
34
/**
33
35
* @var ConfigInterface|MockObject
34
36
*/
35
- protected $ presentationConfig ;
37
+ protected ConfigInterface | MockObject $ presentationConfig ;
36
38
37
39
/**
38
40
* @var EncryptorInterface|MockObject
39
41
*/
40
- protected $ encryptor ;
42
+ protected EncryptorInterface | MockObject $ encryptor ;
41
43
42
44
/**
43
45
* @var Config|MockObject
44
46
*/
45
- protected $ mediaConfig ;
47
+ protected Config | MockObject $ mediaConfig ;
46
48
47
49
/**
48
- * @var Write| MockObject
50
+ * @var MockObject|Write
49
51
*/
50
- protected $ mediaDirectory ;
52
+ protected Write | MockObject $ mediaDirectory ;
51
53
52
54
/**
53
- * @var ParamsBuilder| MockObject
55
+ * @var MockObject|ParamsBuilder
54
56
*/
55
- protected $ imageParamsBuilder ;
57
+ protected ParamsBuilder | MockObject $ imageParamsBuilder ;
56
58
57
59
/**
58
60
* @var ConvertImageMiscParamsToReadableFormat|MockObject
59
61
*/
60
- protected $ convertImageMiscParamsToReadableFormat ;
62
+ protected ConvertImageMiscParamsToReadableFormat | MockObject $ convertImageMiscParamsToReadableFormat ;
61
63
62
64
/**
63
- * @var View| MockObject
65
+ * @var MockObject|View
64
66
*/
65
- protected $ viewMock ;
67
+ protected View | MockObject $ viewMock ;
66
68
67
69
protected function setUp (): void
68
70
{
@@ -102,6 +104,55 @@ protected function setUp(): void
102
104
* @dataProvider createDataProvider
103
105
*/
104
106
public function testRemoveDeletedImagesFromCache (array $ data ): void
107
+ {
108
+ $ this ->getRespectiveMethodMockObjForRemoveDeletedImagesFromCache ($ data );
109
+
110
+ $ this ->mediaDirectory ->expects ($ this ->once ())
111
+ ->method ('delete ' )
112
+ ->willReturn (true );
113
+
114
+ $ this ->model ->removeDeletedImagesFromCache (['i/m/image.jpg ' ]);
115
+ }
116
+
117
+ /**
118
+ * @param array $data
119
+ * @return void
120
+ * @dataProvider createDataProvider
121
+ */
122
+ public function testRemoveDeletedImagesFromCacheWithException (array $ data ): void
123
+ {
124
+ $ this ->getRespectiveMethodMockObjForRemoveDeletedImagesFromCache ($ data );
125
+
126
+ $ this ->expectException ('Exception ' );
127
+ $ this ->expectExceptionMessage ('Unable to write file into directory product/cache. Access forbidden. ' );
128
+
129
+ $ exception = new FileSystemException (
130
+ new Phrase ('Unable to write file into directory product/cache. Access forbidden. ' )
131
+ );
132
+
133
+ $ this ->mediaDirectory ->expects ($ this ->once ())
134
+ ->method ('delete ' )
135
+ ->willThrowException ($ exception );
136
+
137
+ $ this ->model ->removeDeletedImagesFromCache (['i/m/image.jpg ' ]);
138
+ }
139
+
140
+ /**
141
+ * @return void
142
+ */
143
+ public function testRemoveDeletedImagesFromCacheWithEmptyFiles (): void
144
+ {
145
+ $ this ->assertEquals (
146
+ null ,
147
+ $ this ->model ->removeDeletedImagesFromCache ([])
148
+ );
149
+ }
150
+
151
+ /**
152
+ * @param array $data
153
+ * @return void
154
+ */
155
+ public function getRespectiveMethodMockObjForRemoveDeletedImagesFromCache (array $ data ): void
105
156
{
106
157
$ this ->presentationConfig ->expects ($ this ->once ())
107
158
->method ('getViewConfig ' )
@@ -127,12 +178,6 @@ public function testRemoveDeletedImagesFromCache(array $data): void
127
178
$ this ->mediaConfig ->expects ($ this ->once ())
128
179
->method ('getBaseMediaPath ' )
129
180
->willReturn ('catalog/product ' );
130
-
131
- $ this ->mediaDirectory ->expects ($ this ->once ())
132
- ->method ('delete ' )
133
- ->willReturn (true );
134
-
135
- $ this ->model ->removeDeletedImagesFromCache (['i/m/image.jpg ' ]);
136
181
}
137
182
138
183
/**
0 commit comments