Completed
Push — master ( 0e8d0b...b4cd42 )
by
unknown
43s queued 34s
created

Php9Test::providerVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpOffice\PhpSpreadsheetTests\Reader\Csv;
6
7
use PhpOffice\PhpSpreadsheet\Reader\Csv;
8
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
9
use PHPUnit\Framework\Attributes\DataProvider;
10
use PHPUnit\Framework\TestCase;
11
12
class Php9Test extends TestCase
13
{
14
    #[DataProvider('providerVersion')]
15
    public function testAffectedByPhp9(int $version): void
16
    {
17
        if ($version >= 90000) {
18
            $this->expectException(ReaderException::class);
19
            $this->expectExceptionMessage('Php7.4 or Php8');
20
        }
21
        $dir = 'tests/data/Reader/CSV';
22
        $files = glob("$dir/*");
23
        self::assertNotFalse($files);
24
        $affected = [];
25
        foreach ($files as $file) {
26
            $base = basename($file);
27
            $encoding = 'UTF-8';
28
            if (str_contains($base, 'utf') && !str_contains($base, 'bom')) {
29
                $encoding = 'guess';
30
            }
31
            $result = Csv::affectedByPhp9($file, $encoding, version: $version);
32
            if ($result) {
33
                $affected[] = $base;
34
            }
35
        }
36
        $expected = ['backslash.csv', 'escape.csv', 'linend.mac.csv'];
37
        self::assertSame($expected, $affected);
38
    }
39
40
    public static function providerVersion(): array
41
    {
42
        return [
43
            [PHP_VERSION_ID],
44
            [90000],
45
        ];
46
    }
47
}
48