Add content testing for multiple sheets

This commit is contained in:
philipp lang 2025-11-12 03:28:05 +01:00
parent 7304963370
commit f7b0459183
1 changed files with 7 additions and 4 deletions

View File

@ -11,14 +11,17 @@ trait TestsExcelDocuments
public function assertExcelContent(string $should, string $content): void
{
$output = '';
$filename = sys_get_temp_dir() . '/' . str()->uuid()->toString();
file_put_contents($filename, $content);
$spreadsheet = IOFactory::load($filename, 0, [IOFactory::READER_XLSX]);
$writer = new Csv($spreadsheet);
$writer->save($filename);
foreach ($spreadsheet->getAllSheets() as $i => $sheet) {
$writer->setSheetIndex($i)->save($filename);
$output .= file_get_contents($filename);
}
$spreadsheet->disconnectWorksheets();
$contents = file_get_contents($filename);
unlink($filename);
Assert::assertStringContainsString($should, $contents);
Assert::assertStringContainsString($should, $output);
}
}