Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/Functional/StreamTest.php
oleibman 8258919d72 Phpstan Differences from Php7 to Php8 (#2631)
These changes were already implemented as PR #2428. They were, alas, regressed by PR #2585. If at first you don't succeed ...

As configured, Phpstan running under Php7 reports no errors. However, running under Php8, it reports 100 (!) errors. The vast majority of these are due to two reasons:
- renaming parameters in Php builtin functions in preparation for named parameters.
- using the new class GdImage rather than type resource as the argument type for many image-based functions.

Regardless of the cause, this will be a problem sooner or later. This PR is an attempt to get ahead of that problem. For source members, it tweaks only the Phpstan configuration files, without changing any PhpSpreadsheet code. For the small number of test members involved, the code is fixed. Php7 and Php8 both report no errors with this configuration.

Because this involves no changes to code, and because Phpstan baseline is a common cause of merge difficulties, I will probably merge this in a day or two, more quickly than I customarily do.
2022-03-01 01:53:12 -08:00

61 lines
1.7 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Functional;
use PhpOffice\PhpSpreadsheet\IOFactory;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;
class StreamTest extends TestCase
{
public function providerFormats(): array
{
$providerFormats = [
['Xls'],
['Xlsx'],
['Ods'],
['Csv'],
['Html'],
['Mpdf'],
];
if (\PHP_VERSION_ID < 80000) {
$providerFormats = array_merge(
$providerFormats,
[['Tcpdf'], ['Dompdf']]
);
}
return $providerFormats;
}
/**
* @dataProvider providerFormats
*/
public function testAllWritersCanWriteToStream(string $format): void
{
$spreadsheet = new Spreadsheet();
$spreadsheet->getActiveSheet()->setCellValue('A1', 'foo');
$writer = IOFactory::createWriter($spreadsheet, $format);
$stream = fopen('php://memory', 'wb+');
$stat = ($stream === false) ? false : fstat($stream);
if ($stream === false || $stat === false) {
self::fail('fopen or fstat failed');
} else {
self::assertSame(0, $stat['size']);
$writer->save($stream);
self::assertIsResource($stream, 'should not close the stream for further usage out of PhpSpreadsheet');
$stat = fstat($stream);
if ($stat === false) {
self::fail('fstat failed');
} else {
self::assertGreaterThan(0, $stat['size'], 'something should have been written to the stream');
}
self::assertGreaterThan(0, ftell($stream), 'should not be rewinded, because not all streams support it');
}
}
}