PhpSpreadsheet/tests/PhpSpreadsheetTests/Functional/StreamTest.php

51 lines
1.4 KiB
PHP
Raw Normal View History

2020-05-16 11:12:28 +00:00
<?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 = [
2020-05-16 11:12:28 +00:00
['Xls'],
['Xlsx'],
['Ods'],
['Csv'],
['Html'],
['Mpdf'],
];
if (\PHP_VERSION_ID < 80000) {
$providerFormats = array_merge(
$providerFormats,
2020-10-09 14:08:20 +00:00
[['Tcpdf'], ['Dompdf']]
);
}
return $providerFormats;
2020-05-16 11:12:28 +00:00
}
/**
* @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+');
self::assertSame(0, fstat($stream)['size']);
$writer->save($stream);
self::assertIsResource($stream, 'should not close the stream for further usage out of PhpSpreadsheet');
self::assertGreaterThan(0, fstat($stream)['size'], 'something should have been written to the stream');
self::assertGreaterThan(0, ftell($stream), 'should not be rewinded, because not all streams support it');
}
}