Add tests for listWorksheetNames and empty file coverage

This commit is contained in:
kemo
2026-03-11 08:39:40 +01:00
parent e0ecd38a82
commit 545cafb7f2
@@ -304,6 +304,42 @@ class CsvStreamingEncodingTest extends TestCase
self::assertSame('C', $info[0]['lastColumnLetter']);
}
/**
* Test that listWorksheetNames works with non-UTF-8 streaming path.
*/
public function testListWorksheetNamesWithNonUtf8(): void
{
$utf8Csv = "a,b,c\n1,2,3\n";
$isoCsv = mb_convert_encoding($utf8Csv, 'ISO-8859-1', 'UTF-8');
$filename = $this->tempDir . '/worksheetnames_iso.csv';
file_put_contents($filename, $isoCsv);
$reader = new Csv();
$reader->setInputEncoding('ISO-8859-1');
$names = $reader->listWorksheetNames($filename);
self::assertCount(1, $names);
self::assertSame('Worksheet', $names[0]);
}
/**
* Test that an empty non-UTF-8 file is handled gracefully.
*/
public function testEmptyNonUtf8File(): void
{
$filename = $this->tempDir . '/empty_iso.csv';
file_put_contents($filename, '');
$reader = new Csv();
$reader->setInputEncoding('ISO-8859-1');
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();
self::assertNull($sheet->getCell('A1')->getValue());
$spreadsheet->disconnectWorksheets();
}
/**
* Test guess encoding still works with the streaming path.
*/