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.2
- 7.3 - 7.3
- 7.4 - 7.4
- nightly
cache: cache:
directories: directories:
@ -13,12 +14,16 @@ cache:
before_script: before_script:
# Deactivate xdebug # 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 - composer install --ignore-platform-reqs
script: script:
- ./vendor/bin/phpunit --color=always --coverage-text - ./vendor/bin/phpunit --color=always --coverage-text
allow_failures:
- php: nightly
jobs: jobs:
include: include:

View File

@ -39,7 +39,7 @@
] ]
}, },
"require": { "require": {
"php": "^7.2", "php": "^7.2|^8.0",
"ext-ctype": "*", "ext-ctype": "*",
"ext-dom": "*", "ext-dom": "*",
"ext-gd": "*", "ext-gd": "*",
@ -54,8 +54,8 @@
"ext-zip": "*", "ext-zip": "*",
"ext-zlib": "*", "ext-zlib": "*",
"maennchen/zipstream-php": "^2.1", "maennchen/zipstream-php": "^2.1",
"markbaker/complex": "^1.4", "markbaker/complex": "^1.5|^2.0",
"markbaker/matrix": "^1.2", "markbaker/matrix": "^1.2|^2.0",
"psr/simple-cache": "^1.0", "psr/simple-cache": "^1.0",
"psr/http-client": "^1.0", "psr/http-client": "^1.0",
"psr/http-factory": "^1.0" "psr/http-factory": "^1.0"
@ -66,14 +66,14 @@
"jpgraph/jpgraph": "^4.0", "jpgraph/jpgraph": "^4.0",
"mpdf/mpdf": "^8.0", "mpdf/mpdf": "^8.0",
"phpcompatibility/php-compatibility": "^9.3", "phpcompatibility/php-compatibility": "^9.3",
"phpunit/phpunit": "^8.5", "phpunit/phpunit": "^8.5|^9.3",
"squizlabs/php_codesniffer": "^3.5", "squizlabs/php_codesniffer": "^3.5",
"tecnickcom/tcpdf": "^6.3" "tecnickcom/tcpdf": "^6.3"
}, },
"suggest": { "suggest": {
"mpdf/mpdf": "Option for rendering PDF with PDF Writer", "mpdf/mpdf": "Option for rendering PDF with PDF Writer",
"dompdf/dompdf": "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", "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" "jpgraph/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers"
}, },
"autoload": { "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 // at this point, we could do some manipulations with the template, but we skip this step
$helper->write($spreadsheet, __FILE__, ['Xlsx', 'Xls', 'Html']); $helper->write($spreadsheet, __FILE__, ['Xlsx', 'Xls', 'Html']);
// Export to PDF (.pdf) if (\PHP_VERSION_ID < 80000) {
$helper->log('Write to PDF format'); // Export to PDF (.pdf)
IOFactory::registerWriter('Pdf', \PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf::class); $helper->log('Write to PDF format');
$helper->write($spreadsheet, __FILE__, ['Pdf']); 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 // Remove first two rows with field headers before exporting to CSV
$helper->log('Removing first two heading rows for CSV export'); $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'); $helper->log('Set orientation to landscape');
$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE); $spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
$helper->log('Write to Dompdf'); if (\PHP_VERSION_ID < 80000) {
$writer = new Dompdf($spreadsheet); $helper->log('Write to Dompdf');
$filename = $helper->getFileName('21b_Pdf_dompdf.xlsx', 'pdf'); $writer = new Dompdf($spreadsheet);
$writer->setEditHtmlCallback('replaceBody'); $filename = $helper->getFileName('21b_Pdf_dompdf.xlsx', 'pdf');
$writer->save($filename); $writer->setEditHtmlCallback('replaceBody');
$writer->save($filename);
}
$helper->log('Write to Mpdf'); $helper->log('Write to Mpdf');
$writer = new Mpdf($spreadsheet); $writer = new Mpdf($spreadsheet);
@ -44,8 +46,10 @@ $filename = $helper->getFileName('21b_Pdf_mpdf.xlsx', 'pdf');
$writer->setEditHtmlCallback('replaceBody'); $writer->setEditHtmlCallback('replaceBody');
$writer->save($filename); $writer->save($filename);
$helper->log('Write to Tcpdf'); if (\PHP_VERSION_ID < 80000) {
$writer = new Tcpdf($spreadsheet); $helper->log('Write to Tcpdf');
$filename = $helper->getFileName('21b_Pdf_tcpdf.xlsx', 'pdf'); $writer = new Tcpdf($spreadsheet);
$writer->setEditHtmlCallback('replaceBody'); $filename = $helper->getFileName('21b_Pdf_tcpdf.xlsx', 'pdf');
$writer->save($filename); $writer->setEditHtmlCallback('replaceBody');
$writer->save($filename);
}

View File

@ -523,6 +523,7 @@ class Csv extends BaseReader
// Attempt to guess mimetype // Attempt to guess mimetype
$type = mime_content_type($pFilename); $type = mime_content_type($pFilename);
$supportedTypes = [ $supportedTypes = [
'application/csv',
'text/csv', 'text/csv',
'text/plain', 'text/plain',
'inode/x-empty', 'inode/x-empty',

View File

@ -10,16 +10,23 @@ class StreamTest extends TestCase
{ {
public function providerFormats(): array public function providerFormats(): array
{ {
return [ $providerFormats = [
['Xls'], ['Xls'],
['Xlsx'], ['Xlsx'],
['Ods'], ['Ods'],
['Csv'], ['Csv'],
['Html'], ['Html'],
['Tcpdf'],
['Dompdf'],
['Mpdf'], ['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_PDF.php', // Unfortunately JpGraph is not up to date for latest PHP and raise many warnings
'Chart/32_Chart_read_write_HTML.php', // idem '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 // Unfortunately some tests are too long be ran with code-coverage
// analysis on Travis, so we need to exclude them // 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); preg_match('/(?:double|float)\(([^\)]+)\)/mui', ob_get_clean(), $matches);
self::assertArrayHasKey(1, $matches); self::assertArrayHasKey(1, $matches);
$actual = $matches[1]; $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\Settings;
use PhpOffice\PhpSpreadsheet\Shared\File; use PhpOffice\PhpSpreadsheet\Shared\File;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use ZipArchive;
class UnparsedDataCloneTest extends TestCase class UnparsedDataCloneTest extends TestCase
{ {
@ -34,19 +35,20 @@ class UnparsedDataCloneTest extends TestCase
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet); $writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
$writer->save($resultFilename); $writer->save($resultFilename);
$dupname = 'Unable to open saved file'; $dupname = 'Unable to open saved file';
$zip = zip_open($resultFilename);
if (is_resource($zip)) { $zip = new ZipArchive();
if ($zip->open($resultFilename) !== false) {
$names = []; $names = [];
$dupname = ''; $dupname = '';
while ($zip_entry = zip_read($zip)) { for ($index = 0; $index < $zip->numFiles; ++$index) {
$zipname = zip_entry_name($zip_entry); $filename = $zip->getNameIndex($index);
if (in_array($zipname, $names)) { if (in_array($filename, $names)) {
$dupname .= "$zipname,"; $dupname .= "$filename,";
} else { } else {
$names[] = $zipname; $names[] = $filename;
} }
} }
zip_close($zip); $zip->close();
} }
unlink($resultFilename); unlink($resultFilename);
self::assertEquals('', $dupname); self::assertEquals('', $dupname);