Failed Conditions
Push — master ( d6a367...8799a0 )
by
unknown
16:08 queued 05:56
created

Php9Test::testAffectedByPhp9()   A

Complexity

Conditions 6
Paths 10

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 23
rs 9.0777
cc 6
nc 10
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\TestCase;
10
11
class Php9Test extends TestCase
12
{
13
    public function testAffectedByPhp9(): void
14
    {
15
        if (PHP_VERSION_ID >= 90000) {
16
            $this->expectException(ReaderException::class);
17
            $this->expectExceptionMessage('Php7.4 or Php8');
18
        }
19
        $dir = 'tests/data/Reader/CSV';
20
        $files = glob("$dir/*");
21
        self::assertNotFalse($files);
22
        $affected = [];
23
        foreach ($files as $file) {
24
            $base = basename($file);
25
            $encoding = 'UTF-8';
26
            if (str_contains($base, 'utf') && !str_contains($base, 'bom')) {
27
                $encoding = 'guess';
28
            }
29
            $result = Csv::affectedByPhp9($file, $encoding);
30
            if ($result) {
31
                $affected[] = $base;
32
            }
33
        }
34
        $expected = ['backslash.csv', 'escape.csv', 'linend.mac.csv'];
35
        self::assertSame($expected, $affected);
36
    }
37
}
38