Skip to content

Commit

Permalink
PHPUnit 10 attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Mar 27, 2024
1 parent fe4f2ab commit bb25ed9
Showing 1 changed file with 19 additions and 48 deletions.
67 changes: 19 additions & 48 deletions tests/PhoneNumberTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

use Brick\PhoneNumber\PhoneNumber;
use Brick\PhoneNumber\PhoneNumberException;
use Brick\PhoneNumber\PhoneNumberFormat;
use Brick\PhoneNumber\PhoneNumberParseException;
use Brick\PhoneNumber\PhoneNumberType;
use Brick\PhoneNumber\PhoneNumberFormat;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -55,9 +55,7 @@ class PhoneNumberTest extends TestCase
private const UNIVERSAL_PREMIUM_RATE = '+979123456789';
private const UNKNOWN_COUNTRY_CODE_NO_RAW_INPUT = '+212345';

/**
* @dataProvider providerGetExampleNumber
*/
#[DataProvider('providerGetExampleNumber')]
public function testGetExampleNumber(string $regionCode, string $callingCode, ?PhoneNumberType $numberType = null) : void
{
if ($numberType === null) {
Expand Down Expand Up @@ -94,9 +92,7 @@ public function testGetExampleNumberThrowsExceptionForInvalidRegionCode() : void
PhoneNumber::getExampleNumber('ZZ');
}

/**
* @dataProvider providerGetNationalNumber
*/
#[DataProvider('providerGetNationalNumber')]
public function testGetNationalNumber(string $expectedNationalNumber, string $phoneNumber) : void
{
self::assertSame($expectedNationalNumber, PhoneNumber::parse($phoneNumber)->getNationalNumber());
Expand All @@ -112,9 +108,7 @@ public static function providerGetNationalNumber() : array
];
}

/**
* @dataProvider providerParseNationalNumber
*/
#[DataProvider('providerParseNationalNumber')]
public function testParseNationalNumber(string $expectedNumber, string $numberToParse, string $regionCode) : void
{
self::assertSame($expectedNumber, (string) PhoneNumber::parse($numberToParse, $regionCode));
Expand Down Expand Up @@ -153,9 +147,7 @@ public static function providerParseNationalNumber() : array
];
}

/**
* @dataProvider providerGetRegionCode
*/
#[DataProvider('providerGetRegionCode')]
public function testGetRegionCode(?string $expectedRegion, string $phoneNumber) : void
{
self::assertSame($expectedRegion, PhoneNumber::parse($phoneNumber)->getRegionCode());
Expand All @@ -171,9 +163,7 @@ public static function providerGetRegionCode() : array
];
}

/**
* @dataProvider providerGetNumberType
*/
#[DataProvider('providerGetNumberType')]
public function testGetNumberType(PhoneNumberType $numberType, string $phoneNumber) : void
{
self::assertSame($numberType, PhoneNumber::parse($phoneNumber)->getNumberType());
Expand Down Expand Up @@ -227,35 +217,27 @@ public static function providerGetNumberType() : array
];
}

/**
* @dataProvider providerValidNumbers
* @dataProvider providerPossibleButNotValidNumbers
*/
#[DataProvider('providerValidNumbers')]
#[DataProvider('providerPossibleButNotValidNumbers')]
public function testIsPossibleNumber(string $phoneNumber) : void
{
self::assertTrue(PhoneNumber::parse($phoneNumber)->isPossibleNumber());
}

/**
* @dataProvider providerNotPossibleNumbers
*/
#[DataProvider('providerNotPossibleNumbers')]
public function testIsNotPossibleNumber(string $phoneNumber) : void
{
self::assertFalse(PhoneNumber::parse($phoneNumber)->isPossibleNumber());
}

/**
* @dataProvider providerValidNumbers
*/
#[DataProvider('providerValidNumbers')]
public function testIsValidNumber(string $phoneNumber) : void
{
self::assertTrue(PhoneNumber::parse($phoneNumber)->isValidNumber());
}

/**
* @dataProvider providerNotPossibleNumbers
* @dataProvider providerPossibleButNotValidNumbers
*/
#[DataProvider('providerNotPossibleNumbers')]
#[DataProvider('providerPossibleButNotValidNumbers')]
public function testIsNotValidNumber(string $phoneNumber) : void
{
self::assertFalse(PhoneNumber::parse($phoneNumber)->isValidNumber());
Expand Down Expand Up @@ -293,9 +275,7 @@ public static function providerNotPossibleNumbers() : array
];
}

/**
* @dataProvider providerParseException
*/
#[DataProvider('providerParseException')]
public function testParseException(string $phoneNumber, ?string $regionCode = null) : void
{
$this->expectException(PhoneNumberParseException::class);
Expand Down Expand Up @@ -344,9 +324,7 @@ public static function providerParseException() : array
];
}

/**
* @dataProvider providerFormatNumber
*/
#[DataProvider('providerFormatNumber')]
public function testFormatNumber(string $expected, string $phoneNumber, PhoneNumberFormat $numberFormat) : void
{
self::assertSame($expected, PhoneNumber::parse($phoneNumber)->format($numberFormat));
Expand Down Expand Up @@ -446,9 +424,7 @@ public static function providerFormatNumber() : array
];
}

/**
* @dataProvider providerFormatForCallingFrom
*/
#[DataProvider('providerFormatForCallingFrom')]
public function testFormatForCallingFrom(string $phoneNumber, string $countryCode, string $expected) : void
{
self::assertSame($expected, PhoneNumber::parse($phoneNumber)->formatForCallingFrom($countryCode));
Expand All @@ -474,9 +450,7 @@ public static function providerFormatForCallingFrom() : array
];
}

/**
* @dataProvider providerGetGeographicalAreaCode
*/
#[DataProvider('providerGetGeographicalAreaCode')]
public function testGetGeographicalAreaCode(string $phoneNumber, string $areaCode) : void
{
self::assertSame($areaCode, PhoneNumber::parse($phoneNumber)->getGeographicalAreaCode());
Expand All @@ -496,9 +470,7 @@ public static function providerGetGeographicalAreaCode() : array
];
}

/**
* @dataProvider providerIsEqualTo
*/
#[DataProvider('providerIsEqualTo')]
public function testIsEqualTo(string $phoneNumber1, string $phoneNumber2, bool $isEqual): void
{
$phoneNumber1 = PhoneNumber::parse($phoneNumber1);
Expand Down Expand Up @@ -528,10 +500,9 @@ public function testJsonSerializable(): void
* The data provider may provide several possible results, as the results differ depending on the version of the
* underlying phonenumber library.
*
* @dataProvider providerGetDescription
*
* @param (string|null)[] $expected
*/
#[DataProvider('providerGetDescription')]
public function testGetDescription(string $phoneNumber, string $locale, ?string $userRegion, array $expected) : void
{
self::assertContains(PhoneNumber::parse($phoneNumber)->getDescription($locale, $userRegion), $expected);
Expand Down

0 comments on commit bb25ed9

Please sign in to comment.