From ee13533db3c06b3f256bcd96e0e75b5f5ce53aad Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Fri, 9 Oct 2020 14:31:16 +0200 Subject: [PATCH] Remove tests that include tcPDF and DomPDF libraries when running against PHP8, because neither library is yet PHP8-ready --- samples/Basic/26_Utf8.php | 10 ++++---- samples/Pdf/21b_Pdf.php | 24 +++++++++++-------- .../Functional/StreamTest.php | 13 +++++++--- .../PhpSpreadsheetTests/Helper/SampleTest.php | 10 ++++++++ 4 files changed, 40 insertions(+), 17 deletions(-) diff --git a/samples/Basic/26_Utf8.php b/samples/Basic/26_Utf8.php index 52a64509..52953251 100644 --- a/samples/Basic/26_Utf8.php +++ b/samples/Basic/26_Utf8.php @@ -12,10 +12,12 @@ $spreadsheet = $reader->load(__DIR__ . '/../templates/26template.xlsx'); // at this point, we could do some manipulations with the template, but we skip this step $helper->write($spreadsheet, __FILE__, ['Xlsx', 'Xls', 'Html']); -// Export to PDF (.pdf) -$helper->log('Write to PDF format'); -IOFactory::registerWriter('Pdf', \PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf::class); -$helper->write($spreadsheet, __FILE__, ['Pdf']); +if (\PHP_VERSION_ID < 80000) { + // Export to PDF (.pdf) + $helper->log('Write to PDF format'); + IOFactory::registerWriter('Pdf', \PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf::class); + $helper->write($spreadsheet, __FILE__, ['Pdf']); +} // Remove first two rows with field headers before exporting to CSV $helper->log('Removing first two heading rows for CSV export'); diff --git a/samples/Pdf/21b_Pdf.php b/samples/Pdf/21b_Pdf.php index c67ff3d2..6770b7c5 100644 --- a/samples/Pdf/21b_Pdf.php +++ b/samples/Pdf/21b_Pdf.php @@ -32,11 +32,13 @@ $spreadsheet->getActiveSheet()->setShowGridLines(false); $helper->log('Set orientation to landscape'); $spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE); -$helper->log('Write to Dompdf'); -$writer = new Dompdf($spreadsheet); -$filename = $helper->getFileName('21b_Pdf_dompdf.xlsx', 'pdf'); -$writer->setEditHtmlCallback('replaceBody'); -$writer->save($filename); +if (\PHP_VERSION_ID < 80000) { + $helper->log('Write to Dompdf'); + $writer = new Dompdf($spreadsheet); + $filename = $helper->getFileName('21b_Pdf_dompdf.xlsx', 'pdf'); + $writer->setEditHtmlCallback('replaceBody'); + $writer->save($filename); +} $helper->log('Write to Mpdf'); $writer = new Mpdf($spreadsheet); @@ -44,8 +46,10 @@ $filename = $helper->getFileName('21b_Pdf_mpdf.xlsx', 'pdf'); $writer->setEditHtmlCallback('replaceBody'); $writer->save($filename); -$helper->log('Write to Tcpdf'); -$writer = new Tcpdf($spreadsheet); -$filename = $helper->getFileName('21b_Pdf_tcpdf.xlsx', 'pdf'); -$writer->setEditHtmlCallback('replaceBody'); -$writer->save($filename); +if (\PHP_VERSION_ID < 80000) { + $helper->log('Write to Tcpdf'); + $writer = new Tcpdf($spreadsheet); + $filename = $helper->getFileName('21b_Pdf_tcpdf.xlsx', 'pdf'); + $writer->setEditHtmlCallback('replaceBody'); + $writer->save($filename); +} \ No newline at end of file diff --git a/tests/PhpSpreadsheetTests/Functional/StreamTest.php b/tests/PhpSpreadsheetTests/Functional/StreamTest.php index dcca6b8a..3ca01fc4 100644 --- a/tests/PhpSpreadsheetTests/Functional/StreamTest.php +++ b/tests/PhpSpreadsheetTests/Functional/StreamTest.php @@ -10,16 +10,23 @@ class StreamTest extends TestCase { public function providerFormats(): array { - return [ + $providerFormats = [ ['Xls'], ['Xlsx'], ['Ods'], ['Csv'], ['Html'], - ['Tcpdf'], - ['Dompdf'], ['Mpdf'], ]; + + if (\PHP_VERSION_ID < 80000) { + $providerFormats = array_merge( + $providerFormats, + [['Tcpdf'],['Dompdf']] + ); + } + + return $providerFormats; } /** diff --git a/tests/PhpSpreadsheetTests/Helper/SampleTest.php b/tests/PhpSpreadsheetTests/Helper/SampleTest.php index eb729dc9..369b205e 100644 --- a/tests/PhpSpreadsheetTests/Helper/SampleTest.php +++ b/tests/PhpSpreadsheetTests/Helper/SampleTest.php @@ -31,6 +31,16 @@ class SampleTest extends TestCase 'Chart/32_Chart_read_write_PDF.php', // Unfortunately JpGraph is not up to date for latest PHP and raise many warnings 'Chart/32_Chart_read_write_HTML.php', // idem ]; + // TCPDF and DomPDF libraries don't support PHP8 yet + if (\PHP_VERSION_ID >= 80000) { + $skipped = array_merge( + $skipped, + [ + 'Pdf/21_Pdf_Domdf.php', + 'Pdf/21_Pdf_TCPDF.php', + ] + ); + } // Unfortunately some tests are too long be ran with code-coverage // analysis on Travis, so we need to exclude them