99
1010use Magento \Framework \App \Filesystem \DirectoryList ;
1111use Magento \Framework \Filesystem ;
12+ use Magento \ImportExport \Model \Import ;
1213use Magento \Framework \ObjectManagerInterface ;
1314use Magento \TestFramework \Helper \Bootstrap ;
1415use PHPUnit \Framework \TestCase ;
@@ -28,43 +29,53 @@ class CsvTest extends TestCase
2829 */
2930 private $ objectManager ;
3031
31- /**
32- * @var Csv
33- */
34- private $ csv ;
35-
3632 /**
3733 * @inheritdoc
3834 */
3935 protected function setUp (): void
4036 {
41- parent ::setUp ();
42-
4337 $ this ->objectManager = Bootstrap::getObjectManager ();
44- $ this ->csv = $ this ->objectManager ->create (
45- Csv::class,
46- ['destination ' => $ this ->destination ]
47- );
4838 }
4939
5040 /**
5141 * Test to destruct export adapter
42+ *
43+ * @dataProvider destructDataProvider
44+ *
45+ * @param string $destination
46+ * @param bool $shouldBeDeleted
47+ * @return void
5248 */
53- public function testDestruct (): void
49+ public function testDestruct (string $ destination , bool $ shouldBeDeleted ): void
5450 {
51+ $ csv = $ this ->objectManager ->create (Csv::class, ['destination ' => $ destination ]);
5552 /** @var Filesystem $fileSystem */
5653 $ fileSystem = $ this ->objectManager ->get (Filesystem::class);
5754 $ directoryHandle = $ fileSystem ->getDirectoryRead (DirectoryList::VAR_DIR );
5855 /** Assert that the destination file is present after construct */
5956 $ this ->assertFileExists (
60- $ directoryHandle ->getAbsolutePath ($ this -> destination ),
57+ $ directoryHandle ->getAbsolutePath ($ destination ),
6158 'The destination file was \'t created after construct '
6259 );
63- /** Assert that the destination file was removed after destruct */
64- $ this ->csv = null ;
65- $ this ->assertFileNotExists (
66- $ directoryHandle ->getAbsolutePath ($ this ->destination ),
67- 'The destination file was \'t removed after destruct '
68- );
60+ unset($ csv );
61+
62+ if ($ shouldBeDeleted ) {
63+ $ this ->assertFileDoesNotExist ($ directoryHandle ->getAbsolutePath ($ destination ));
64+ } else {
65+ $ this ->assertFileExists ($ directoryHandle ->getAbsolutePath ($ destination ));
66+ }
67+ }
68+
69+ /**
70+ * DataProvider for testDestruct
71+ *
72+ * @return array
73+ */
74+ public function destructDataProvider (): array
75+ {
76+ return [
77+ 'temporary file ' => [$ this ->destination , true ],
78+ 'import history file ' => [Import::IMPORT_HISTORY_DIR . $ this ->destination , false ],
79+ ];
6980 }
7081}
0 commit comments