3
3
namespace Illuminate \Tests \Support ;
4
4
5
5
use Illuminate \Support \Number ;
6
+ use PHPUnit \Framework \Attributes \RequiresPhpExtension ;
6
7
use PHPUnit \Framework \TestCase ;
7
8
8
9
class SupportNumberTest extends TestCase
9
10
{
11
+ #[RequiresPhpExtension('intl ' )]
10
12
public function testFormat ()
11
13
{
12
- $ this ->needsIntlExtension ();
13
-
14
14
$ this ->assertSame ('0 ' , Number::format (0 ));
15
15
$ this ->assertSame ('0 ' , Number::format (0.0 ));
16
16
$ this ->assertSame ('0 ' , Number::format (0.00 ));
@@ -40,21 +40,19 @@ public function testFormat()
40
40
$ this ->assertSame ('NaN ' , Number::format (NAN ));
41
41
}
42
42
43
+ #[RequiresPhpExtension('intl ' )]
43
44
public function testFormatWithDifferentLocale ()
44
45
{
45
- $ this ->needsIntlExtension ();
46
-
47
46
$ this ->assertSame ('123,456,789 ' , Number::format (123456789 , locale: 'en ' ));
48
47
$ this ->assertSame ('123.456.789 ' , Number::format (123456789 , locale: 'de ' ));
49
48
$ this ->assertSame ('123 456 789 ' , Number::format (123456789 , locale: 'fr ' ));
50
49
$ this ->assertSame ('123 456 789 ' , Number::format (123456789 , locale: 'ru ' ));
51
50
$ this ->assertSame ('123 456 789 ' , Number::format (123456789 , locale: 'sv ' ));
52
51
}
53
52
53
+ #[RequiresPhpExtension('intl ' )]
54
54
public function testFormatWithAppLocale ()
55
55
{
56
- $ this ->needsIntlExtension ();
57
-
58
56
$ this ->assertSame ('123,456,789 ' , Number::format (123456789 ));
59
57
60
58
Number::useLocale ('de ' );
@@ -70,17 +68,15 @@ public function testSpellout()
70
68
$ this ->assertSame ('one point two ' , Number::spell (1.2 ));
71
69
}
72
70
71
+ #[RequiresPhpExtension('intl ' )]
73
72
public function testSpelloutWithLocale ()
74
73
{
75
- $ this ->needsIntlExtension ();
76
-
77
74
$ this ->assertSame ('trois ' , Number::spell (3 , 'fr ' ));
78
75
}
79
76
77
+ #[RequiresPhpExtension('intl ' )]
80
78
public function testSpelloutWithThreshold ()
81
79
{
82
- $ this ->needsIntlExtension ();
83
-
84
80
$ this ->assertSame ('9 ' , Number::spell (9 , after: 10 ));
85
81
$ this ->assertSame ('10 ' , Number::spell (10 , after: 10 ));
86
82
$ this ->assertSame ('eleven ' , Number::spell (11 , after: 10 ));
@@ -100,10 +96,9 @@ public function testOrdinal()
100
96
$ this ->assertSame ('3rd ' , Number::ordinal (3 ));
101
97
}
102
98
99
+ #[RequiresPhpExtension('intl ' )]
103
100
public function testToPercent ()
104
101
{
105
- $ this ->needsIntlExtension ();
106
-
107
102
$ this ->assertSame ('0% ' , Number::percentage (0 , precision: 0 ));
108
103
$ this ->assertSame ('0% ' , Number::percentage (0 ));
109
104
$ this ->assertSame ('1% ' , Number::percentage (1 ));
@@ -124,10 +119,9 @@ public function testToPercent()
124
119
$ this ->assertSame ('0.1235% ' , Number::percentage (0.12345 , precision: 4 ));
125
120
}
126
121
122
+ #[RequiresPhpExtension('intl ' )]
127
123
public function testToCurrency ()
128
124
{
129
- $ this ->needsIntlExtension ();
130
-
131
125
$ this ->assertSame ('$0.00 ' , Number::currency (0 ));
132
126
$ this ->assertSame ('$1.00 ' , Number::currency (1 ));
133
127
$ this ->assertSame ('$10.00 ' , Number::currency (10 ));
@@ -141,10 +135,9 @@ public function testToCurrency()
141
135
$ this ->assertSame ('$5.32 ' , Number::currency (5.325 ));
142
136
}
143
137
138
+ #[RequiresPhpExtension('intl ' )]
144
139
public function testToCurrencyWithDifferentLocale ()
145
140
{
146
- $ this ->needsIntlExtension ();
147
-
148
141
$ this ->assertSame ('1,00 € ' , Number::currency (1 , 'EUR ' , 'de ' ));
149
142
$ this ->assertSame ('1,00 $ ' , Number::currency (1 , 'USD ' , 'de ' ));
150
143
$ this ->assertSame ('1,00 £ ' , Number::currency (1 , 'GBP ' , 'de ' ));
@@ -293,11 +286,4 @@ public function testSummarize()
293
286
$ this ->assertSame ('-1Q ' , Number::abbreviate (-1000000000000000 ));
294
287
$ this ->assertSame ('-1KQ ' , Number::abbreviate (-1000000000000000000 ));
295
288
}
296
-
297
- protected function needsIntlExtension ()
298
- {
299
- if (! extension_loaded ('intl ' )) {
300
- $ this ->markTestSkipped ('The intl extension is not installed. Please install the extension to enable ' .__CLASS__ );
301
- }
302
- }
303
289
}
0 commit comments