diff --git a/.travis.yml b/.travis.yml index 77eed44148..d8e0c16816 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 00b6fe9e0b..0fcb2556dd 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 52a64509b3..52953251c8 100644 --- a/samples/Basic/26_Utf8.php +++ b/samples/Basic/26_Utf8.php @@ -12,10 +12,12 @@ // 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 c67ff3d29d..ad2f609b7c 100644 --- a/samples/Pdf/21b_Pdf.php +++ b/samples/Pdf/21b_Pdf.php @@ -32,11 +32,13 @@ function replaceBody(string $html): string $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 @@ function replaceBody(string $html): string $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 db2b50b928..d6eb16b0af 100644 --- a/src/PhpSpreadsheet/Reader/Csv.php +++ b/src/PhpSpreadsheet/Reader/Csv.php @@ -523,6 +523,7 @@ public function canRead($pFilename) // 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 dcca6b8a07..03f9a2d92a 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 eb729dc9a9..369b205e08 100644 --- a/tests/PhpSpreadsheetTests/Helper/SampleTest.php +++ b/tests/PhpSpreadsheetTests/Helper/SampleTest.php @@ -31,6 +31,16 @@ public function providerSample() '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 81d4a77736..83defb7b11 100644 --- a/tests/PhpSpreadsheetTests/Writer/Xlsx/LocaleFloatsTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Xlsx/LocaleFloatsTest.php @@ -54,6 +54,7 @@ public function testLocaleFloatsCorrectlyConvertedByWriter(): void 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 d2afb4239c..660e40feff 100644 --- a/tests/PhpSpreadsheetTests/Writer/Xlsx/UnparsedDataCloneTest.php +++ b/tests/PhpSpreadsheetTests/Writer/Xlsx/UnparsedDataCloneTest.php @@ -5,6 +5,7 @@ use PhpOffice\PhpSpreadsheet\Settings; use PhpOffice\PhpSpreadsheet\Shared\File; use PHPUnit\Framework\TestCase; +use ZipArchive; class UnparsedDataCloneTest extends TestCase { @@ -34,19 +35,20 @@ public function testLoadSaveXlsxWithUnparsedDataClone(): void $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);