2020use Magento \ImportExport \Controller \Adminhtml \Export \File \Download ;
2121use PHPUnit \Framework \MockObject \MockObject ;
2222use PHPUnit \Framework \TestCase ;
23+ use Magento \Framework \Filesystem \Directory \WriteInterface ;
24+ use Magento \Framework \Filesystem \DriverInterface ;
2325
2426/**
2527 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -76,6 +78,11 @@ class DownloadTest extends TestCase
7678 */
7779 private $ directoryMock ;
7880
81+ /**
82+ * @var WriteInterface|MockObject
83+ */
84+ private $ exportDirectoryMock ;
85+
7986 /**
8087 * Set up
8188 */
@@ -89,6 +96,10 @@ protected function setUp(): void
8996 ->disableOriginalConstructor ()
9097 ->getMock ();
9198
99+ $ this ->exportDirectoryMock = $ this ->getMockBuilder (WriteInterface::class)
100+ ->disableOriginalConstructor ()
101+ ->getMockForAbstractClass ();
102+
92103 $ this ->directoryMock = $ this ->getMockBuilder (ReadInterface::class)
93104 ->disableOriginalConstructor ()
94105 ->getMockForAbstractClass ();
@@ -135,6 +146,10 @@ protected function setUp(): void
135146 ->method ('getDirectoryRead ' )
136147 ->willReturn ($ this ->directoryMock );
137148
149+ $ this ->fileSystemMock ->expects ($ this ->any ())
150+ ->method ('getDirectoryWrite ' )
151+ ->willReturn ($ this ->exportDirectoryMock );
152+
138153 $ this ->objectManagerHelper = new ObjectManagerHelper ($ this );
139154 $ this ->downloadControllerMock = $ this ->objectManagerHelper ->getObject (
140155 Download::class,
@@ -154,7 +169,18 @@ public function testExecuteSuccess()
154169 $ this ->requestMock ->method ('getParam ' )
155170 ->with ('filename ' )
156171 ->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 );
158184 $ this ->directoryMock ->expects ($ this ->once ())->method ('isFile ' )->willReturn (true );
159185 $ this ->fileFactoryMock ->expects ($ this ->once ())->method ('create ' );
160186
@@ -170,8 +196,18 @@ public function testExecuteFileDoesntExists()
170196 ->with ('filename ' )
171197 ->willReturn ('sampleFile ' );
172198
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 );
173210 $ this ->directoryMock ->expects ($ this ->once ())->method ('isFile ' )->willReturn (false );
174- $ this ->directoryMock ->expects ($ this ->once ())->method ('isExist ' )->willReturn (true );
175211 $ this ->messageManagerMock ->expects ($ this ->once ())->method ('addErrorMessage ' );
176212
177213 $ this ->downloadControllerMock ->execute ();
0 commit comments