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

Php9Test   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 18
c 1
b 0
f 0
dl 0
loc 25
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testAffectedByPhp9() 0 23 6
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