Skip to content

Commit

Permalink
[BUGFIX] Allow importing empty CSV table (#560)
Browse files Browse the repository at this point in the history
When importing a .csv with a table definition and
no rows, a warning is raised: DataSet->getElements()
may return null, and this fails in the foreach in
DataSet->import(). It is more clean to return an
empty array in getElements(), which is done with
the patch.
  • Loading branch information
lolli42 authored Apr 9, 2024
1 parent b9c64f3 commit 3f1f220
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Classes/Core/Functional/Framework/DataHandling/DataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ public function getHashIndex(string $tableName): ?int
* Return a list of rows of given table. Keys are the uid or hash
* index fields of that table.
*/
public function getElements(string $tableName): ?array
public function getElements(string $tableName): array
{
$elements = null;
$elements = [];
if (isset($this->data[$tableName]['elements'])) {
$elements = $this->data[$tableName]['elements'];
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/Core/Functional/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ protected function assertCSVDataSet(string $fileName): void
$hasUidField = ($dataSet->getIdIndex($tableName) !== null);
$hasHashField = ($dataSet->getHashIndex($tableName) !== null);
$records = $this->getAllRecords($tableName, $hasUidField, $hasHashField);
$assertions = (array)$dataSet->getElements($tableName);
$assertions = $dataSet->getElements($tableName);
foreach ($assertions as $assertion) {
$result = $this->assertInRecords($assertion, $records);
if ($result === false) {
Expand Down

0 comments on commit 3f1f220

Please sign in to comment.