Failed Conditions
Push — master ( a2282e...ad0b68 )
by Mark
40s queued 35s
created

NumberTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 24
c 1
b 0
f 0
dl 0
loc 59
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testNumber() 0 4 1
A providerNumberLocale() 0 4 1
A testNumberLocaleInvalidFormat() 0 13 2
A providerNumber() 0 9 1
A testNumberLocale() 0 11 2
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);
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCase::expectException() is not static, but was called statically. ( Ignorable by Annotation )

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

64
        self::/** @scrutinizer ignore-call */ 
65
              expectException(Exception::class);
Loading history...
65
        self::expectExceptionMessage("Invalid locale code '{$locale}'");
0 ignored issues
show
Bug Best Practice introduced by
The method PHPUnit\Framework\TestCa...xpectExceptionMessage() is not static, but was called statically. ( Ignorable by Annotation )

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

65
        self::/** @scrutinizer ignore-call */ 
66
              expectExceptionMessage("Invalid locale code '{$locale}'");
Loading history...
66
67
        $wizard = new Number(2);
68
        $wizard->setLocale($locale);
69
    }
70
}
71