diff --git a/.travis.yml b/.travis.yml index 6e29283c..28a9af0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,7 @@ php: - 7.2 - 7.3 - 7.4 + - nightly cache: directories: @@ -13,12 +14,16 @@ cache: before_script: # Deactivate xdebug - - phpenv config-rm xdebug.ini + - if [[ $TRAVIS_PHP_VERSION != nightly ]]; then phpenv config-rm xdebug.ini; fi + - if [[ $TRAVIS_PHP_VERSION == nightly ]]; then rm composer.lock; fi - composer install --ignore-platform-reqs script: - ./vendor/bin/phpunit --color=always --coverage-text +allow_failures: + - php: nightly + jobs: include: diff --git a/composer.json b/composer.json index 00b6fe9e..0fcb2556 100644 --- a/composer.json +++ b/composer.json @@ -39,7 +39,7 @@ ] }, "require": { - "php": "^7.2", + "php": "^7.2|^8.0", "ext-ctype": "*", "ext-dom": "*", "ext-gd": "*", @@ -54,8 +54,8 @@ "ext-zip": "*", "ext-zlib": "*", "maennchen/zipstream-php": "^2.1", - "markbaker/complex": "^1.4", - "markbaker/matrix": "^1.2", + "markbaker/complex": "^1.5|^2.0", + "markbaker/matrix": "^1.2|^2.0", "psr/simple-cache": "^1.0", "psr/http-client": "^1.0", "psr/http-factory": "^1.0" @@ -66,14 +66,14 @@ "jpgraph/jpgraph": "^4.0", "mpdf/mpdf": "^8.0", "phpcompatibility/php-compatibility": "^9.3", - "phpunit/phpunit": "^8.5", + "phpunit/phpunit": "^8.5|^9.3", "squizlabs/php_codesniffer": "^3.5", "tecnickcom/tcpdf": "^6.3" }, "suggest": { "mpdf/mpdf": "Option for rendering PDF with PDF Writer", - "dompdf/dompdf": "Option for rendering PDF with PDF Writer", - "tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer", + "dompdf/dompdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)", + "tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)", "jpgraph/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers" }, "autoload": { 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..ad2f609b 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); +} diff --git a/src/PhpSpreadsheet/Reader/Csv.php b/src/PhpSpreadsheet/Reader/Csv.php index db2b50b9..d6eb16b0 100644 --- a/src/PhpSpreadsheet/Reader/Csv.php +++ b/src/PhpSpreadsheet/Reader/Csv.php @@ -523,6 +523,7 @@ class Csv extends BaseReader // Attempt to guess mimetype $type = mime_content_type($pFilename); $supportedTypes = [ + 'application/csv', 'text/csv', 'text/plain', 'inode/x-empty', diff --git a/tests/PhpSpreadsheetTests/Functional/StreamTest.php b/tests/PhpSpreadsheetTests/Functional/StreamTest.php index dcca6b8a..03f9a2d9 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 diff --git a/tests/PhpSpreadsheetTests/Writer/Xlsx/LocaleFloatsTest.php b/tests/PhpSpreadsheetTests/Writer/Xlsx/LocaleFloatsTest.php index 81d4a777..83defb7b 100644 --- a/tests/PhpSpreadsheetTests/Writer/Xlsx/LocaleFloatsTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Xlsx/LocaleFloatsTest.php @@ -54,6 +54,7 @@ class LocaleFloatsTest extends TestCase preg_match('/(?:double|float)\(([^\)]+)\)/mui', ob_get_clean(), $matches); self::assertArrayHasKey(1, $matches); $actual = $matches[1]; - self::assertEquals('1,1', $actual); + // From PHP8, https://wiki.php.net/rfc/locale_independent_float_to_string applies + self::assertEquals((\PHP_VERSION_ID < 80000) ? '1,1' : '1.1', $actual); } } diff --git a/tests/PhpSpreadsheetTests/Writer/Xlsx/UnparsedDataCloneTest.php b/tests/PhpSpreadsheetTests/Writer/Xlsx/UnparsedDataCloneTest.php index d2afb423..660e40fe 100644 --- a/tests/PhpSpreadsheetTests/Writer/Xlsx/UnparsedDataCloneTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Xlsx/UnparsedDataCloneTest.php @@ -5,6 +5,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Writer\Xlsx; use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Shared\File; use PHPUnit\Framework\TestCase; +use ZipArchive; class UnparsedDataCloneTest extends TestCase { @@ -34,19 +35,20 @@ class UnparsedDataCloneTest extends TestCase $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet); $writer->save($resultFilename); $dupname = 'Unable to open saved file'; - $zip = zip_open($resultFilename); - if (is_resource($zip)) { + + $zip = new ZipArchive(); + if ($zip->open($resultFilename) !== false) { $names = []; $dupname = ''; - while ($zip_entry = zip_read($zip)) { - $zipname = zip_entry_name($zip_entry); - if (in_array($zipname, $names)) { - $dupname .= "$zipname,"; + for ($index = 0; $index < $zip->numFiles; ++$index) { + $filename = $zip->getNameIndex($index); + if (in_array($filename, $names)) { + $dupname .= "$filename,"; } else { - $names[] = $zipname; + $names[] = $filename; } } - zip_close($zip); + $zip->close(); } unlink($resultFilename); self::assertEquals('', $dupname);