Skip to content

Commit 591f7cf

Browse files
authored
Merge pull request #1675 from PHPOffice/PHP8-Testing
Php8 testing
2 parents c3d1ce5 + 2d93c36 commit 591f7cf

File tree

9 files changed

+65
-33
lines changed

9 files changed

+65
-33
lines changed

.travis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ php:
55
- 7.2
66
- 7.3
77
- 7.4
8+
- nightly
89

910
cache:
1011
directories:
@@ -13,12 +14,16 @@ cache:
1314

1415
before_script:
1516
# Deactivate xdebug
16-
- phpenv config-rm xdebug.ini
17+
- if [[ $TRAVIS_PHP_VERSION != nightly ]]; then phpenv config-rm xdebug.ini; fi
18+
- if [[ $TRAVIS_PHP_VERSION == nightly ]]; then rm composer.lock; fi
1719
- composer install --ignore-platform-reqs
1820

1921
script:
2022
- ./vendor/bin/phpunit --color=always --coverage-text
2123

24+
allow_failures:
25+
- php: nightly
26+
2227
jobs:
2328
include:
2429

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
]
4040
},
4141
"require": {
42-
"php": "^7.2",
42+
"php": "^7.2|^8.0",
4343
"ext-ctype": "*",
4444
"ext-dom": "*",
4545
"ext-gd": "*",
@@ -54,8 +54,8 @@
5454
"ext-zip": "*",
5555
"ext-zlib": "*",
5656
"maennchen/zipstream-php": "^2.1",
57-
"markbaker/complex": "^1.4",
58-
"markbaker/matrix": "^1.2",
57+
"markbaker/complex": "^1.5|^2.0",
58+
"markbaker/matrix": "^1.2|^2.0",
5959
"psr/simple-cache": "^1.0",
6060
"psr/http-client": "^1.0",
6161
"psr/http-factory": "^1.0"
@@ -66,14 +66,14 @@
6666
"jpgraph/jpgraph": "^4.0",
6767
"mpdf/mpdf": "^8.0",
6868
"phpcompatibility/php-compatibility": "^9.3",
69-
"phpunit/phpunit": "^8.5",
69+
"phpunit/phpunit": "^8.5|^9.3",
7070
"squizlabs/php_codesniffer": "^3.5",
7171
"tecnickcom/tcpdf": "^6.3"
7272
},
7373
"suggest": {
7474
"mpdf/mpdf": "Option for rendering PDF with PDF Writer",
75-
"dompdf/dompdf": "Option for rendering PDF with PDF Writer",
76-
"tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer",
75+
"dompdf/dompdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)",
76+
"tecnickcom/tcpdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)",
7777
"jpgraph/jpgraph": "Option for rendering charts, or including charts with PDF or HTML Writers"
7878
},
7979
"autoload": {

samples/Basic/26_Utf8.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
// at this point, we could do some manipulations with the template, but we skip this step
1313
$helper->write($spreadsheet, __FILE__, ['Xlsx', 'Xls', 'Html']);
1414

15-
// Export to PDF (.pdf)
16-
$helper->log('Write to PDF format');
17-
IOFactory::registerWriter('Pdf', \PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf::class);
18-
$helper->write($spreadsheet, __FILE__, ['Pdf']);
15+
if (\PHP_VERSION_ID < 80000) {
16+
// Export to PDF (.pdf)
17+
$helper->log('Write to PDF format');
18+
IOFactory::registerWriter('Pdf', \PhpOffice\PhpSpreadsheet\Writer\Pdf\Dompdf::class);
19+
$helper->write($spreadsheet, __FILE__, ['Pdf']);
20+
}
1921

2022
// Remove first two rows with field headers before exporting to CSV
2123
$helper->log('Removing first two heading rows for CSV export');

samples/Pdf/21b_Pdf.php

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,24 @@ function replaceBody(string $html): string
3232
$helper->log('Set orientation to landscape');
3333
$spreadsheet->getActiveSheet()->getPageSetup()->setOrientation(PageSetup::ORIENTATION_LANDSCAPE);
3434

35-
$helper->log('Write to Dompdf');
36-
$writer = new Dompdf($spreadsheet);
37-
$filename = $helper->getFileName('21b_Pdf_dompdf.xlsx', 'pdf');
38-
$writer->setEditHtmlCallback('replaceBody');
39-
$writer->save($filename);
35+
if (\PHP_VERSION_ID < 80000) {
36+
$helper->log('Write to Dompdf');
37+
$writer = new Dompdf($spreadsheet);
38+
$filename = $helper->getFileName('21b_Pdf_dompdf.xlsx', 'pdf');
39+
$writer->setEditHtmlCallback('replaceBody');
40+
$writer->save($filename);
41+
}
4042

4143
$helper->log('Write to Mpdf');
4244
$writer = new Mpdf($spreadsheet);
4345
$filename = $helper->getFileName('21b_Pdf_mpdf.xlsx', 'pdf');
4446
$writer->setEditHtmlCallback('replaceBody');
4547
$writer->save($filename);
4648

47-
$helper->log('Write to Tcpdf');
48-
$writer = new Tcpdf($spreadsheet);
49-
$filename = $helper->getFileName('21b_Pdf_tcpdf.xlsx', 'pdf');
50-
$writer->setEditHtmlCallback('replaceBody');
51-
$writer->save($filename);
49+
if (\PHP_VERSION_ID < 80000) {
50+
$helper->log('Write to Tcpdf');
51+
$writer = new Tcpdf($spreadsheet);
52+
$filename = $helper->getFileName('21b_Pdf_tcpdf.xlsx', 'pdf');
53+
$writer->setEditHtmlCallback('replaceBody');
54+
$writer->save($filename);
55+
}

src/PhpSpreadsheet/Reader/Csv.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ public function canRead($pFilename)
523523
// Attempt to guess mimetype
524524
$type = mime_content_type($pFilename);
525525
$supportedTypes = [
526+
'application/csv',
526527
'text/csv',
527528
'text/plain',
528529
'inode/x-empty',

tests/PhpSpreadsheetTests/Functional/StreamTest.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,23 @@ class StreamTest extends TestCase
1010
{
1111
public function providerFormats(): array
1212
{
13-
return [
13+
$providerFormats = [
1414
['Xls'],
1515
['Xlsx'],
1616
['Ods'],
1717
['Csv'],
1818
['Html'],
19-
['Tcpdf'],
20-
['Dompdf'],
2119
['Mpdf'],
2220
];
21+
22+
if (\PHP_VERSION_ID < 80000) {
23+
$providerFormats = array_merge(
24+
$providerFormats,
25+
[['Tcpdf'], ['Dompdf']]
26+
);
27+
}
28+
29+
return $providerFormats;
2330
}
2431

2532
/**

tests/PhpSpreadsheetTests/Helper/SampleTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ public function providerSample()
3131
'Chart/32_Chart_read_write_PDF.php', // Unfortunately JpGraph is not up to date for latest PHP and raise many warnings
3232
'Chart/32_Chart_read_write_HTML.php', // idem
3333
];
34+
// TCPDF and DomPDF libraries don't support PHP8 yet
35+
if (\PHP_VERSION_ID >= 80000) {
36+
$skipped = array_merge(
37+
$skipped,
38+
[
39+
'Pdf/21_Pdf_Domdf.php',
40+
'Pdf/21_Pdf_TCPDF.php',
41+
]
42+
);
43+
}
3444

3545
// Unfortunately some tests are too long be ran with code-coverage
3646
// analysis on Travis, so we need to exclude them

tests/PhpSpreadsheetTests/Writer/Xlsx/LocaleFloatsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function testLocaleFloatsCorrectlyConvertedByWriter(): void
5454
preg_match('/(?:double|float)\(([^\)]+)\)/mui', ob_get_clean(), $matches);
5555
self::assertArrayHasKey(1, $matches);
5656
$actual = $matches[1];
57-
self::assertEquals('1,1', $actual);
57+
// From PHP8, https://wiki.php.net/rfc/locale_independent_float_to_string applies
58+
self::assertEquals((\PHP_VERSION_ID < 80000) ? '1,1' : '1.1', $actual);
5859
}
5960
}

tests/PhpSpreadsheetTests/Writer/Xlsx/UnparsedDataCloneTest.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use PhpOffice\PhpSpreadsheet\Settings;
66
use PhpOffice\PhpSpreadsheet\Shared\File;
77
use PHPUnit\Framework\TestCase;
8+
use ZipArchive;
89

910
class UnparsedDataCloneTest extends TestCase
1011
{
@@ -34,19 +35,20 @@ public function testLoadSaveXlsxWithUnparsedDataClone(): void
3435
$writer = new \PhpOffice\PhpSpreadsheet\Writer\Xlsx($spreadsheet);
3536
$writer->save($resultFilename);
3637
$dupname = 'Unable to open saved file';
37-
$zip = zip_open($resultFilename);
38-
if (is_resource($zip)) {
38+
39+
$zip = new ZipArchive();
40+
if ($zip->open($resultFilename) !== false) {
3941
$names = [];
4042
$dupname = '';
41-
while ($zip_entry = zip_read($zip)) {
42-
$zipname = zip_entry_name($zip_entry);
43-
if (in_array($zipname, $names)) {
44-
$dupname .= "$zipname,";
43+
for ($index = 0; $index < $zip->numFiles; ++$index) {
44+
$filename = $zip->getNameIndex($index);
45+
if (in_array($filename, $names)) {
46+
$dupname .= "$filename,";
4547
} else {
46-
$names[] = $zipname;
48+
$names[] = $filename;
4749
}
4850
}
49-
zip_close($zip);
51+
$zip->close();
5052
}
5153
unlink($resultFilename);
5254
self::assertEquals('', $dupname);

0 commit comments

Comments
 (0)