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

testAccountingLocaleInvalidFormat()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 13
rs 10
cc 2
nc 2
nop 0
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\Accounting;
8
use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard\Currency;
9
use PhpOffice\PhpSpreadsheet\Style\NumberFormat\Wizard\Number;
10
use PHPUnit\Framework\TestCase;
11
12
class AccountingTest extends TestCase
13
{
14
    /**
15
     * @dataProvider providerAccounting
16
     */
17
    public function testCurrency(
18
        string $expectedResult,
19
        string $currencyCode,
20
        int $decimals,
21
        bool $thousandsSeparator,
22
        bool $currencySymbolPosition,
23
        bool $currencySymbolSpacing
24
    ): void {
25
        $wizard = new Accounting($currencyCode, $decimals, $thousandsSeparator, $currencySymbolPosition, $currencySymbolSpacing);
26
        self::assertSame($expectedResult, (string) $wizard);
27
    }
28
29
    public function providerAccounting(): array
30
    {
31
        return [
32
            ['_-$* 0_-', '$', 0, Number::WITHOUT_THOUSANDS_SEPARATOR, Currency::LEADING_SYMBOL, Currency::SYMBOL_WITH_SPACING],
33
            ['_-$* #,##0_-', '$', 0, Number::WITH_THOUSANDS_SEPARATOR, Currency::LEADING_SYMBOL, Currency::SYMBOL_WITH_SPACING],
34
            ['_-$*#,##0_-', '$', 0, Number::WITH_THOUSANDS_SEPARATOR, Currency::LEADING_SYMBOL, Currency::SYMBOL_WITHOUT_SPACING],
35
            ['_-0.00 €*_-', '€', 2, Number::WITHOUT_THOUSANDS_SEPARATOR, Currency::TRAILING_SYMBOL, Currency::SYMBOL_WITH_SPACING],
36
            ['_-#,##0.00 €*_-', '€', 2, Number::WITH_THOUSANDS_SEPARATOR, Currency::TRAILING_SYMBOL, Currency::SYMBOL_WITH_SPACING],
37
            ['_-0.00€*_-', '€', 2, Number::WITHOUT_THOUSANDS_SEPARATOR, Currency::TRAILING_SYMBOL, Currency::SYMBOL_WITHOUT_SPACING],
38
        ];
39
    }
40
41
    /**
42
     * @dataProvider providerAccountingLocale
43
     */
44
    public function testAccountingLocale(
45
        string $expectedResult,
46
        string $currencyCode,
47
        string $locale
48
    ): void {
49
        if (class_exists(NumberFormatter::class) === false) {
50
            self::markTestSkipped('Intl extension is not available');
51
        }
52
53
        $wizard = new Accounting($currencyCode);
54
        $wizard->setLocale($locale);
55
        self::assertSame($expectedResult, (string) $wizard);
56
    }
57
58
    public function providerAccountingLocale(): array
59
    {
60
        return [
61
            ["[\$€-fy-NL]\u{a0}#,##0.00;([\$€-fy-NL]\u{a0}#,##0.00)", '€', 'fy-NL'],
62
            ["[\$€-nl-NL]\u{a0}#,##0.00;([\$€-nl-NL]\u{a0}#,##0.00)", '€', 'nl-NL'],
63
            ["[\$€-nl-BE]\u{a0}#,##0.00;([\$€-nl-BE]\u{a0}#,##0.00)", '€', 'NL-BE'],
64
            ["#,##0.00\u{a0}[\$€-fr-BE];(#,##0.00\u{a0}[\$€-fr-BE])", '€', 'fr-be'],
65
            ["#,##0.00\u{a0}[\$€-el-GR]", '€', 'el-gr'],
66
            ['[$$-en-CA]#,##0.00;([$$-en-CA]#,##0.00)', '$', 'en-ca'],
67
            ["#,##0.00\u{a0}[\$\$-fr-CA];(#,##0.00\u{a0}[\$\$-fr-CA])", '$', 'fr-ca'],
68
            ['[$¥-ja-JP]#,##0;([$¥-ja-JP]#,##0)', '¥', 'ja-JP'], // No decimals
69
            ["#,##0.000\u{a0}[\$د.ب‎-ar-BH]", 'د.ب‎', 'ar-BH'],  // 3 decimals
70
        ];
71
    }
72
73
    public function testAccountingLocaleInvalidFormat(): void
74
    {
75
        if (class_exists(NumberFormatter::class) === false) {
76
            self::markTestSkipped('Intl extension is not available');
77
        }
78
79
        $locale = 'en-usa';
80
81
        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

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

82
        self::/** @scrutinizer ignore-call */ 
83
              expectExceptionMessage("Invalid locale code '{$locale}'");
Loading history...
83
84
        $wizard = new Accounting('€');
85
        $wizard->setLocale($locale);
86
    }
87
88
    public function testAccountingLocaleInvalidCode(): void
89
    {
90
        if (class_exists(NumberFormatter::class) === false) {
91
            self::markTestSkipped('Intl extension is not available');
92
        }
93
94
        $locale = 'nl-GB';
95
96
        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

96
        self::/** @scrutinizer ignore-call */ 
97
              expectException(Exception::class);
Loading history...
97
        self::expectExceptionMessage("Unable to read locale data for '{$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

97
        self::/** @scrutinizer ignore-call */ 
98
              expectExceptionMessage("Unable to read locale data for '{$locale}'");
Loading history...
98
99
        $wizard = new Accounting('€');
100
        $wizard->setLocale($locale);
101
    }
102
}
103