Completed
Push — master ( 4b5c92...896769 )
by Adrien
16:06 queued 09:43
created

StreamTest::providerFormats()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 11
rs 9.9666
c 1
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Functional;
4
5
use PhpOffice\PhpSpreadsheet\IOFactory;
6
use PhpOffice\PhpSpreadsheet\Spreadsheet;
7
use PHPUnit\Framework\TestCase;
8
9
class StreamTest extends TestCase
10
{
11
    public function providerFormats(): array
12
    {
13
        return [
14
            ['Xls'],
15
            ['Xlsx'],
16
            ['Ods'],
17
            ['Csv'],
18
            ['Html'],
19
            ['Tcpdf'],
20
            ['Dompdf'],
21
            ['Mpdf'],
22
        ];
23
    }
24
25
    /**
26
     * @dataProvider providerFormats
27
     *
28
     * @param string $format
29
     */
30
    public function testAllWritersCanWriteToStream(string $format): void
31
    {
32
        $spreadsheet = new Spreadsheet();
33
        $spreadsheet->getActiveSheet()->setCellValue('A1', 'foo');
34
        $writer = IOFactory::createWriter($spreadsheet, $format);
35
36
        $stream = fopen('php://memory', 'wb+');
37
        self::assertSame(0, fstat($stream)['size']);
1 ignored issue
show
Bug introduced by
It seems like $stream can also be of type false; however, parameter $handle of fstat() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

37
        self::assertSame(0, fstat(/** @scrutinizer ignore-type */ $stream)['size']);
Loading history...
38
39
        $writer->save($stream);
1 ignored issue
show
Bug introduced by
It seems like $stream can also be of type false; however, parameter $pFilename of PhpOffice\PhpSpreadsheet\Writer\IWriter::save() does only seem to accept resource|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

39
        $writer->save(/** @scrutinizer ignore-type */ $stream);
Loading history...
40
41
        self::assertIsResource($stream, 'should not close the stream for further usage out of PhpSpreadsheet');
42
        self::assertGreaterThan(0, fstat($stream)['size'], 'something should have been written to the stream');
43
        self::assertGreaterThan(0, ftell($stream), 'should not be rewinded, because not all streams support it');
1 ignored issue
show
Bug introduced by
It seems like $stream can also be of type false; however, parameter $handle of ftell() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

43
        self::assertGreaterThan(0, ftell(/** @scrutinizer ignore-type */ $stream), 'should not be rewinded, because not all streams support it');
Loading history...
44
    }
45
}
46