Completed
Push — master ( 8ca7bf...84e03d )
by Adrien
08:54
created

CodePageTest   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
dl 0
loc 60
rs 10
c 1
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A providerCodePage() 0 3 1
A testCodePageNumberToName() 0 4 1
A testNumberToNameWithInvalidCodePage() 0 12 2
A testCoverage() 0 13 4
A testNumberToNameWithUnsupportedCodePage() 0 12 2
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Shared;
4
5
use PhpOffice\PhpSpreadsheet\Exception;
6
use PhpOffice\PhpSpreadsheet\Shared\CodePage;
7
use PHPUnit\Framework\TestCase;
8
9
class CodePageTest extends TestCase
10
{
11
    /**
12
     * @dataProvider providerCodePage
13
     *
14
     * @param mixed $expectedResult
15
     */
16
    public function testCodePageNumberToName($expectedResult, ...$args): void
17
    {
18
        $result = CodePage::numberToName(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $codePage of PhpOffice\PhpSpreadsheet...odePage::numberToName() does not expect variable arguments. ( Ignorable by Annotation )

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

18
        $result = CodePage::numberToName(/** @scrutinizer ignore-type */ ...$args);
Loading history...
19
        self::assertEquals($expectedResult, $result);
20
    }
21
22
    public function providerCodePage()
23
    {
24
        return require 'tests/data/Shared/CodePage.php';
25
    }
26
27
    public function testCoverage(): void
28
    {
29
        $covered = [];
30
        $expected = CodePage::getEncodings();
31
        foreach ($expected as $key => $val) {
32
            $covered[$key] = 0;
33
        }
34
        $tests = $this->providerCodePage();
35
        foreach ($tests as $test) {
36
            $covered[$test[1]] = 1;
37
        }
38
        foreach ($covered as $key => $val) {
39
            self::assertEquals(1, $val, "Codepage $key not tested");
40
        }
41
    }
42
43
    public function testNumberToNameWithInvalidCodePage(): void
44
    {
45
        $invalidCodePage = 12345;
46
47
        try {
48
            CodePage::numberToName($invalidCodePage);
49
        } catch (Exception $e) {
50
            self::assertEquals($e->getMessage(), 'Unknown codepage: 12345');
51
52
            return;
53
        }
54
        self::fail('An expected exception has not been raised.');
55
    }
56
57
    public function testNumberToNameWithUnsupportedCodePage(): void
58
    {
59
        $unsupportedCodePage = 720;
60
61
        try {
62
            CodePage::numberToName($unsupportedCodePage);
63
        } catch (Exception $e) {
64
            self::assertEquals($e->getMessage(), 'Code page 720 not supported.');
65
66
            return;
67
        }
68
        self::fail('An expected exception has not been raised.');
69
    }
70
}
71