From a23246ff7cd865d40e7e5d9b81b4e294f4d54a1f Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Thu, 1 Feb 2024 10:22:54 -0800 Subject: [PATCH 1/4] Work around dateTime bug in Respect/Validation 2.3 The DateTime::RFC3339 formats no longer work with valid RFC 3339 timestamps. See https://github.com/Respect/Validation/issues/1442. --- src/MinFraud/Validation/Rules/Event.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/MinFraud/Validation/Rules/Event.php b/src/MinFraud/Validation/Rules/Event.php index ea2a33c6..7f6548fe 100644 --- a/src/MinFraud/Validation/Rules/Event.php +++ b/src/MinFraud/Validation/Rules/Event.php @@ -20,7 +20,12 @@ public function __construct() 'time', v::anyOf( v::dateTime(\DateTime::RFC3339), - v::dateTime(\DateTime::RFC3339_EXTENDED) + v::dateTime(\DateTime::RFC3339_EXTENDED), + // Respect/Validation no longer correctly supports the RFC 3339 + // formats as of 2.3. See + // https://github.com/Respect/Validation/issues/1442. + v::dateTime('Y-m-d\TH:i:sp'), + v::dateTime('Y-m-d\TH:i:s.vp'), ), false ), From 6faa20ac8bb19e44fe8ab3a6b4856c9b9920f05f Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Thu, 1 Feb 2024 10:27:20 -0800 Subject: [PATCH 2/4] Update test for improved messages in Respect\Validation 2.3 --- composer.json | 2 +- .../Test/MinFraud/ReportTransaction/ReportTransactionTest.php | 2 +- tests/MaxMind/Test/MinFraudTest.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index c1c0e3df..111768a4 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "ext-json": "*", "geoip2/geoip2": "^v3.0.0", "maxmind/web-service-common": "^0.9.0", - "respect/validation": "^2.2.4" + "respect/validation": "^2.3.1" }, "require-dev": { "friendsofphp/php-cs-fixer": "3.*", diff --git a/tests/MaxMind/Test/MinFraud/ReportTransaction/ReportTransactionTest.php b/tests/MaxMind/Test/MinFraud/ReportTransaction/ReportTransactionTest.php index 388c2e88..1635c635 100644 --- a/tests/MaxMind/Test/MinFraud/ReportTransaction/ReportTransactionTest.php +++ b/tests/MaxMind/Test/MinFraud/ReportTransaction/ReportTransactionTest.php @@ -112,7 +112,7 @@ public static function requestsMissingRequiredFields(): array public function testUnknownKey(): void { $this->expectException(InvalidInputException::class); - $this->expectExceptionMessage('Must have keys'); + $this->expectExceptionMessage('Must not have keys'); $req = array_merge( Data::minimalRequest(), diff --git a/tests/MaxMind/Test/MinFraudTest.php b/tests/MaxMind/Test/MinFraudTest.php index fbc85d88..9ec89ccd 100644 --- a/tests/MaxMind/Test/MinFraudTest.php +++ b/tests/MaxMind/Test/MinFraudTest.php @@ -278,7 +278,7 @@ public function testMissingIpAddressWithoutValidation(string $class, string $ser public function testUnknownKeys(string $method): void { $this->expectException(InvalidInputException::class); - $this->expectExceptionMessage('Must have keys'); + $this->expectExceptionMessage('Must not have keys'); $this->createMinFraudRequestWithFullResponse( 'insights', @@ -996,7 +996,7 @@ public static function invalidQuantities(): array public function testBadShoppingCartItemWithDoubleArray(): void { $this->expectException(InvalidInputException::class); - $this->expectExceptionMessage('Must have keys'); + $this->expectExceptionMessage('Must not have keys'); $this->createMinFraudRequestWithFullResponse( 'insights', From fbc01fafca99211da4dabcf4263fad550d92be1f Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Thu, 1 Feb 2024 10:55:49 -0800 Subject: [PATCH 3/4] Work around Respect\Validation country code bug As of 2.3, it allows lowercase country codes. See https://github.com/Respect/Validation/issues/1446. --- src/MinFraud/Validation/Rules/Address.php | 2 +- src/MinFraud/Validation/Rules/CreditCard.php | 2 +- .../MaxMind/Test/MinFraud/Validation/Rules/CreditCardTest.php | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/MinFraud/Validation/Rules/Address.php b/src/MinFraud/Validation/Rules/Address.php index 6aadebb1..78fb3ef3 100644 --- a/src/MinFraud/Validation/Rules/Address.php +++ b/src/MinFraud/Validation/Rules/Address.php @@ -18,7 +18,7 @@ public static function keys(): array v::key('address_2', new IntOrString(), false), v::key('city', v::stringType(), false), v::key('company', v::stringType(), false), - v::key('country', v::countryCode(), false), + v::key('country', v::allOf(v::countryCode(), v::uppercase()), false), v::key('first_name', v::stringType(), false), v::key('last_name', v::stringType(), false), v::key('phone_country_code', new TelephoneCountryCode(), false), diff --git a/src/MinFraud/Validation/Rules/CreditCard.php b/src/MinFraud/Validation/Rules/CreditCard.php index 0f55bd59..e11c21ff 100644 --- a/src/MinFraud/Validation/Rules/CreditCard.php +++ b/src/MinFraud/Validation/Rules/CreditCard.php @@ -20,7 +20,7 @@ public function __construct() v::key('bank_name', v::stringType(), false), v::key('bank_phone_country_code', new TelephoneCountryCode(), false), v::key('bank_phone_number', v::stringType(), false), - v::key('country', v::countryCode(), false), + v::key('country', v::allOf(v::countryCode(), v::uppercase()), false), v::key('cvv_result', v::stringType()->length(1, 1), false), v::key('issuer_id_number', v::regex('/^(?:[0-9]{6}|[0-9]{8})$/'), false), v::key('last_digits', v::regex('/^(?:[0-9]{2}|[0-9]{4})$/'), false), diff --git a/tests/MaxMind/Test/MinFraud/Validation/Rules/CreditCardTest.php b/tests/MaxMind/Test/MinFraud/Validation/Rules/CreditCardTest.php index df6147ed..6637666b 100644 --- a/tests/MaxMind/Test/MinFraud/Validation/Rules/CreditCardTest.php +++ b/tests/MaxMind/Test/MinFraud/Validation/Rules/CreditCardTest.php @@ -6,7 +6,6 @@ use MaxMind\MinFraud\Validation\Rules\CreditCard; use PHPUnit\Framework\TestCase; -use Respect\Validation\Exceptions\CountryCodeException; /** * @coversNothing @@ -24,7 +23,7 @@ public function testInvalidCountry($code): void { $validator = new CreditCard(); - $this->expectException(CountryCodeException::class); + $this->expectExceptionMessageMatches('/^country must be a valid country|country must be uppercase$/'); $validator->check([ 'country' => $code, From 694fd258ff8b48c0d2bb8dd901074246b6145eef Mon Sep 17 00:00:00 2001 From: Gregory Oschwald Date: Thu, 1 Feb 2024 11:04:55 -0800 Subject: [PATCH 4/4] Remove now invalid phpstan error pattern --- phpstan.neon | 2 -- 1 file changed, 2 deletions(-) diff --git a/phpstan.neon b/phpstan.neon index c823f0e9..06f84c2d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,5 +4,3 @@ parameters: - src - tests checkMissingIterableValueType: false - ignoreErrors: - - '/Parameter \#\d+ \.\.\.\$rule of static method Respect\\Validation\\StaticValidator::keySet\(\) expects Respect\\Validation\\Rules\\Key, Respect\\Validation\\ChainedValidator given\./'