PhpSpreadsheet/tests/PhpSpreadsheetTests/Shared/CodePageTest.php

71 lines
1.8 KiB
PHP
Raw Permalink Normal View History

<?php
namespace PhpOffice\PhpSpreadsheetTests\Shared;
use PhpOffice\PhpSpreadsheet\Exception;
use PhpOffice\PhpSpreadsheet\Shared\CodePage;
use PHPUnit\Framework\TestCase;
class CodePageTest extends TestCase
{
/**
* @dataProvider providerCodePage
*
* @param mixed $expectedResult
*/
2020-05-18 04:49:57 +00:00
public function testCodePageNumberToName($expectedResult, ...$args): void
2015-05-17 13:00:02 +00:00
{
$result = CodePage::numberToName(...$args);
self::assertEquals($expectedResult, $result);
2015-05-17 13:00:02 +00:00
}
public function providerCodePage()
{
return require 'tests/data/Shared/CodePage.php';
2015-05-17 13:00:02 +00:00
}
public function testCoverage(): void
{
$covered = [];
$expected = CodePage::getEncodings();
foreach ($expected as $key => $val) {
$covered[$key] = 0;
}
$tests = $this->providerCodePage();
foreach ($tests as $test) {
$covered[$test[1]] = 1;
}
foreach ($covered as $key => $val) {
self::assertEquals(1, $val, "Codepage $key not tested");
}
}
2020-05-18 04:49:57 +00:00
public function testNumberToNameWithInvalidCodePage(): void
2015-05-17 13:00:02 +00:00
{
$invalidCodePage = 12345;
2017-10-01 11:07:04 +00:00
2015-05-17 13:00:02 +00:00
try {
CodePage::numberToName($invalidCodePage);
} catch (Exception $e) {
self::assertEquals($e->getMessage(), 'Unknown codepage: 12345');
2015-05-17 13:00:02 +00:00
return;
}
2020-05-18 04:49:57 +00:00
self::fail('An expected exception has not been raised.');
2015-05-17 13:00:02 +00:00
}
2020-05-18 04:49:57 +00:00
public function testNumberToNameWithUnsupportedCodePage(): void
2015-05-17 13:00:02 +00:00
{
$unsupportedCodePage = 720;
2017-10-01 11:07:04 +00:00
2015-05-17 13:00:02 +00:00
try {
CodePage::numberToName($unsupportedCodePage);
} catch (Exception $e) {
self::assertEquals($e->getMessage(), 'Code page 720 not supported.');
2015-05-17 13:00:02 +00:00
return;
}
2020-05-18 04:49:57 +00:00
self::fail('An expected exception has not been raised.');
2015-05-17 13:00:02 +00:00
}
}