20
20
use Magento \ImportExport \Controller \Adminhtml \Export \File \Download ;
21
21
use PHPUnit \Framework \MockObject \MockObject ;
22
22
use PHPUnit \Framework \TestCase ;
23
+ use Magento \Framework \Filesystem \Directory \WriteInterface ;
24
+ use Magento \Framework \Filesystem \DriverInterface ;
23
25
24
26
/**
25
27
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -76,6 +78,11 @@ class DownloadTest extends TestCase
76
78
*/
77
79
private $ directoryMock ;
78
80
81
+ /**
82
+ * @var WriteInterface|MockObject
83
+ */
84
+ private $ exportDirectoryMock ;
85
+
79
86
/**
80
87
* Set up
81
88
*/
@@ -89,6 +96,10 @@ protected function setUp(): void
89
96
->disableOriginalConstructor ()
90
97
->getMock ();
91
98
99
+ $ this ->exportDirectoryMock = $ this ->getMockBuilder (WriteInterface::class)
100
+ ->disableOriginalConstructor ()
101
+ ->getMockForAbstractClass ();
102
+
92
103
$ this ->directoryMock = $ this ->getMockBuilder (ReadInterface::class)
93
104
->disableOriginalConstructor ()
94
105
->getMockForAbstractClass ();
@@ -135,6 +146,10 @@ protected function setUp(): void
135
146
->method ('getDirectoryRead ' )
136
147
->willReturn ($ this ->directoryMock );
137
148
149
+ $ this ->fileSystemMock ->expects ($ this ->any ())
150
+ ->method ('getDirectoryWrite ' )
151
+ ->willReturn ($ this ->exportDirectoryMock );
152
+
138
153
$ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
139
154
$ this ->downloadControllerMock = $ this ->objectManagerHelper ->getObject (
140
155
Download::class,
@@ -154,7 +169,18 @@ public function testExecuteSuccess()
154
169
$ this ->requestMock ->method ('getParam ' )
155
170
->with ('filename ' )
156
171
->willReturn ('sampleFile.csv ' );
157
- $ this ->directoryMock ->expects ($ this ->once ())->method ('isExist ' )->willReturn (true );
172
+
173
+ $ driverMock = $ this ->getMockBuilder (DriverInterface::class)
174
+ ->disableOriginalConstructor ()
175
+ ->getMock ();
176
+
177
+ $ driverMock ->expects ($ this ->once ())->method ('getRealPathSafety ' )->willReturn ('sampleFile.csv ' );
178
+
179
+ $ this ->exportDirectoryMock ->expects ($ this ->any ())
180
+ ->method ('getDriver ' )
181
+ ->willReturn ($ driverMock );
182
+
183
+ $ this ->exportDirectoryMock ->expects ($ this ->once ())->method ('isExist ' )->willReturn (true );
158
184
$ this ->directoryMock ->expects ($ this ->once ())->method ('isFile ' )->willReturn (true );
159
185
$ this ->fileFactoryMock ->expects ($ this ->once ())->method ('create ' );
160
186
@@ -170,8 +196,18 @@ public function testExecuteFileDoesntExists()
170
196
->with ('filename ' )
171
197
->willReturn ('sampleFile ' );
172
198
199
+ $ driverMock = $ this ->getMockBuilder (DriverInterface::class)
200
+ ->disableOriginalConstructor ()
201
+ ->getMock ();
202
+
203
+ $ driverMock ->expects ($ this ->once ())->method ('getRealPathSafety ' )->willReturn ('sampleFile ' );
204
+
205
+ $ this ->exportDirectoryMock ->expects ($ this ->any ())
206
+ ->method ('getDriver ' )
207
+ ->willReturn ($ driverMock );
208
+
209
+ $ this ->exportDirectoryMock ->expects ($ this ->once ())->method ('isExist ' )->willReturn (true );
173
210
$ this ->directoryMock ->expects ($ this ->once ())->method ('isFile ' )->willReturn (false );
174
- $ this ->directoryMock ->expects ($ this ->once ())->method ('isExist ' )->willReturn (true );
175
211
$ this ->messageManagerMock ->expects ($ this ->once ())->method ('addErrorMessage ' );
176
212
177
213
$ this ->downloadControllerMock ->execute ();
0 commit comments