mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-21 19:23:49 +00:00
ec4098c8fd
While we might never be able to have 100% of our code strict, we can at the very least do it for all of our tests. This ensures that our tests are using our API with the types as intended by the test author, and not silently be cast to what our API requires.
58 lines
1.6 KiB
PHP
58 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Functional;
|
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class StreamTest extends TestCase
|
|
{
|
|
public static function providerFormats(): array
|
|
{
|
|
$providerFormats = [
|
|
['Xls'],
|
|
['Xlsx'],
|
|
['Ods'],
|
|
['Csv'],
|
|
['Html'],
|
|
['Mpdf'],
|
|
['Dompdf'],
|
|
['Tcpdf'],
|
|
];
|
|
|
|
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');
|
|
}
|
|
}
|
|
}
|