1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Style\NumberFormat\Wizard; |
4
|
|
|
|
5
|
|
|
use NumberFormatter; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Exception; |
7
|
|
|
use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard\Scientific; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
class ScientificTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @dataProvider providerScientific |
14
|
|
|
*/ |
15
|
|
|
public function testScientific(string $expectedResult, int $decimals): void |
16
|
|
|
{ |
17
|
|
|
$wizard = new Scientific($decimals); |
18
|
|
|
self::assertSame($expectedResult, (string) $wizard); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function providerScientific(): array |
22
|
|
|
{ |
23
|
|
|
return [ |
24
|
|
|
['0E+00', 0], |
25
|
|
|
['0.0E+00', 1], |
26
|
|
|
['0.00E+00', 2], |
27
|
|
|
['0.000E+00', 3], |
28
|
|
|
['0E+00', -1], |
29
|
|
|
['0.000000000000000000000000000000E+00', 31], |
30
|
|
|
]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @dataProvider providerScientificLocale |
35
|
|
|
*/ |
36
|
|
|
public function testScientificLocale( |
37
|
|
|
string $expectedResult, |
38
|
|
|
string $locale |
39
|
|
|
): void { |
40
|
|
|
if (class_exists(NumberFormatter::class) === false) { |
41
|
|
|
self::markTestSkipped('Intl extension is not available'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
$wizard = new Scientific(2); |
45
|
|
|
$wizard->setLocale($locale); |
46
|
|
|
self::assertSame($expectedResult, (string) $wizard); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function providerScientificLocale(): array |
50
|
|
|
{ |
51
|
|
|
return [ |
52
|
|
|
['0.00E+00', 'en'], |
53
|
|
|
['0.00E+00', 'az-AZ'], |
54
|
|
|
['0.00E+00', 'az-Cyrl'], |
55
|
|
|
['0.00E+00', 'az-Cyrl-AZ'], |
56
|
|
|
['0.00E+00', 'az-Latn'], |
57
|
|
|
['0.00E+00', 'az-Latn-AZ'], |
58
|
|
|
]; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function testScientificLocaleInvalidFormat(): void |
62
|
|
|
{ |
63
|
|
|
if (class_exists(NumberFormatter::class) === false) { |
64
|
|
|
self::markTestSkipped('Intl extension is not available'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$locale = 'en-usa'; |
68
|
|
|
|
69
|
|
|
self::expectException(Exception::class); |
|
|
|
|
70
|
|
|
self::expectExceptionMessage("Invalid locale code '{$locale}'"); |
|
|
|
|
71
|
|
|
|
72
|
|
|
$wizard = new Scientific(2); |
73
|
|
|
$wizard->setLocale($locale); |
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|