diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index aa7b554..476c92c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,12 +13,12 @@ jobs: strategy: fail-fast: false matrix: - php: [ 8.0, 8.1, 8.2, 8.3 ] - laravel: [ 9, 10 ] + php: [ 8.1, 8.2, 8.3 ] + laravel: [ 10, 11 ] stability: [ prefer-lowest, prefer-stable ] exclude: - - php: 8.0 - laravel: 10 + - php: 8.1 + laravel: 11 name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} (${{ matrix.stability }}) @@ -46,7 +46,7 @@ jobs: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress - name: Execute tests - run: vendor/bin/phpunit --verbose + run: vendor/bin/phpunit - name: Run phpstan run: vendor/bin/phpstan analyse --error-format=github diff --git a/composer.json b/composer.json index 6bafeff..36d6064 100644 --- a/composer.json +++ b/composer.json @@ -15,17 +15,17 @@ } ], "require": { - "php": "^8.0", - "illuminate/contracts": "^9.0|^10.0", - "illuminate/support": "^9.0|^10.0", - "illuminate/validation": "^9.0|^10.0", + "php": "^8.1", + "illuminate/contracts": "^10.0|^11.0", + "illuminate/support": "^10.0|^11.0", + "illuminate/validation": "^10.0|^11.0", "giggsey/libphonenumber-for-php": "^7.0|^8.0" }, "require-dev": { "orchestra/testbench": "*", - "phpunit/phpunit": "^9.5.10", - "nunomaduro/larastan": "^2.4", - "laravel/pint": "^1.4" + "phpunit/phpunit": "^10.5", + "larastan/larastan": "^2.9", + "laravel/pint": "^1.14" }, "autoload": { "psr-4": { diff --git a/phpstan.neon b/phpstan.neon index 29875cb..3038835 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,5 @@ includes: - - ./vendor/nunomaduro/larastan/extension.neon + - ./vendor/larastan/larastan/extension.neon parameters: diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7d75852..451acf8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,21 +1,18 @@ - +> - ./tests/ + tests + tests/TestCase.php - - - ./src - - + + + src + + diff --git a/src/Concerns/PhoneNumberFormat.php b/src/Concerns/PhoneNumberFormat.php index c8fce54..cb5eb74 100644 --- a/src/Concerns/PhoneNumberFormat.php +++ b/src/Concerns/PhoneNumberFormat.php @@ -26,7 +26,7 @@ public static function isValidName($format): bool return ! is_null($format) && in_array(strtoupper($format), $formats, true); } - public static function getHumanReadableName($format): string|null + public static function getHumanReadableName($format): ?string { $name = array_search($format, static::all(), true); diff --git a/src/Concerns/PhoneNumberType.php b/src/Concerns/PhoneNumberType.php index ef4119b..59603e8 100644 --- a/src/Concerns/PhoneNumberType.php +++ b/src/Concerns/PhoneNumberType.php @@ -26,7 +26,7 @@ public static function isValidName($type): bool return ! is_null($type) && in_array(strtoupper($type), $types, true); } - public static function getHumanReadableName($type): string|null + public static function getHumanReadableName($type): ?string { $name = array_search($type, static::all(), true); diff --git a/src/PhoneNumber.php b/src/PhoneNumber.php index dd23a8c..53f0700 100644 --- a/src/PhoneNumber.php +++ b/src/PhoneNumber.php @@ -34,7 +34,7 @@ public function __construct(?string $number, $country = []) $this->countries = Arr::wrap($country); } - public function getCountry(): string|null + public function getCountry(): ?string { // Try to detect the country first from the number itself. try { diff --git a/src/Rules/Phone.php b/src/Rules/Phone.php index 33b39ba..da69361 100644 --- a/src/Rules/Phone.php +++ b/src/Rules/Phone.php @@ -9,8 +9,8 @@ use libphonenumber\PhoneNumberType as libPhoneNumberType; use Propaganistas\LaravelPhone\Concerns\PhoneNumberCountry; use Propaganistas\LaravelPhone\Concerns\PhoneNumberType; -use Propaganistas\LaravelPhone\Exceptions\NumberParseException; use Propaganistas\LaravelPhone\Exceptions\IncompatibleTypesException; +use Propaganistas\LaravelPhone\Exceptions\NumberParseException; use Propaganistas\LaravelPhone\PhoneNumber; class Phone implements Rule, ValidatorAwareRule diff --git a/tests/E164PhoneNumberCastTest.php b/tests/E164PhoneNumberCastTest.php index f4db887..70afd79 100644 --- a/tests/E164PhoneNumberCastTest.php +++ b/tests/E164PhoneNumberCastTest.php @@ -3,13 +3,14 @@ namespace Propaganistas\LaravelPhone\Tests; use Illuminate\Database\Eloquent\Model; +use PHPUnit\Framework\Attributes\Test; use Propaganistas\LaravelPhone\Casts\E164PhoneNumberCast; use Propaganistas\LaravelPhone\PhoneNumber; use UnexpectedValueException; class E164PhoneNumberCastTest extends TestCase { - /** @test */ + #[Test] public function it_mutates_to_e164_number() { $model = new ModelWithE164Cast; @@ -21,7 +22,7 @@ public function it_mutates_to_e164_number() $this->assertEquals('+3212345678', $model->getAttributes()['phone']); } - /** @test */ + #[Test] public function it_mutates_to_e164_number_with_implicit_country_field() { $model = new ModelWithE164Cast; @@ -35,7 +36,7 @@ public function it_mutates_to_e164_number_with_implicit_country_field() $this->assertEquals('+3212345678', $model->getAttributes()['phone']); } - /** @test */ + #[Test] public function it_mutates_to_e164_number_with_explicit_country_field() { $model = new ModelWithE164CastAndCountryField; @@ -49,7 +50,7 @@ public function it_mutates_to_e164_number_with_explicit_country_field() $this->assertEquals('+3212345678', $model->getAttributes()['phone']); } - /** @test */ + #[Test] public function it_gets_phone_object() { $model = new ModelWithE164Cast; @@ -58,7 +59,7 @@ public function it_gets_phone_object() $this->assertEquals(PhoneNumber::class, get_class($model->phone)); } - /** @test */ + #[Test] public function it_throws_when_accessing_non_international_value() { $model = new ModelWithE164Cast(); @@ -67,7 +68,7 @@ public function it_throws_when_accessing_non_international_value() $model->phone; } - /** @test */ + #[Test] public function it_serializes() { $model = new ModelWithE164Cast(); diff --git a/tests/PhoneNumberTest.php b/tests/PhoneNumberTest.php index 451fe2c..bf9a2df 100644 --- a/tests/PhoneNumberTest.php +++ b/tests/PhoneNumberTest.php @@ -4,6 +4,7 @@ use libphonenumber\PhoneNumberFormat; use libphonenumber\PhoneNumberType; +use PHPUnit\Framework\Attributes\Test; use Propaganistas\LaravelPhone\Exceptions\CountryCodeException; use Propaganistas\LaravelPhone\Exceptions\NumberFormatException; use Propaganistas\LaravelPhone\Exceptions\NumberParseException; @@ -11,42 +12,42 @@ class PhoneNumberTest extends TestCase { - /** @test */ + #[Test] public function it_constructs_without_country() { $object = new PhoneNumber('012345678'); $this->assertInstanceOf(PhoneNumber::class, $object); } - - /** @test */ + + #[Test] public function it_constructs_with_string_country() { $object = new PhoneNumber('012345678', 'BE'); $this->assertInstanceOf(PhoneNumber::class, $object); } - - /** @test */ + + #[Test] public function it_constructs_with_array_country() { $object = new PhoneNumber('012345678', ['BE', 'NL']); $this->assertInstanceOf(PhoneNumber::class, $object); } - - /** @test */ + + #[Test] public function it_constructs_with_null_country() { $object = new PhoneNumber('012345678', null); $this->assertInstanceOf(PhoneNumber::class, $object); } - /** @test */ + #[Test] public function it_returns_the_raw_number() { $object = new PhoneNumber('012 34 56 78'); $this->assertEquals('012 34 56 78', $object->getRawNumber()); } - /** @test */ + #[Test] public function it_returns_true_when_checking_correct_validity() { $object = new PhoneNumber('+3212345678'); @@ -59,14 +60,14 @@ public function it_returns_true_when_checking_correct_validity() $this->assertTrue($object->isValid()); } - /** @test */ + #[Test] public function it_returns_true_when_checking_correct_validity_with_wrong_country() { $object = new PhoneNumber('+3212345678', 'US'); $this->assertTrue($object->isValid()); } - /** @test */ + #[Test] public function it_returns_false_when_checking_incorrect_validity() { $object = new PhoneNumber('012345678'); @@ -82,35 +83,35 @@ public function it_returns_false_when_checking_incorrect_validity() $this->assertFalse($object->isValid()); } - /** @test */ + #[Test] public function it_gets_the_country_for_an_international_number() { $object = new PhoneNumber('+3212345678'); $this->assertEquals('BE', $object->getCountry()); } - /** @test */ + #[Test] public function it_gets_the_country_for_a_non_international_number() { $object = new PhoneNumber('012345678', ['NL', 'BE', 'FR']); $this->assertEquals('BE', $object->getCountry()); } - /** @test */ + #[Test] public function it_returns_null_when_country_is_not_found_for_a_non_international_number() { $object = new PhoneNumber('012345678', ['NL', 'FR']); $this->assertNull($object->getCountry()); } - /** @test */ + #[Test] public function it_ignores_invalid_countries() { $object = new PhoneNumber('012345678', ['BE', 'foo', 23]); $this->assertEquals('BE', $object->getCountry()); } - /** @test */ + #[Test] public function it_returns_true_when_checking_correct_country() { $object = new PhoneNumber('012345678'); @@ -120,7 +121,7 @@ public function it_returns_true_when_checking_correct_country() $this->assertTrue($object->isOfCountry('BE')); } - /** @test */ + #[Test] public function it_returns_false_when_checking_incorrect_country_or_null() { $object = new PhoneNumber('012345678'); @@ -130,7 +131,7 @@ public function it_returns_false_when_checking_incorrect_country_or_null() $this->assertFalse($object->isOfCountry('US')); } - /** @test */ + #[Test] public function it_ignores_provided_countries_when_checking_country() { $object = new PhoneNumber('012345678', 'NL'); @@ -140,7 +141,7 @@ public function it_ignores_provided_countries_when_checking_country() $this->assertFalse($object->isOfCountry('US')); } - /** @test */ + #[Test] public function it_checks_libphonenumber_specific_regions_as_country() { $object = new PhoneNumber('+247501234'); @@ -148,14 +149,14 @@ public function it_checks_libphonenumber_specific_regions_as_country() $this->assertFalse($object->isOfCountry('US')); } - /** @test */ + #[Test] public function it_doesnt_throw_for_antarctica() { $object = new PhoneNumber('012345678', ['AQ', 'BE']); $this->assertEquals('BE', $object->getCountry()); } - /** @test */ + #[Test] public function it_returns_the_type() { $object = new PhoneNumber('012345678', 'BE'); @@ -165,7 +166,7 @@ public function it_returns_the_type() $this->assertEquals('mobile', $object->getType()); } - /** @test */ + #[Test] public function it_returns_the_type_value() { $object = new PhoneNumber('012345678', 'BE'); @@ -175,7 +176,7 @@ public function it_returns_the_type_value() $this->assertEquals(PhoneNumberType::MOBILE, $object->getType(true)); } - /** @test */ + #[Test] public function it_returns_true_when_checking_type_with_correct_name() { $object = new PhoneNumber('012345678', 'BE'); @@ -187,7 +188,7 @@ public function it_returns_true_when_checking_type_with_correct_name() $this->assertTrue($object->isOfType('mobile')); } - /** @test */ + #[Test] public function it_returns_true_when_checking_type_with_correct_value() { $object = new PhoneNumber('012345678', 'BE'); @@ -199,7 +200,7 @@ public function it_returns_true_when_checking_type_with_correct_value() $this->assertTrue($object->isOfType(PhoneNumberType::MOBILE)); } - /** @test */ + #[Test] public function it_returns_false_when_checking_incorrect_type_or_null() { $object = new PhoneNumber('012345678', 'BE'); @@ -215,7 +216,7 @@ public function it_returns_false_when_checking_incorrect_type_or_null() $this->assertFalse($object->isOfType(null)); } - /** @test */ + #[Test] public function it_adds_the_unsure_type_when_checking_fixed_line_or_mobile() { // This number is of type FIXED_LINE_OR_MOBILE. @@ -225,21 +226,21 @@ public function it_adds_the_unsure_type_when_checking_fixed_line_or_mobile() $this->assertTrue($object->isOfType('mobile')); } - /** @test */ + #[Test] public function it_formats_with_format_value() { $object = new PhoneNumber('+3212345678'); $this->assertEquals('012 34 56 78', $object->format(PhoneNumberFormat::NATIONAL)); } - /** @test */ + #[Test] public function it_formats_with_format_name() { $object = new PhoneNumber('+3212345678'); $this->assertEquals('012 34 56 78', $object->format('national')); } - /** @test */ + #[Test] public function it_throws_an_exception_when_formatting_invalid_numbers() { $object = new PhoneNumber('012345678'); @@ -249,7 +250,7 @@ public function it_throws_an_exception_when_formatting_invalid_numbers() $object->format(PhoneNumberFormat::NATIONAL); } - /** @test */ + #[Test] public function it_throws_an_exception_for_invalid_formats() { $object = new PhoneNumber('+3212345678'); @@ -259,7 +260,7 @@ public function it_throws_an_exception_for_invalid_formats() $object->format('foo'); } - /** @test */ + #[Test] public function it_has_an_international_format_shortcut_method() { $object = new PhoneNumber('+3212345678'); @@ -270,7 +271,7 @@ public function it_has_an_international_format_shortcut_method() ); } - /** @test */ + #[Test] public function it_has_a_national_format_shortcut_method() { $object = new PhoneNumber('+3212345678'); @@ -280,7 +281,7 @@ public function it_has_a_national_format_shortcut_method() ); } - /** @test */ + #[Test] public function it_has_an_E164_format_shortcut_method() { $object = new PhoneNumber('012345678', 'BE'); @@ -290,7 +291,7 @@ public function it_has_an_E164_format_shortcut_method() ); } - /** @test */ + #[Test] public function it_has_an_RFC3966_format_shortcut_method() { $object = new PhoneNumber('+3212345678'); @@ -300,7 +301,7 @@ public function it_has_an_RFC3966_format_shortcut_method() ); } - /** @test */ + #[Test] public function it_accepts_numbers_prefixed_with_something() { $object = new PhoneNumber('BE+3212345678'); @@ -314,7 +315,7 @@ public function it_accepts_numbers_prefixed_with_something() $this->assertEquals('012 34 56 78', $object->format(PhoneNumberFormat::NATIONAL)); } - /** @test */ + #[Test] public function it_formats_for_dialing_from_within_a_given_country() { $object = new PhoneNumber('+3212345678'); @@ -323,7 +324,7 @@ public function it_formats_for_dialing_from_within_a_given_country() $this->assertEquals('011 32 12 34 56 78', $object->formatForCountry('US')); } - /** @test */ + #[Test] public function it_formats_for_dialing_on_mobile_from_within_a_given_country() { $object = new PhoneNumber('012 34 56 78', 'BE'); @@ -332,7 +333,7 @@ public function it_formats_for_dialing_on_mobile_from_within_a_given_country() $this->assertEquals('+3212345678', $object->formatForMobileDialingInCountry('US')); } - /** @test */ + #[Test] public function it_throws_an_exception_when_an_invalid_country_is_provided_for_formatting_for_dialing() { $object = new PhoneNumber('+3212345678'); @@ -342,7 +343,7 @@ public function it_throws_an_exception_when_an_invalid_country_is_provided_for_f $object->formatForCountry('foo'); } - /** @test */ + #[Test] public function it_throws_an_exception_when_an_invalid_country_is_provided_for_formatting_for_mobile_dialing() { $object = new PhoneNumber('+3212345678'); @@ -352,7 +353,7 @@ public function it_throws_an_exception_when_an_invalid_country_is_provided_for_f $object->formatForMobileDialingInCountry('foo'); } - /** @test */ + #[Test] public function it_throws_an_exception_on_formatting_when_the_country_is_missing() { $object = new PhoneNumber('45678'); @@ -362,7 +363,7 @@ public function it_throws_an_exception_on_formatting_when_the_country_is_missing $object->formatRFC3966(); } - /** @test */ + #[Test] public function it_throws_an_exception_on_formatting_when_the_country_is_mismatched() { $object = new PhoneNumber('45678', 'BE'); @@ -372,7 +373,7 @@ public function it_throws_an_exception_on_formatting_when_the_country_is_mismatc $object->formatRFC3966(); } - /** @test */ + #[Test] public function it_handles_json_encoding() { $object = new PhoneNumber('+3212345678'); @@ -381,7 +382,7 @@ public function it_handles_json_encoding() $this->assertEquals('"+3212345678"', json_encode($object)); } - /** @test */ + #[Test] public function it_handles_serialization() { $object = new PhoneNumber('+3212345678'); @@ -395,14 +396,14 @@ public function it_handles_serialization() $this->assertEquals('BE', $unserialized->getCountry()); } - /** @test */ + #[Test] public function it_casts_to_string() { $object = new PhoneNumber('012 34 56 78', 'BE'); $this->assertEquals($object->formatE164(), (string) $object); } - /** @test */ + #[Test] public function it_returns_the_original_number_when_unparsable_number_is_cast_to_string() { $object = new PhoneNumber('45678'); @@ -412,14 +413,14 @@ public function it_returns_the_original_number_when_unparsable_number_is_cast_to $this->assertEquals('45678', (string) $object); } - /** @test */ + #[Test] public function it_returns_empty_string_when_null_is_cast_to_string() { $object = new PhoneNumber(null); $this->assertEquals('', (string) $object); } - /** @test */ + #[Test] public function it_gets_the_exceptions_number() { $exception = NumberParseException::countryRequired('12345'); @@ -429,14 +430,14 @@ public function it_gets_the_exceptions_number() $this->assertEquals('12345', $exception->getNumber()); } - /** @test */ + #[Test] public function it_gets_the_exceptions_countries() { $exception = NumberParseException::countryMismatch('12345', ['BE', 'foo']); $this->assertEquals(['BE', 'foo'], $exception->getCountries()); } - /** @test */ + #[Test] public function it_can_check_equality() { $object = new PhoneNumber('012345678', ['AQ', 'BE']); @@ -452,7 +453,7 @@ public function it_can_check_equality() $this->assertFalse($object->equals(new PhoneNumber('012345679', 'BE'))); } - /** @test */ + #[Test] public function it_can_check_inequality() { $object = new PhoneNumber('012345678', ['AQ', 'BE']); @@ -468,7 +469,7 @@ public function it_can_check_inequality() $this->assertFalse($object->notEquals(new PhoneNumber('012345678', 'BE'))); } - /** @test */ + #[Test] public function it_doesnt_throw_for_invalid_numbers_when_checking_equality() { $object = new PhoneNumber('012345678', ['AQ', 'BE']); @@ -477,7 +478,7 @@ public function it_doesnt_throw_for_invalid_numbers_when_checking_equality() $this->assertFalse($object->equals('012345678', 'NL')); } - /** @test */ + #[Test] public function it_doesnt_throw_for_invalid_numbers_when_checking_inequality() { $object = new PhoneNumber('012345678', ['AQ', 'BE']); @@ -485,40 +486,40 @@ public function it_doesnt_throw_for_invalid_numbers_when_checking_inequality() $this->assertTrue($object->notEquals('1234')); $this->assertTrue($object->notEquals('012345678', 'NL')); } - - /** @test */ + + #[Test] public function helper_function_constructs_without_country() { $actual = phone('+32 12 34 56 78'); $expected = new PhoneNumber('+32 12 34 56 78'); $this->assertEquals($expected, $actual); } - - /** @test */ + + #[Test] public function helper_function_constructs_with_string_country() { $actual = phone('012 34 56 78', 'BE'); $expected = new PhoneNumber('012 34 56 78', 'BE'); $this->assertEquals($expected, $actual); } - - /** @test */ + + #[Test] public function helper_function_constructs_with_array_country() { $actual = phone('012 34 56 78', ['BE', 'NL']); $expected = new PhoneNumber('012 34 56 78', ['BE', 'NL']); $this->assertEquals($expected, $actual); } - - /** @test */ + + #[Test] public function helper_function_constructs_with_null_country() { $actual = phone('+32 12 34 56 78', null); $expected = new PhoneNumber('+32 12 34 56 78', null); $this->assertEquals($expected, $actual); } - - /** @test */ + + #[Test] public function helper_function_formats() { $actual = phone('012345678', 'BE', PhoneNumberFormat::NATIONAL); diff --git a/tests/RawPhoneNumberCastTest.php b/tests/RawPhoneNumberCastTest.php index 1f12ce4..0a9175a 100644 --- a/tests/RawPhoneNumberCastTest.php +++ b/tests/RawPhoneNumberCastTest.php @@ -4,12 +4,13 @@ use Illuminate\Database\Eloquent\Model; use InvalidArgumentException; +use PHPUnit\Framework\Attributes\Test; use Propaganistas\LaravelPhone\Casts\RawPhoneNumberCast; use Propaganistas\LaravelPhone\PhoneNumber; class RawPhoneNumberCastTest extends TestCase { - /** @test */ + #[Test] public function it_mutates_to_raw_number() { $model = new ModelWithRawCast; @@ -31,7 +32,7 @@ public function it_mutates_to_raw_number() $this->assertEquals('012-34-56-78', $model->getAttributes()['phone']); } - /** @test */ + #[Test] public function it_gets_phone_object() { $model = new ModelWithRawCast; @@ -40,7 +41,7 @@ public function it_gets_phone_object() $this->assertEquals(PhoneNumber::class, get_class($model->phone)); } - /** @test */ + #[Test] public function it_gets_with_implicit_country_field() { $model = new ModelWithIncompleteRawCast; @@ -52,7 +53,7 @@ public function it_gets_with_implicit_country_field() $this->assertEquals(PhoneNumber::class, get_class($model->phone)); } - /** @test */ + #[Test] public function it_gets_with_explicit_country_field() { $model = new ModelWithRawCastAndCountryField; @@ -64,7 +65,7 @@ public function it_gets_with_explicit_country_field() $this->assertEquals(PhoneNumber::class, get_class($model->phone)); } - /** @test */ + #[Test] public function it_throws_when_accessing_incomplete_raw_cast() { $model = new ModelWithIncompleteRawCast; @@ -73,7 +74,7 @@ public function it_throws_when_accessing_incomplete_raw_cast() $model->phone; } - /** @test */ + #[Test] public function it_gets_phone_object_when_accessing_incomplete_raw_cast_with_international_number() { $model = new ModelWithIncompleteRawCast; @@ -83,7 +84,7 @@ public function it_gets_phone_object_when_accessing_incomplete_raw_cast_with_int $this->assertEquals(PhoneNumber::class, get_class($model->phone)); } - /** @test */ + #[Test] public function it_serializes() { $model = new ModelWithRawCast; diff --git a/tests/RuleTest.php b/tests/RuleTest.php index 2aa841e..813db3a 100644 --- a/tests/RuleTest.php +++ b/tests/RuleTest.php @@ -2,15 +2,14 @@ namespace Propaganistas\LaravelPhone\Tests; -use Illuminate\Validation\Validator; use libphonenumber\PhoneNumberType; -use Propaganistas\LaravelPhone\Exceptions\IncompatibleTypesException; +use PHPUnit\Framework\Attributes\Test; use Propaganistas\LaravelPhone\Rules\Phone; use ReflectionClass; class RuleTest extends TestCase { - /** @test */ + #[Test] public function it_defaults_to_nothing() { $rule = (new Phone); @@ -23,7 +22,7 @@ public function it_defaults_to_nothing() $this->assertFalse($this->getProtectedProperty($rule, 'international')); } - /** @test */ + #[Test] public function it_sets_countries() { $rule = (new Phone)->country('BE'); @@ -33,7 +32,7 @@ public function it_sets_countries() $this->assertEquals(['BE', 'NL'], $this->getProtectedProperty($rule, 'countries')); } - /** @test */ + #[Test] public function it_merges_existing_countries() { $rule = (new Phone)->country('BE'); @@ -42,14 +41,14 @@ public function it_merges_existing_countries() $this->assertEquals(['BE', 'NL'], $this->getProtectedProperty($rule, 'countries')); } - /** @test */ + #[Test] public function it_sets_countryField() { $rule = (new Phone)->countryField('foo'); $this->assertEquals('foo', $this->getProtectedProperty($rule, 'countryField')); } - /** @test */ + #[Test] public function it_sets_types() { $rule = (new Phone)->type('mobile'); @@ -59,7 +58,7 @@ public function it_sets_types() $this->assertEquals(['mobile', 'fixed_line'], $this->getProtectedProperty($rule, 'allowedTypes')); } - /** @test */ + #[Test] public function it_merges_existing_types() { $rule = (new Phone)->type('mobile'); @@ -68,7 +67,7 @@ public function it_merges_existing_types() $this->assertEquals(['mobile', 'fixed_line'], $this->getProtectedProperty($rule, 'allowedTypes')); } - /** @test */ + #[Test] public function it_sets_blocked_types() { $rule = (new Phone)->notType('mobile'); @@ -78,7 +77,7 @@ public function it_sets_blocked_types() $this->assertEquals(['mobile', 'fixed_line'], $this->getProtectedProperty($rule, 'blockedTypes')); } - /** @test */ + #[Test] public function it_merges_existing_blocked_types() { $rule = (new Phone)->notType('mobile'); @@ -87,35 +86,35 @@ public function it_merges_existing_blocked_types() $this->assertEquals(['mobile', 'fixed_line'], $this->getProtectedProperty($rule, 'blockedTypes')); } - /** @test */ + #[Test] public function it_sets_mobile_type_using_shortcut_method() { $rule = (new Phone)->mobile(); $this->assertEquals([PhoneNumberType::MOBILE], $this->getProtectedProperty($rule, 'allowedTypes')); } - /** @test */ + #[Test] public function it_sets_fixed_line_type_using_shortcut_method() { $rule = (new Phone)->fixedLine(); $this->assertEquals([PhoneNumberType::FIXED_LINE], $this->getProtectedProperty($rule, 'allowedTypes')); } - /** @test */ + #[Test] public function it_sets_lenient_mode() { $rule = (new Phone)->lenient(); $this->assertTrue($this->getProtectedProperty($rule, 'lenient')); } - /** @test */ + #[Test] public function it_sets_international_mode() { $rule = (new Phone)->international(); $this->assertTrue($this->getProtectedProperty($rule, 'international')); } - /** @test */ + #[Test] public function it_returns_default_validation_message() { app('translator')->setLocale('xx'); @@ -133,7 +132,7 @@ public function it_returns_default_validation_message() $this->assertEquals('foo', (new Phone)->message()); } - /** @test */ + #[Test] public function it_converts_string_validation_parameters() { $base = (new Phone)->setValidator(validator(['foo' => null])); @@ -172,18 +171,18 @@ public function it_converts_string_validation_parameters() $this->assertTrue($this->getProtectedProperty($rule, 'lenient')); $this->assertTrue($this->getProtectedProperty($rule, 'international')); $this->assertEquals('foo', $this->getProtectedProperty($rule, 'countryField')); - $this->assertEquals(['be','nl'], $this->getProtectedProperty($rule, 'countries')); + $this->assertEquals(['be', 'nl'], $this->getProtectedProperty($rule, 'countries')); $this->assertEquals(['mobile', 'fixed_line'], $this->getProtectedProperty($rule, 'allowedTypes')); $rule = (clone $base)->setParameters(['lenient', 'international', 'foo', 'be', 'nl', '!mobile', '!fixed_line']); $this->assertTrue($this->getProtectedProperty($rule, 'lenient')); $this->assertTrue($this->getProtectedProperty($rule, 'international')); $this->assertEquals('foo', $this->getProtectedProperty($rule, 'countryField')); - $this->assertEquals(['be','nl'], $this->getProtectedProperty($rule, 'countries')); + $this->assertEquals(['be', 'nl'], $this->getProtectedProperty($rule, 'countries')); $this->assertEquals(['mobile', 'fixed_line'], $this->getProtectedProperty($rule, 'blockedTypes')); } - /** @test */ + #[Test] public function it_treats_string_validation_parameters_case_insensitive() { $base = (new Phone)->setValidator(validator(['foo' => null])); @@ -201,7 +200,7 @@ public function it_treats_string_validation_parameters_case_insensitive() $this->assertEquals(['MoBIle'], $this->getProtectedProperty($rule, 'blockedTypes')); } - /** @test */ + #[Test] public function it_treats_coinciding_field_names_as_parameters() { $base = (new Phone)->setValidator(validator([ @@ -221,7 +220,7 @@ public function it_treats_coinciding_field_names_as_parameters() $this->assertTrue($this->getProtectedProperty($rule, 'international')); } - /** @test */ + #[Test] public function it_ignores_invalid_string_validation_parameters() { $base = (new Phone)->setValidator(validator([])); diff --git a/tests/ValidatorTest.php b/tests/ValidatorTest.php index a971f98..aa39e8f 100644 --- a/tests/ValidatorTest.php +++ b/tests/ValidatorTest.php @@ -4,6 +4,7 @@ use Illuminate\Validation\Validator; use libphonenumber\PhoneNumberType; +use PHPUnit\Framework\Attributes\Test; use Propaganistas\LaravelPhone\Exceptions\IncompatibleTypesException; use Propaganistas\LaravelPhone\Rules\Phone; @@ -14,7 +15,7 @@ protected function validate(array $data, array $rules): Validator return $this->app['validator']->make($data, $rules); } - /** @test */ + #[Test] public function it_validates_without_parameters() { $this->assertTrue($this->validate( @@ -33,8 +34,7 @@ public function it_validates_without_parameters() )->passes()); } - - /** @test */ + #[Test] public function it_validates_with_explicit_countries() { $this->assertTrue($this->validate( @@ -44,7 +44,7 @@ public function it_validates_with_explicit_countries() $this->assertTrue($this->validate( ['field' => '012345678'], - ['field' => (new Phone)->country(['NL','BE','US'])] + ['field' => (new Phone)->country(['NL', 'BE', 'US'])] )->passes()); $this->assertFalse($this->validate( @@ -54,11 +54,11 @@ public function it_validates_with_explicit_countries() $this->assertFalse($this->validate( ['field' => '012345678'], - ['field' => (new Phone)->country(['DE','NL','US'])] + ['field' => (new Phone)->country(['DE', 'NL', 'US'])] )->passes()); } - /** @test */ + #[Test] public function it_validates_countries_case_insensitive() { $this->assertTrue($this->validate( @@ -72,7 +72,7 @@ public function it_validates_countries_case_insensitive() )->passes()); } - /** @test */ + #[Test] public function it_validates_with_implicit_country_field() { $this->assertTrue($this->validate( @@ -86,7 +86,7 @@ public function it_validates_with_implicit_country_field() )->passes()); } - /** @test */ + #[Test] public function it_validates_with_custom_country_field() { $this->assertTrue($this->validate( @@ -100,7 +100,7 @@ public function it_validates_with_custom_country_field() )->passes()); } - /** @test */ + #[Test] public function it_validates_country_field_case_insensitive() { $this->assertTrue($this->validate( @@ -114,7 +114,7 @@ public function it_validates_country_field_case_insensitive() )->passes()); } - /** @test */ + #[Test] public function it_validates_with_explicit_countries_and_implicit_country_field_combined() { $this->assertTrue($this->validate( @@ -128,7 +128,7 @@ public function it_validates_with_explicit_countries_and_implicit_country_field_ )->passes()); } - /** @test */ + #[Test] public function it_validates_with_explicit_countries_and_custom_country_field_combined() { $this->assertTrue($this->validate( @@ -142,7 +142,7 @@ public function it_validates_with_explicit_countries_and_custom_country_field_co )->passes()); } - /** @test */ + #[Test] public function it_validates_with_custom_country_field_taking_precedence_over_implicit_country_field() { $this->assertTrue($this->validate( @@ -156,7 +156,7 @@ public function it_validates_with_custom_country_field_taking_precedence_over_im )->passes()); } - /** @test */ + #[Test] public function it_validates_in_international_mode() { $this->assertFalse($this->validate( @@ -180,7 +180,7 @@ public function it_validates_in_international_mode() )->passes()); } - /** @test */ + #[Test] public function it_validates_in_lenient_mode() { $this->assertFalse($this->validate( @@ -204,7 +204,7 @@ public function it_validates_in_lenient_mode() )->passes()); } - /** @test */ + #[Test] public function it_validates_array_input_with_explicit_countries() { $errors = $this->validate( @@ -244,7 +244,7 @@ public function it_validates_array_input_with_explicit_countries() $this->assertEquals(['container.0.field', 'container.1.field'], $errors->keys()); } - /** @test */ + #[Test] public function it_validates_array_input_with_implicity_country_fields() { $errors = $this->validate( @@ -273,7 +273,7 @@ public function it_validates_array_input_with_implicity_country_fields() $this->assertEquals(['container.0.field'], $errors->keys()); } - /** @test */ + #[Test] public function it_validates_array_input_with_custom_country_fields() { $errors = $this->validate( @@ -303,7 +303,7 @@ public function it_validates_array_input_with_custom_country_fields() $this->assertEquals(['container.0.field'], $errors->keys()); } - /** @test */ + #[Test] public function it_validates_type() { $this->assertTrue($this->validate( @@ -317,7 +317,7 @@ public function it_validates_type() )->passes()); } - /** @test */ + #[Test] public function it_validates_type_and_explicit_country_combined() { $this->assertTrue($this->validate( @@ -336,7 +336,7 @@ public function it_validates_type_and_explicit_country_combined() )->passes()); } - /** @test */ + #[Test] public function it_validates_type_and_implicit_country_field_combined() { $this->assertTrue($this->validate( @@ -355,7 +355,7 @@ public function it_validates_type_and_implicit_country_field_combined() )->passes()); } - /** @test */ + #[Test] public function it_validates_type_and_custom_country_field_combined() { $this->assertTrue($this->validate( @@ -374,7 +374,7 @@ public function it_validates_type_and_custom_country_field_combined() )->passes()); } - /** @test */ + #[Test] public function it_validates_type_as_string() { $this->assertTrue($this->validate( @@ -388,7 +388,7 @@ public function it_validates_type_as_string() )->passes()); } - /** @test */ + #[Test] public function it_validates_type_case_insensitive() { $this->assertTrue($this->validate( @@ -402,7 +402,7 @@ public function it_validates_type_case_insensitive() )->passes()); } - /** @test */ + #[Test] public function it_validates_blocked_type() { $this->assertFalse($this->validate( @@ -416,7 +416,7 @@ public function it_validates_blocked_type() )->passes()); } - /** @test */ + #[Test] public function it_validates_blocked_type_and_explicit_country_combined() { $this->assertFalse($this->validate( @@ -435,7 +435,7 @@ public function it_validates_blocked_type_and_explicit_country_combined() )->passes()); } - /** @test */ + #[Test] public function it_validates_blocked_type_and_implicit_country_field_combined() { $this->assertFalse($this->validate( @@ -454,7 +454,7 @@ public function it_validates_blocked_type_and_implicit_country_field_combined() )->passes()); } - /** @test */ + #[Test] public function it_validates_blocked_type_and_custom_country_field_combined() { $this->assertFalse($this->validate( @@ -473,7 +473,7 @@ public function it_validates_blocked_type_and_custom_country_field_combined() )->passes()); } - /** @test */ + #[Test] public function it_validates_blocked_type_as_string() { $this->assertFalse($this->validate( @@ -487,7 +487,7 @@ public function it_validates_blocked_type_as_string() )->passes()); } - /** @test */ + #[Test] public function it_validates_blocked_type_case_insensitive() { $this->assertFalse($this->validate( @@ -501,7 +501,7 @@ public function it_validates_blocked_type_case_insensitive() )->passes()); } - /** @test */ + #[Test] public function it_doesnt_allow_allowed_and_blocked_types_simultaneously() { $this->expectException(IncompatibleTypesException::class); @@ -512,7 +512,7 @@ public function it_doesnt_allow_allowed_and_blocked_types_simultaneously() )->passes(); } - /** @test */ + #[Test] public function it_prevents_parameter_hijacking_through_the_country_field() { $this->assertFalse($this->validate( @@ -521,7 +521,7 @@ public function it_prevents_parameter_hijacking_through_the_country_field() )->passes()); } - /** @test */ + #[Test] public function it_copes_with_nullable_validation_rule() { $this->assertTrue($this->validate( @@ -530,16 +530,16 @@ public function it_copes_with_nullable_validation_rule() )->passes()); } - /** @test */ + #[Test] public function it_copes_with_required_if_validation_rule() { - $this->assertTrue($this->validate( + $this->assertTrue($this->validate( ['other' => 0], ['field' => ['required_if:other,1', (new Phone)->country('BE')]] )->passes()); } - /** @test */ + #[Test] public function it_validates_libphonenumber_specific_regions_as_country() { $this->assertTrue($this->validate(