Skip to content

Commit bd208cc

Browse files
ENGCOM-7616: Product CSV import error report file missing #28460
- Merge Pull Request #28460 from engcom-Charlie/magento2:28420 - Merged commits: 1. d4d8ef4 2. 597d65f
2 parents a94aa00 + 597d65f commit bd208cc

File tree

2 files changed

+43
-19
lines changed
  • app/code/Magento/ImportExport/Model/Export/Adapter
  • dev/tests/integration/testsuite/Magento/ImportExport/Model/Export/Adapter

2 files changed

+43
-19
lines changed

app/code/Magento/ImportExport/Model/Export/Adapter/Csv.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,19 @@ public function destruct()
5454
{
5555
if (is_object($this->_fileHandler)) {
5656
$this->_fileHandler->close();
57+
$this->resolveDestination();
58+
}
59+
}
60+
61+
/**
62+
* Remove temporary destination
63+
*
64+
* @return void
65+
*/
66+
private function resolveDestination(): void
67+
{
68+
// only temporary file located directly in var folder
69+
if (strpos($this->_destination, '/') === false) {
5770
$this->_directoryHandle->delete($this->_destination);
5871
}
5972
}

dev/tests/integration/testsuite/Magento/ImportExport/Model/Export/Adapter/CsvTest.php

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Framework\App\Filesystem\DirectoryList;
1111
use Magento\Framework\Filesystem;
12+
use Magento\ImportExport\Model\Import;
1213
use Magento\Framework\ObjectManagerInterface;
1314
use Magento\TestFramework\Helper\Bootstrap;
1415
use 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

Comments
 (0)