Skip to content

Commit

Permalink
Merge pull request #4165 from oleibman/dompdf84
Browse files Browse the repository at this point in the history
Dompdf and Php8.4
  • Loading branch information
oleibman authored Sep 8, 2024
2 parents 6c9b2a8 + 995d9c7 commit 3815843
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/PhpSpreadsheet/Helper/Sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PhpOffice\PhpSpreadsheet\Writer\IWriter;
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use RecursiveRegexIterator;
Expand Down Expand Up @@ -125,7 +126,11 @@ public function write(Spreadsheet $spreadsheet, string $filename, array $writers
$writerCallback($writer);
}
$callStartTime = microtime(true);
$writer->save($path);
if (PHP_VERSION_ID >= 80400 && $writer instanceof Dompdf) {
@$writer->save($path);
} else {
$writer->save($path);
}
$this->logWrite($writer, $path, $callStartTime);
if ($this->isCli() === false) {
// @codeCoverageIgnoreStart
Expand Down
12 changes: 11 additions & 1 deletion tests/PhpSpreadsheetTests/Functional/StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;

/**
* Not clear that Dompdf will be Php8.4 compatible in time.
* Run in separate process and add version test till it is ready.
*
* @runTestsInSeparateProcesses
*/
class StreamTest extends TestCase
{
public static function providerFormats(): array
Expand Down Expand Up @@ -42,7 +48,11 @@ public function testAllWritersCanWriteToStream(string $format): void
} else {
self::assertSame(0, $stat['size']);

$writer->save($stream);
if ($format === 'Dompdf' && PHP_VERSION_ID >= 80400) {
@$writer->save($stream);
} else {
$writer->save($stream);
}

self::assertIsResource($stream, 'should not close the stream for further usage out of PhpSpreadsheet');
$stat = fstat($stream);
Expand Down
18 changes: 16 additions & 2 deletions tests/PhpSpreadsheetTests/Writer/Dompdf/PaperSizeArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
use PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf;
use PHPUnit\Framework\TestCase;

/**
* Not clear that Dompdf will be Php8.4 compatible in time.
* Run in separate process and add version test till it is ready.
*
* @runTestsInSeparateProcesses
*/
class PaperSizeArrayTest extends TestCase
{
private string $outfile = '';
Expand All @@ -36,7 +42,11 @@ public function testPaperSizeArray(): void
$sheet->setCellValue('A7', 'Lorem Ipsum');
$writer = new Dompdf($spreadsheet);
$this->outfile = File::temporaryFilename();
$writer->save($this->outfile);
if (PHP_VERSION_ID >= 80400) { // hopefully temporary
@$writer->save($this->outfile);
} else {
$writer->save($this->outfile);
}
$spreadsheet->disconnectWorksheets();
unset($spreadsheet);
$contents = file_get_contents($this->outfile);
Expand All @@ -56,7 +66,11 @@ public function testPaperSizeNotArray(): void
$sheet->setCellValue('A7', 'Lorem Ipsum');
$writer = new Dompdf($spreadsheet);
$this->outfile = File::temporaryFilename();
$writer->save($this->outfile);
if (PHP_VERSION_ID >= 80400) { // hopefully temporary
@$writer->save($this->outfile);
} else {
$writer->save($this->outfile);
}
$spreadsheet->disconnectWorksheets();
unset($spreadsheet);
$contents = file_get_contents($this->outfile);
Expand Down

0 comments on commit 3815843

Please sign in to comment.