Add content testing for multiple sheets
This commit is contained in:
parent
7304963370
commit
f7b0459183
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue