Merge pull request #1675 from PHPOffice/PHP8-Testing

Php8 testing
This commit is contained in:
Adrien Crivelli 2020-10-11 18:34:42 +09:00 committed by GitHub
commit 591f7cf301
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 65 additions and 33 deletions

View File

@ -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:

View File

@ -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": {

View File

@ -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']);
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');

View File

@ -32,11 +32,13 @@ $spreadsheet->getActiveSheet()->setShowGridLines(false);
$helper->log('Set orientation to landscape');
$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
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);
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);
}

View File

@ -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',

View File

@ -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;
}
/**

View File

@ -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

View File

@ -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);
}
}

View File

@ -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);