Add test for excel document content

This commit is contained in:
philipp lang 2024-07-15 23:24:10 +02:00
parent c1d0221dcd
commit 50a3c6df90
1 changed files with 23 additions and 0 deletions

View File

@ -0,0 +1,23 @@
<?php
namespace Zoomyboy\TableDocument;
use PhpOffice\PhpSpreadsheet\Writer\Csv;
use PHPUnit\Framework\Assert;
trait TestsExcelDocuments
{
public function assertExcelContent(string $should, string $content): void
{
$filename = sys_get_temp_dir() . '/' . str()->uuid()->toString();
file_put_contents($filename, $content);
$spreadsheet = \PhpOffice\PhpSpreadsheet\IOFactory::load($filename);
$writer = new Csv($spreadsheet);
$writer->save($filename);
$spreadsheet->disconnectWorksheets();
$contents = file_get_contents($filename);
unlink($filename);
Assert::assertStringContainsString($should, $contents);
}
}