9
9
10
10
use Magento \Framework \App \Filesystem \DirectoryList ;
11
11
use Magento \Framework \Filesystem ;
12
+ use Magento \ImportExport \Model \Import ;
12
13
use Magento \Framework \ObjectManagerInterface ;
13
14
use Magento \TestFramework \Helper \Bootstrap ;
14
15
use PHPUnit \Framework \TestCase ;
@@ -28,43 +29,53 @@ class CsvTest extends TestCase
28
29
*/
29
30
private $ objectManager ;
30
31
31
- /**
32
- * @var Csv
33
- */
34
- private $ csv ;
35
-
36
32
/**
37
33
* @inheritdoc
38
34
*/
39
35
protected function setUp (): void
40
36
{
41
- parent ::setUp ();
42
-
43
37
$ this ->objectManager = Bootstrap::getObjectManager ();
44
- $ this ->csv = $ this ->objectManager ->create (
45
- Csv::class,
46
- ['destination ' => $ this ->destination ]
47
- );
48
38
}
49
39
50
40
/**
51
41
* Test to destruct export adapter
42
+ *
43
+ * @dataProvider destructDataProvider
44
+ *
45
+ * @param string $destination
46
+ * @param bool $shouldBeDeleted
47
+ * @return void
52
48
*/
53
- public function testDestruct (): void
49
+ public function testDestruct (string $ destination , bool $ shouldBeDeleted ): void
54
50
{
51
+ $ csv = $ this ->objectManager ->create (Csv::class, ['destination ' => $ destination ]);
55
52
/** @var Filesystem $fileSystem */
56
53
$ fileSystem = $ this ->objectManager ->get (Filesystem::class);
57
54
$ directoryHandle = $ fileSystem ->getDirectoryRead (DirectoryList::VAR_DIR );
58
55
/** Assert that the destination file is present after construct */
59
56
$ this ->assertFileExists (
60
- $ directoryHandle ->getAbsolutePath ($ this -> destination ),
57
+ $ directoryHandle ->getAbsolutePath ($ destination ),
61
58
'The destination file was \'t created after construct '
62
59
);
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
+ ];
69
80
}
70
81
}
0 commit comments