Completed
Push — develop ( dfcab0...962367 )
by Adrien
28:38
created

HtmlTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 37
rs 10
c 2
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testCsvWithAngleBracket() 0 5 1
A providerCanReadVerySmallFile() 0 9 1
A testCanReadVerySmallFile() 0 10 1
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Reader;
4
5
use PhpOffice\PhpSpreadsheet\Reader\Html;
6
use PHPUnit\Framework\TestCase;
7
8
class HtmlTest extends TestCase
9
{
10
    public function testCsvWithAngleBracket()
11
    {
12
        $filename = __DIR__ . '/../../data/Reader/HTML/csv_with_angle_bracket.csv';
13
        $reader = new Html();
14
        self::assertFalse($reader->canRead($filename));
15
    }
16
17
    public function providerCanReadVerySmallFile()
18
    {
19
        $padding = str_repeat('a', 2048);
20
21
        return [
22
            [true, ' <html> ' . $padding . ' </html> '],
23
            [true, ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html>' . $padding . '</html>'],
24
            [true, '<html></html>'],
25
            [false, ''],
26
        ];
27
    }
28
29
    /**
30
     * @dataProvider providerCanReadVerySmallFile
31
     *
32
     * @param bool $expected
33
     * @param string $content
34
     */
35
    public function testCanReadVerySmallFile($expected, $content)
36
    {
37
        $filename = tempnam(sys_get_temp_dir(), 'html');
38
        file_put_contents($filename, $content);
1 ignored issue
show
Bug introduced by
It seems like $filename can also be of type false; however, parameter $filename of file_put_contents() does only seem to accept 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

38
        file_put_contents(/** @scrutinizer ignore-type */ $filename, $content);
Loading history...
39
40
        $reader = new Html();
41
        $actual = $reader->canRead($filename);
1 ignored issue
show
Bug introduced by
It seems like $filename can also be of type false; however, parameter $pFilename of PhpOffice\PhpSpreadsheet\Reader\Html::canRead() does only seem to accept 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

41
        $actual = $reader->canRead(/** @scrutinizer ignore-type */ $filename);
Loading history...
42
        unlink($filename);
1 ignored issue
show
Bug introduced by
It seems like $filename can also be of type false; however, parameter $filename of unlink() does only seem to accept 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

42
        unlink(/** @scrutinizer ignore-type */ $filename);
Loading history...
43
44
        self::assertSame($expected, $actual);
45
    }
46
}
47