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

CodePageTest::testCoverage()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 9
nc 8
nop 0
dl 0
loc 13
rs 9.9666
c 0
b 0
f 0
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