Failed Conditions
Pull Request — master (#3334)
by Mark
19:27 queued 08:13
created

ScientificTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A providerScientific() 0 9 1
A providerScientificLocale() 0 9 1
A testScientificLocale() 0 11 2
A testScientificLocaleInvalidFormat() 0 13 2
A testScientific() 0 4 1
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);
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

69
        self::/** @scrutinizer ignore-call */ 
70
              expectException(Exception::class);
Loading history...
70
        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

70
        self::/** @scrutinizer ignore-call */ 
71
              expectExceptionMessage("Invalid locale code '{$locale}'");
Loading history...
71
72
        $wizard = new Scientific(2);
73
        $wizard->setLocale($locale);
74
    }
75
}
76