1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Functional; |
6
|
|
|
|
7
|
|
|
use PhpOffice\PhpSpreadsheet\IOFactory; |
8
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Not clear that Dompdf will be Php8.4 compatible in time. |
13
|
|
|
* Run in separate process and add version test till it is ready. |
14
|
|
|
* |
15
|
|
|
* @runTestsInSeparateProcesses |
16
|
|
|
*/ |
17
|
|
|
class StreamTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
public static function providerFormats(): array |
20
|
|
|
{ |
21
|
|
|
$providerFormats = [ |
22
|
|
|
['Xls'], |
23
|
|
|
['Xlsx'], |
24
|
|
|
['Ods'], |
25
|
|
|
['Csv'], |
26
|
|
|
['Html'], |
27
|
|
|
['Mpdf'], |
28
|
|
|
['Dompdf'], |
29
|
|
|
['Tcpdf'], |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
return $providerFormats; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @dataProvider providerFormats |
37
|
|
|
*/ |
38
|
|
|
public function testAllWritersCanWriteToStream(string $format): void |
39
|
|
|
{ |
40
|
|
|
$spreadsheet = new Spreadsheet(); |
41
|
|
|
$spreadsheet->getActiveSheet()->setCellValue('A1', 'foo'); |
42
|
|
|
$writer = IOFactory::createWriter($spreadsheet, $format); |
43
|
|
|
|
44
|
|
|
$stream = fopen('php://memory', 'wb+'); |
45
|
|
|
$stat = ($stream === false) ? false : fstat($stream); |
46
|
|
|
if ($stream === false || $stat === false) { |
47
|
|
|
self::fail('fopen or fstat failed'); |
48
|
|
|
} else { |
49
|
|
|
self::assertSame(0, $stat['size']); |
50
|
|
|
|
51
|
|
|
if ($format === 'Dompdf' && PHP_VERSION_ID >= 80400) { |
52
|
|
|
@$writer->save($stream); |
|
|
|
|
53
|
|
|
} else { |
54
|
|
|
$writer->save($stream); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
self::assertIsResource($stream, 'should not close the stream for further usage out of PhpSpreadsheet'); |
58
|
|
|
$stat = fstat($stream); |
59
|
|
|
if ($stat === false) { |
60
|
|
|
self::fail('fstat failed'); |
61
|
|
|
} else { |
62
|
|
|
self::assertGreaterThan(0, $stat['size'], 'something should have been written to the stream'); |
63
|
|
|
} |
64
|
|
|
self::assertGreaterThan(0, ftell($stream), 'should not be rewinded, because not all streams support it'); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.