6
6
7
7
use Brick \PhoneNumber \PhoneNumber ;
8
8
use Brick \PhoneNumber \PhoneNumberException ;
9
+ use Brick \PhoneNumber \PhoneNumberFormat ;
9
10
use Brick \PhoneNumber \PhoneNumberParseException ;
10
11
use Brick \PhoneNumber \PhoneNumberType ;
11
- use Brick \PhoneNumber \PhoneNumberFormat ;
12
-
12
+ use PHPUnit \Framework \Attributes \DataProvider ;
13
13
use PHPUnit \Framework \TestCase ;
14
14
15
15
/**
@@ -55,9 +55,7 @@ class PhoneNumberTest extends TestCase
55
55
private const UNIVERSAL_PREMIUM_RATE = '+979123456789 ' ;
56
56
private const UNKNOWN_COUNTRY_CODE_NO_RAW_INPUT = '+212345 ' ;
57
57
58
- /**
59
- * @dataProvider providerGetExampleNumber
60
- */
58
+ #[DataProvider('providerGetExampleNumber ' )]
61
59
public function testGetExampleNumber (string $ regionCode , string $ callingCode , ?PhoneNumberType $ numberType = null ) : void
62
60
{
63
61
if ($ numberType === null ) {
@@ -94,9 +92,7 @@ public function testGetExampleNumberThrowsExceptionForInvalidRegionCode() : void
94
92
PhoneNumber::getExampleNumber ('ZZ ' );
95
93
}
96
94
97
- /**
98
- * @dataProvider providerGetNationalNumber
99
- */
95
+ #[DataProvider('providerGetNationalNumber ' )]
100
96
public function testGetNationalNumber (string $ expectedNationalNumber , string $ phoneNumber ) : void
101
97
{
102
98
self ::assertSame ($ expectedNationalNumber , PhoneNumber::parse ($ phoneNumber )->getNationalNumber ());
@@ -112,9 +108,7 @@ public static function providerGetNationalNumber() : array
112
108
];
113
109
}
114
110
115
- /**
116
- * @dataProvider providerParseNationalNumber
117
- */
111
+ #[DataProvider('providerParseNationalNumber ' )]
118
112
public function testParseNationalNumber (string $ expectedNumber , string $ numberToParse , string $ regionCode ) : void
119
113
{
120
114
self ::assertSame ($ expectedNumber , (string ) PhoneNumber::parse ($ numberToParse , $ regionCode ));
@@ -153,9 +147,7 @@ public static function providerParseNationalNumber() : array
153
147
];
154
148
}
155
149
156
- /**
157
- * @dataProvider providerGetRegionCode
158
- */
150
+ #[DataProvider('providerGetRegionCode ' )]
159
151
public function testGetRegionCode (?string $ expectedRegion , string $ phoneNumber ) : void
160
152
{
161
153
self ::assertSame ($ expectedRegion , PhoneNumber::parse ($ phoneNumber )->getRegionCode ());
@@ -171,9 +163,7 @@ public static function providerGetRegionCode() : array
171
163
];
172
164
}
173
165
174
- /**
175
- * @dataProvider providerGetNumberType
176
- */
166
+ #[DataProvider('providerGetNumberType ' )]
177
167
public function testGetNumberType (PhoneNumberType $ numberType , string $ phoneNumber ) : void
178
168
{
179
169
self ::assertSame ($ numberType , PhoneNumber::parse ($ phoneNumber )->getNumberType ());
@@ -227,35 +217,27 @@ public static function providerGetNumberType() : array
227
217
];
228
218
}
229
219
230
- /**
231
- * @dataProvider providerValidNumbers
232
- * @dataProvider providerPossibleButNotValidNumbers
233
- */
220
+ #[DataProvider('providerValidNumbers ' )]
221
+ #[DataProvider('providerPossibleButNotValidNumbers ' )]
234
222
public function testIsPossibleNumber (string $ phoneNumber ) : void
235
223
{
236
224
self ::assertTrue (PhoneNumber::parse ($ phoneNumber )->isPossibleNumber ());
237
225
}
238
226
239
- /**
240
- * @dataProvider providerNotPossibleNumbers
241
- */
227
+ #[DataProvider('providerNotPossibleNumbers ' )]
242
228
public function testIsNotPossibleNumber (string $ phoneNumber ) : void
243
229
{
244
230
self ::assertFalse (PhoneNumber::parse ($ phoneNumber )->isPossibleNumber ());
245
231
}
246
232
247
- /**
248
- * @dataProvider providerValidNumbers
249
- */
233
+ #[DataProvider('providerValidNumbers ' )]
250
234
public function testIsValidNumber (string $ phoneNumber ) : void
251
235
{
252
236
self ::assertTrue (PhoneNumber::parse ($ phoneNumber )->isValidNumber ());
253
237
}
254
238
255
- /**
256
- * @dataProvider providerNotPossibleNumbers
257
- * @dataProvider providerPossibleButNotValidNumbers
258
- */
239
+ #[DataProvider('providerNotPossibleNumbers ' )]
240
+ #[DataProvider('providerPossibleButNotValidNumbers ' )]
259
241
public function testIsNotValidNumber (string $ phoneNumber ) : void
260
242
{
261
243
self ::assertFalse (PhoneNumber::parse ($ phoneNumber )->isValidNumber ());
@@ -293,9 +275,7 @@ public static function providerNotPossibleNumbers() : array
293
275
];
294
276
}
295
277
296
- /**
297
- * @dataProvider providerParseException
298
- */
278
+ #[DataProvider('providerParseException ' )]
299
279
public function testParseException (string $ phoneNumber , ?string $ regionCode = null ) : void
300
280
{
301
281
$ this ->expectException (PhoneNumberParseException::class);
@@ -344,9 +324,7 @@ public static function providerParseException() : array
344
324
];
345
325
}
346
326
347
- /**
348
- * @dataProvider providerFormatNumber
349
- */
327
+ #[DataProvider('providerFormatNumber ' )]
350
328
public function testFormatNumber (string $ expected , string $ phoneNumber , PhoneNumberFormat $ numberFormat ) : void
351
329
{
352
330
self ::assertSame ($ expected , PhoneNumber::parse ($ phoneNumber )->format ($ numberFormat ));
@@ -446,9 +424,7 @@ public static function providerFormatNumber() : array
446
424
];
447
425
}
448
426
449
- /**
450
- * @dataProvider providerFormatForCallingFrom
451
- */
427
+ #[DataProvider('providerFormatForCallingFrom ' )]
452
428
public function testFormatForCallingFrom (string $ phoneNumber , string $ countryCode , string $ expected ) : void
453
429
{
454
430
self ::assertSame ($ expected , PhoneNumber::parse ($ phoneNumber )->formatForCallingFrom ($ countryCode ));
@@ -474,9 +450,7 @@ public static function providerFormatForCallingFrom() : array
474
450
];
475
451
}
476
452
477
- /**
478
- * @dataProvider providerGetGeographicalAreaCode
479
- */
453
+ #[DataProvider('providerGetGeographicalAreaCode ' )]
480
454
public function testGetGeographicalAreaCode (string $ phoneNumber , string $ areaCode ) : void
481
455
{
482
456
self ::assertSame ($ areaCode , PhoneNumber::parse ($ phoneNumber )->getGeographicalAreaCode ());
@@ -496,9 +470,7 @@ public static function providerGetGeographicalAreaCode() : array
496
470
];
497
471
}
498
472
499
- /**
500
- * @dataProvider providerIsEqualTo
501
- */
473
+ #[DataProvider('providerIsEqualTo ' )]
502
474
public function testIsEqualTo (string $ phoneNumber1 , string $ phoneNumber2 , bool $ isEqual ): void
503
475
{
504
476
$ phoneNumber1 = PhoneNumber::parse ($ phoneNumber1 );
@@ -528,10 +500,9 @@ public function testJsonSerializable(): void
528
500
* The data provider may provide several possible results, as the results differ depending on the version of the
529
501
* underlying phonenumber library.
530
502
*
531
- * @dataProvider providerGetDescription
532
- *
533
503
* @param (string|null)[] $expected
534
504
*/
505
+ #[DataProvider('providerGetDescription ' )]
535
506
public function testGetDescription (string $ phoneNumber , string $ locale , ?string $ userRegion , array $ expected ) : void
536
507
{
537
508
self ::assertContains (PhoneNumber::parse ($ phoneNumber )->getDescription ($ locale , $ userRegion ), $ expected );
0 commit comments