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\Number; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
class NumberTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @dataProvider providerNumber |
14
|
|
|
*/ |
15
|
|
|
public function testNumber(string $expectedResult, int $decimals, bool $thousandsSeparator): void |
16
|
|
|
{ |
17
|
|
|
$wizard = new Number($decimals, $thousandsSeparator); |
18
|
|
|
self::assertSame($expectedResult, (string) $wizard); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
public function providerNumber(): array |
22
|
|
|
{ |
23
|
|
|
return [ |
24
|
|
|
['0', 0, Number::WITHOUT_THOUSANDS_SEPARATOR], |
25
|
|
|
['#,##0', 0, Number::WITH_THOUSANDS_SEPARATOR], |
26
|
|
|
['0.0', 1, Number::WITHOUT_THOUSANDS_SEPARATOR], |
27
|
|
|
['#,##0.0', 1, Number::WITH_THOUSANDS_SEPARATOR], |
28
|
|
|
['0.00', 2, Number::WITHOUT_THOUSANDS_SEPARATOR], |
29
|
|
|
['#,##0.00', 2, Number::WITH_THOUSANDS_SEPARATOR], |
30
|
|
|
]; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @dataProvider providerNumberLocale |
35
|
|
|
*/ |
36
|
|
|
public function testNumberLocale( |
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 Number(2); |
45
|
|
|
$wizard->setLocale($locale); |
46
|
|
|
self::assertSame($expectedResult, (string) $wizard); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function providerNumberLocale(): array |
50
|
|
|
{ |
51
|
|
|
return [ |
52
|
|
|
['#,##0.00', 'en-us'], |
53
|
|
|
]; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testNumberLocaleInvalidFormat(): void |
57
|
|
|
{ |
58
|
|
|
if (class_exists(NumberFormatter::class) === false) { |
59
|
|
|
self::markTestSkipped('Intl extension is not available'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
$locale = 'en-usa'; |
63
|
|
|
|
64
|
|
|
self::expectException(Exception::class); |
|
|
|
|
65
|
|
|
self::expectExceptionMessage("Invalid locale code '{$locale}'"); |
|
|
|
|
66
|
|
|
|
67
|
|
|
$wizard = new Number(2); |
68
|
|
|
$wizard->setLocale($locale); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|