From 5b292a58e792420bcf7e93ecb6fc97de8a9be88e Mon Sep 17 00:00:00 2001 From: pixelpeter Date: Fri, 15 Mar 2019 11:56:23 +0100 Subject: [PATCH] ADD: functionality to validate arrays with dot notation (data.*.field) --- src/IsoCodesValidationServiceProvider.php | 1 + src/IsoCodesValidator.php | 36 +- tests/IsoCodesValidatorTest.php | 485 +++----------------- tests/fixtures/invalid.php | 378 +++++++++++++++ tests/fixtures/invalid_wit_dot_notation.php | 76 +++ tests/fixtures/invalid_with_references.php | 8 + tests/fixtures/valid.php | 37 ++ tests/fixtures/valid_wit_dot_notation.php | 69 +++ tests/fixtures/valid_with_references.php | 8 + 9 files changed, 670 insertions(+), 428 deletions(-) create mode 100644 tests/fixtures/invalid.php create mode 100644 tests/fixtures/invalid_wit_dot_notation.php create mode 100644 tests/fixtures/invalid_with_references.php create mode 100644 tests/fixtures/valid.php create mode 100644 tests/fixtures/valid_wit_dot_notation.php create mode 100644 tests/fixtures/valid_with_references.php diff --git a/src/IsoCodesValidationServiceProvider.php b/src/IsoCodesValidationServiceProvider.php index d184147..ca4ef78 100644 --- a/src/IsoCodesValidationServiceProvider.php +++ b/src/IsoCodesValidationServiceProvider.php @@ -24,6 +24,7 @@ public function boot() // set the validation error messages foreach (get_class_methods('Pixelpeter\IsoCodesValidation\IsoCodesValidator') as $method) { $key = $this->getTranslationKeyFromMethodName($method); + $messages[$key] = $this->getErrorMessage($translator, $messages, $key); } diff --git a/src/IsoCodesValidator.php b/src/IsoCodesValidator.php index 7eb71cb..568543b 100644 --- a/src/IsoCodesValidator.php +++ b/src/IsoCodesValidator.php @@ -241,7 +241,7 @@ public function validateIpaddress($attribute, $value, $parameters) public function validateIsbn($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'isbn'); - $type = Arr::get($this->data, $parameters[0]); + $type = $this->prepareReference($attribute, $parameters); return $this->runIsoCodesValidator(\IsoCodes\Isbn::class, $value, $type); } @@ -322,7 +322,7 @@ public function validateNif($attribute, $value, $parameters) public function validateOrganismeType12NormeB2($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'organisme_type12_norme_b2'); - $clef = Arr::get($this->data, $parameters[0]); + $clef = $this->prepareReference($attribute, $parameters); return $this->runIsoCodesValidator(\IsoCodes\OrganismeType12NormeB2::class, $value, $clef); } @@ -338,7 +338,7 @@ public function validateOrganismeType12NormeB2($attribute, $value, $parameters) public function validatePhonenumber($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'phonenumber'); - $country = Arr::get($this->data, $parameters[0]); + $country = $this->prepareReference($attribute, $parameters); return $this->runIsoCodesValidator(\IsoCodes\PhoneNumber::class, $value, $country); } @@ -497,11 +497,27 @@ public function validateVat($attribute, $value, $parameters) public function validateZipcode($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'zipcode'); - $country = Arr::get($this->data, $parameters[0]); + $country = $this->prepareReference($attribute, $parameters); return $this->runIsoCodesValidator(\IsoCodes\ZipCode::class, $value, $country); } + /** + * Prepare/get the reference when defined in dot notation + * + * @param $attribute + * @param $parameters + * @return mixed + */ + protected function prepareReference($attribute, $parameters) + { + if ($keys = $this->getExplicitKeys($attribute)) { + $parameters = $this->replaceAsterisksInParameters($parameters, $keys); + } + + return Arr::get($this->data, $parameters[0], $parameters[0]); + } + /** * Execute the validation function * and catch every other Exception from underlying libraries @@ -532,9 +548,9 @@ protected function runIsoCodesValidator($validator, $value, $reference = '') * @param $parameter * @return mixed */ - protected function countryReplacer($message, $parameter) + protected function countryReplacer($message, $reference) { - return str_replace(':country', Arr::get($this->data, $parameter[0]), $message); + return str_replace(':country', $reference, $message); } /** @@ -896,8 +912,10 @@ public function replaceOrganismeType12NormeB2($message, $attribute, $rule, $para */ protected function replacePhonenumber($message, $attribute, $rule, $parameter) { + $reference = $this->prepareReference($attribute, $parameter); + $message = $this->valueReplacer($message, $attribute); - $message = $this->countryReplacer($message, $parameter); + $message = $this->countryReplacer($message, $reference); return $message; } @@ -1067,8 +1085,10 @@ public function replaceVat($message, $attribute, $rule, $parameter) */ public function replaceZipcode($message, $attribute, $rule, $parameter) { + $reference = $this->prepareReference($attribute, $parameter); + $message = $this->valueReplacer($message, $attribute); - $message = $this->countryReplacer($message, $parameter); + $message = $this->countryReplacer($message, $reference); return $message; } diff --git a/tests/IsoCodesValidatorTest.php b/tests/IsoCodesValidatorTest.php index 00faff3..354f1fb 100644 --- a/tests/IsoCodesValidatorTest.php +++ b/tests/IsoCodesValidatorTest.php @@ -60,6 +60,26 @@ public function it_validates_correctly_with_references($field, $value, $referenc $this->assertTrue($validator->passes()); } + /** + * DataProvider for simple rules + * + * @return array + */ + public function validDataProvider() + { + return include_once(__DIR__.'/fixtures/valid.php'); + } + + /** + * DataProvider for failing tests + * + * @return array + */ + public function invalidDataProvider() + { + return include_once(__DIR__.'/fixtures/invalid.php'); + } + /** * DataProvider for rules with references * @@ -67,440 +87,65 @@ public function it_validates_correctly_with_references($field, $value, $referenc */ public function validDataWithReferencesProvider() { - return [ - ['isbn', '978-88-8183-718-2', 'type', 13], - ['organisme_type12_norme_b2', '76031208', 'clef', 2], - ['phonenumber', '+1-650-798-2800', 'country', 'US'], - ['zipcode', '1234AA', 'country', 'NL'] - ]; + return include_once(__DIR__.'/fixtures/valid_with_references.php'); } /** - * DataProvider for simple rules + * DataProvider for arrays with dot notation * * @return array */ - public function validDataProvider() + public function validDataWithDotNotationProvider() { - return [ - ['bban', '15459450000411700920U62'], - ['bsn', '075278431'], - ['cif', 'N0032484H'], - ['creditcard', '4111111111111111'], - ['ean8', '90311017'], - ['ean13', '4719512002889'], - ['gdti', '4719512002889 1234567890 123456'], - ['gln', '0614141000012'], - ['grai', '04719512002889 1234567890 12345A'], - ['gsrn', '735005385000000011'], - ['gtin8', '12345670'], - ['gtin12', '1-23456-78999-9'], - ['gtin13', '4006381333931'], - ['gtin14', '12345678901231'], - ['iban', 'AL86751639367318444714198669'], - ['insee', '253012B073004'], - ['ipaddress', '73.194.66.94'], - ['isin', 'US0378331005'], - ['ismn', '979-0-2600-0043-8'], - ['iswc', 'T-000.000.001-0'], - ['mac', '01-2d-4c-ef-89-59'], - ['nif', '04381012H'], - ['sedol', 'B0YBKJ7'], - ['siren', 523311082], - ['siret', 33493272000017], - ['sscc', '340123450000000000'], - ['ssn', '651-01-3431'], - ['structured_communication', '123456789002'], - ['swift_bic', 'BCEELULL'], - ['udi', '07610221010301'], - ['uknin', 'EH123456A'], - ['upca', '1-23456-78999-9'], - ['vat', 'LV12345678901'], - ]; + return include_once(__DIR__.'/fixtures/valid_wit_dot_notation.php'); } /** - * DataProvider for failing tests + * DataProvider for arrays with dot notation * * @return array */ - public function invalidDataProvider() + public function invalidDataWithDotNotationProvider() { - return [ - // BBAN - [ - 'payload' => [ - 'bban' => 'invalid' - ], - 'rules' => [ - 'bban' => 'bban' - ], - 'message' => 'The value "invalid" of bban is not a valid BBAN code.' - ], - // BSN - [ - 'payload' => [ - 'bsn' => 'invalid' - ], - 'rules' => [ - 'bsn' => 'bsn' - ], - 'message' => 'The value "invalid" of bsn is not a valid BSN.' - ], - // CIF - [ - 'payload' => [ - 'cif' => 'invalid' - ], - 'rules' => [ - 'cif' => 'cif' - ], - 'message' => 'The value "invalid" of cif is not a valid CIF code.' - ], - // CREDITCARD - [ - 'payload' => [ - 'creditcard' => 'invalid' - ], - 'rules' => [ - 'creditcard' => 'creditcard' - ], - 'message' => 'The value "invalid" of creditcard is not a valid credit card number.' - ], - // EAN8 - [ - 'payload' => [ - 'ean8' => 'invalid' - ], - 'rules' => [ - 'ean8' => 'ean8' - ], - 'message' => 'The value "invalid" of ean8 is not a valid EAN8 code.' - ], - // EAN13 - [ - 'payload' => [ - 'ean13' => 'invalid' - ], - 'rules' => [ - 'ean13' => 'ean13' - ], - 'message' => 'The value "invalid" of ean13 is not a valid EAN13 code.' - ], - // GDTI - [ - 'payload' => [ - 'gdti' => 'invalid' - ], - 'rules' => [ - 'gdti' => 'gdti' - ], - 'message' => 'The value "invalid" of gdti is not a valid Global Document Type Identifier (GDTI).' - ], - // GLN - [ - 'payload' => [ - 'gln' => 'invalid' - ], - 'rules' => [ - 'gln' => 'gln' - ], - 'message' => 'The value "invalid" of gln is not a valid Global Location Number (GLN).' - ], - // GRAI - [ - 'payload' => [ - 'grai' => 'invalid' - ], - 'rules' => [ - 'grai' => 'grai' - ], - 'message' => 'The value "invalid" of grai is not a valid Global Returnable Asset Identifier.' - ], - // GSRN - [ - 'payload' => [ - 'gsrn' => 'invalid' - ], - 'rules' => [ - 'gsrn' => 'gsrn' - ], - 'message' => 'The value "invalid" of gsrn is not a valid Global Service Relation Number (GS1).' - ], - // GTIN8 - [ - 'payload' => [ - 'gtin8' => 'invalid' - ], - 'rules' => [ - 'gtin8' => 'gtin8' - ], - 'message' => 'The value "invalid" of gtin8 is not a valid GTIN-8 code.' - ], - // GTIN12 - [ - 'payload' => [ - 'gtin12' => 'invalid' - ], - 'rules' => [ - 'gtin12' => 'gtin12' - ], - 'message' => 'The value "invalid" of gtin12 is not a valid GTIN-12 code.' - ], - // GTIN13 - [ - 'payload' => [ - 'gtin13' => 'invalid' - ], - 'rules' => [ - 'gtin13' => 'gtin13' - ], - 'message' => 'The value "invalid" of gtin13 is not a valid GTIN-13 code.' - ], - // GTIN14 - [ - 'payload' => [ - 'gtin14' => 'invalid' - ], - 'rules' => [ - 'gtin14' => 'gtin14' - ], - 'message' => 'The value "invalid" of gtin14 is not a valid GTIN-14 code.' - ], - // IBAN - [ - 'payload' => [ - 'iban' => 'invalid' - ], - 'rules' => [ - 'iban' => 'iban' - ], - 'message' => 'The value "invalid" of iban is not a valid IBAN.' - ], - // INSEE - [ - 'payload' => [ - 'insee' => 'invalid' - ], - 'rules' => [ - 'insee' => 'insee' - ], - 'message' => 'The value "invalid" of insee is not a valid INSEE code.' - ], - // IP - [ - 'payload' => [ - 'ipaddress' => 'invalid' - ], - 'rules' => [ - 'ipaddress' => 'ipaddress' - ], - 'message' => 'The value "invalid" of ipaddress is not a valid ip address.' - ], - // ISBN - [ - 'payload' => [ - 'isbn' => 'invalid', - 'type' => 13 - ], - 'rules' => [ - 'isbn' => 'isbn:type' - ], - 'message' => 'The value "invalid" of isbn is not a valid ISBN.' - ], - // ISIN - [ - 'payload' => [ - 'isin' => 'invalid' - ], - 'rules' => [ - 'isin' => 'isin' - ], - 'message' => 'The value "invalid" of isin is not a valid ISIN.' - ], - // ISMN - [ - 'payload' => [ - 'ismn' => 'invalid' - ], - 'rules' => [ - 'ismn' => 'ismn' - ], - 'message' => 'The value "invalid" of ismn is not a valid International Standard Music Number or ISMN (ISO 10957)', - ], - // ISWC - [ - 'payload' => [ - 'iswc' => 'invalid' - ], - 'rules' => [ - 'iswc' => 'iswc' - ], - 'message' => 'The value "invalid" of iswc is not a valid International Standard Musical Work Code (ISWC)' - ], - // MAC - [ - 'payload' => [ - 'mac' => 'invalid' - ], - 'rules' => [ - 'mac' => 'mac' - ], - 'message' => 'The value "invalid" of mac is not a valid MAC address.' - ], - // NIF - [ - 'payload' => [ - 'nif' => 'invalid' - ], - 'rules' => [ - 'nif' => 'nif' - ], - 'message' => 'The value "invalid" of nif is not a valid NIF.' - ], - // ORGANISME_TYPE12_NORME_B2 - [ - 'payload' => [ - 'organisme_type12_norme_b2' => 'invalid', - 'clef' => 2 - ], - 'rules' => [ - 'organisme_type12_norme_b2' => 'organisme_type12_norme_b2:clef' - ], - 'message' => 'The value "invalid" of organisme type12 norme b2 is not a valid Organisme Type12 Norme B2.' - ], - // PHONE NUMBER - [ - 'payload' => [ - 'country' => 'GB', - 'phonenumber' => 'invalid' - ], - 'rules' => [ - 'phonenumber' => 'phonenumber:country' - ], - 'message' => 'The value "invalid" of phonenumber is not valid for "GB".' - ], - // SEDOL - [ - 'payload' => [ - 'sedol' => 'invalid' - ], - 'rules' => [ - 'sedol' => 'sedol' - ], - 'message' => 'The value "invalid" of sedol is not a valid SEDOL.' - ], - // SIREN - [ - 'payload' => [ - 'siren' => 'invalid' - ], - 'rules' => [ - 'siren' => 'siren' - ], - 'message' => 'The value "invalid" of siren is not a valid SIREN code.' - ], - // SIRET - [ - 'payload' => [ - 'siret' => 'invalid' - ], - 'rules' => [ - 'siret' => 'siret' - ], - 'message' => 'The value "invalid" of siret is not a valid SIRET code.' - ], - // SSCC - [ - 'payload' => [ - 'sscc' => 'invalid' - ], - 'rules' => [ - 'sscc' => 'sscc' - ], - 'message' => 'The value "invalid" of sscc is not a valid SSCC.' - ], - // SSN - [ - 'payload' => [ - 'ssn' => 'invalid' - ], - 'rules' => [ - 'ssn' => 'ssn' - ], - 'message' => 'The value "invalid" of ssn is not a valid SSN.' - ], - // STRUCTURED_COMMUNICATION - [ - 'payload' => [ - 'structured_communication' => 'invalid' - ], - 'rules' => [ - 'structured_communication' => 'structured_communication' - ], - 'message' => 'The value "invalid" of structured communication is not a valid structured communication code.' - ], - // SWIFT_BIC - [ - 'payload' => [ - 'swift_bic' => 'invalid' - ], - 'rules' => [ - 'swift_bic' => 'swift_bic' - ], - 'message' => 'The value "invalid" of swift bic is not a valid SWIFT/BIC.' - ], - // UDI - [ - 'payload' => [ - 'udi' => 'invalid' - ], - 'rules' => [ - 'udi' => 'udi' - ], - 'message' => 'The value "invalid" of udi is not a valid UDI.' - ], - // UKNIN - [ - 'payload' => [ - 'uknin' => 'invalid' - ], - 'rules' => [ - 'uknin' => 'uknin' - ], - 'message' => 'The value "invalid" of uknin is not a valid UK National Insurance Number.' - ], - // UPCA - [ - 'payload' => [ - 'upca' => 'invalid' - ], - 'rules' => [ - 'upca' => 'upca' - ], - 'message' => 'The value "invalid" of upca is not a valid UPCA.' - ], - // VAT - [ - 'payload' => [ - 'vat' => 'invalid' - ], - 'rules' => [ - 'vat' => 'vat' - ], - 'message' => 'The value "invalid" of vat is not a valid VAT.' - ], - // ZIPCODE - [ - 'payload' => [ - 'country' => 'GB', - 'zipcode' => 63741 - ], - 'rules' => [ - 'zipcode' => 'zipcode:country' - ], - 'message' => 'The value "63741" of zipcode is not valid for "GB".' - ], + return include_once(__DIR__.'/fixtures/invalid_wit_dot_notation.php'); + } + + /** + * Test validator can work on arrays with dot notation + * and returns true for valid data + * + * @test + * @dataProvider validDataWithDotNotationProvider + */ + public function it_validates_correctly_with_dot_notation($data, $rule) + { + $payload = [ + 'data' => $data ]; + + $validator = Validator::make($payload, $rule); + + $this->assertTrue($validator->passes()); + $this->assertEmpty($validator->errors()->all()); + } + + /** + * Test the correct error messages ist returned + * on arrays with dot notation + * + * @test + * @dataProvider invalidDataWithDotNotationProvider + */ + public function validator_returns_correct_error_message_with_dot_notation($data, $rule, $error_message) + { + $payload = [ + 'data' => $data + ]; + + $validator = Validator::make($payload, $rule); + + $this->assertTrue($validator->fails()); + $this->assertCount(2, $validator->errors()->all()); + $this->assertEquals($error_message[0], $validator->errors()->first()); } } diff --git a/tests/fixtures/invalid.php b/tests/fixtures/invalid.php new file mode 100644 index 0000000..5542899 --- /dev/null +++ b/tests/fixtures/invalid.php @@ -0,0 +1,378 @@ + [ + 'bban' => 'invalid' + ], + 'rules' => [ + 'bban' => 'bban' + ], + 'message' => 'The value "invalid" of bban is not a valid BBAN code.' + ], + // BSN + [ + 'payload' => [ + 'bsn' => 'invalid' + ], + 'rules' => [ + 'bsn' => 'bsn' + ], + 'message' => 'The value "invalid" of bsn is not a valid BSN.' + ], + // CIF + [ + 'payload' => [ + 'cif' => 'invalid' + ], + 'rules' => [ + 'cif' => 'cif' + ], + 'message' => 'The value "invalid" of cif is not a valid CIF code.' + ], + // CREDITCARD + [ + 'payload' => [ + 'creditcard' => 'invalid' + ], + 'rules' => [ + 'creditcard' => 'creditcard' + ], + 'message' => 'The value "invalid" of creditcard is not a valid credit card number.' + ], + // EAN8 + [ + 'payload' => [ + 'ean8' => 'invalid' + ], + 'rules' => [ + 'ean8' => 'ean8' + ], + 'message' => 'The value "invalid" of ean8 is not a valid EAN8 code.' + ], + // EAN13 + [ + 'payload' => [ + 'ean13' => 'invalid' + ], + 'rules' => [ + 'ean13' => 'ean13' + ], + 'message' => 'The value "invalid" of ean13 is not a valid EAN13 code.' + ], + // GDTI + [ + 'payload' => [ + 'gdti' => 'invalid' + ], + 'rules' => [ + 'gdti' => 'gdti' + ], + 'message' => 'The value "invalid" of gdti is not a valid Global Document Type Identifier (GDTI).' + ], + // GLN + [ + 'payload' => [ + 'gln' => 'invalid' + ], + 'rules' => [ + 'gln' => 'gln' + ], + 'message' => 'The value "invalid" of gln is not a valid Global Location Number (GLN).' + ], + // GRAI + [ + 'payload' => [ + 'grai' => 'invalid' + ], + 'rules' => [ + 'grai' => 'grai' + ], + 'message' => 'The value "invalid" of grai is not a valid Global Returnable Asset Identifier.' + ], + // GSRN + [ + 'payload' => [ + 'gsrn' => 'invalid' + ], + 'rules' => [ + 'gsrn' => 'gsrn' + ], + 'message' => 'The value "invalid" of gsrn is not a valid Global Service Relation Number (GS1).' + ], + // GTIN8 + [ + 'payload' => [ + 'gtin8' => 'invalid' + ], + 'rules' => [ + 'gtin8' => 'gtin8' + ], + 'message' => 'The value "invalid" of gtin8 is not a valid GTIN-8 code.' + ], + // GTIN12 + [ + 'payload' => [ + 'gtin12' => 'invalid' + ], + 'rules' => [ + 'gtin12' => 'gtin12' + ], + 'message' => 'The value "invalid" of gtin12 is not a valid GTIN-12 code.' + ], + // GTIN13 + [ + 'payload' => [ + 'gtin13' => 'invalid' + ], + 'rules' => [ + 'gtin13' => 'gtin13' + ], + 'message' => 'The value "invalid" of gtin13 is not a valid GTIN-13 code.' + ], + // GTIN14 + [ + 'payload' => [ + 'gtin14' => 'invalid' + ], + 'rules' => [ + 'gtin14' => 'gtin14' + ], + 'message' => 'The value "invalid" of gtin14 is not a valid GTIN-14 code.' + ], + // IBAN + [ + 'payload' => [ + 'iban' => 'invalid' + ], + 'rules' => [ + 'iban' => 'iban' + ], + 'message' => 'The value "invalid" of iban is not a valid IBAN.' + ], + // INSEE + [ + 'payload' => [ + 'insee' => 'invalid' + ], + 'rules' => [ + 'insee' => 'insee' + ], + 'message' => 'The value "invalid" of insee is not a valid INSEE code.' + ], + // IP + [ + 'payload' => [ + 'ipaddress' => 'invalid' + ], + 'rules' => [ + 'ipaddress' => 'ipaddress' + ], + 'message' => 'The value "invalid" of ipaddress is not a valid ip address.' + ], + // ISBN + [ + 'payload' => [ + 'isbn' => 'invalid', + 'type' => 13 + ], + 'rules' => [ + 'isbn' => 'isbn:type' + ], + 'message' => 'The value "invalid" of isbn is not a valid ISBN.' + ], + // ISIN + [ + 'payload' => [ + 'isin' => 'invalid' + ], + 'rules' => [ + 'isin' => 'isin' + ], + 'message' => 'The value "invalid" of isin is not a valid ISIN.' + ], + // ISMN + [ + 'payload' => [ + 'ismn' => 'invalid' + ], + 'rules' => [ + 'ismn' => 'ismn' + ], + 'message' => 'The value "invalid" of ismn is not a valid International Standard Music Number or ISMN (ISO 10957)', + ], + // ISWC + [ + 'payload' => [ + 'iswc' => 'invalid' + ], + 'rules' => [ + 'iswc' => 'iswc' + ], + 'message' => 'The value "invalid" of iswc is not a valid International Standard Musical Work Code (ISWC)' + ], + // MAC + [ + 'payload' => [ + 'mac' => 'invalid' + ], + 'rules' => [ + 'mac' => 'mac' + ], + 'message' => 'The value "invalid" of mac is not a valid MAC address.' + ], + // NIF + [ + 'payload' => [ + 'nif' => 'invalid' + ], + 'rules' => [ + 'nif' => 'nif' + ], + 'message' => 'The value "invalid" of nif is not a valid NIF.' + ], + // ORGANISME_TYPE12_NORME_B2 + [ + 'payload' => [ + 'organisme_type12_norme_b2' => 'invalid', + 'clef' => 2 + ], + 'rules' => [ + 'organisme_type12_norme_b2' => 'organisme_type12_norme_b2:clef' + ], + 'message' => 'The value "invalid" of organisme type12 norme b2 is not a valid Organisme Type12 Norme B2.' + ], + // PHONE NUMBER + [ + 'payload' => [ + 'country' => 'GB', + 'phonenumber' => 'invalid' + ], + 'rules' => [ + 'phonenumber' => 'phonenumber:country' + ], + 'message' => 'The value "invalid" of phonenumber is not valid for "GB".' + ], + // SEDOL + [ + 'payload' => [ + 'sedol' => 'invalid' + ], + 'rules' => [ + 'sedol' => 'sedol' + ], + 'message' => 'The value "invalid" of sedol is not a valid SEDOL.' + ], + // SIREN + [ + 'payload' => [ + 'siren' => 'invalid' + ], + 'rules' => [ + 'siren' => 'siren' + ], + 'message' => 'The value "invalid" of siren is not a valid SIREN code.' + ], + // SIRET + [ + 'payload' => [ + 'siret' => 'invalid' + ], + 'rules' => [ + 'siret' => 'siret' + ], + 'message' => 'The value "invalid" of siret is not a valid SIRET code.' + ], + // SSCC + [ + 'payload' => [ + 'sscc' => 'invalid' + ], + 'rules' => [ + 'sscc' => 'sscc' + ], + 'message' => 'The value "invalid" of sscc is not a valid SSCC.' + ], + // SSN + [ + 'payload' => [ + 'ssn' => 'invalid' + ], + 'rules' => [ + 'ssn' => 'ssn' + ], + 'message' => 'The value "invalid" of ssn is not a valid SSN.' + ], + // STRUCTURED_COMMUNICATION + [ + 'payload' => [ + 'structured_communication' => 'invalid' + ], + 'rules' => [ + 'structured_communication' => 'structured_communication' + ], + 'message' => 'The value "invalid" of structured communication is not a valid structured communication code.' + ], + // SWIFT_BIC + [ + 'payload' => [ + 'swift_bic' => 'invalid' + ], + 'rules' => [ + 'swift_bic' => 'swift_bic' + ], + 'message' => 'The value "invalid" of swift bic is not a valid SWIFT/BIC.' + ], + // UDI + [ + 'payload' => [ + 'udi' => 'invalid' + ], + 'rules' => [ + 'udi' => 'udi' + ], + 'message' => 'The value "invalid" of udi is not a valid UDI.' + ], + // UKNIN + [ + 'payload' => [ + 'uknin' => 'invalid' + ], + 'rules' => [ + 'uknin' => 'uknin' + ], + 'message' => 'The value "invalid" of uknin is not a valid UK National Insurance Number.' + ], + // UPCA + [ + 'payload' => [ + 'upca' => 'invalid' + ], + 'rules' => [ + 'upca' => 'upca' + ], + 'message' => 'The value "invalid" of upca is not a valid UPCA.' + ], + // VAT + [ + 'payload' => [ + 'vat' => 'invalid' + ], + 'rules' => [ + 'vat' => 'vat' + ], + 'message' => 'The value "invalid" of vat is not a valid VAT.' + ], + // ZIPCODE + [ + 'payload' => [ + 'country' => 'GB', + 'zipcode' => 63741 + ], + 'rules' => [ + 'zipcode' => 'zipcode:country' + ], + 'message' => 'The value "63741" of zipcode is not valid for "GB".' + ], +]; diff --git a/tests/fixtures/invalid_wit_dot_notation.php b/tests/fixtures/invalid_wit_dot_notation.php new file mode 100644 index 0000000..36f1d0f --- /dev/null +++ b/tests/fixtures/invalid_wit_dot_notation.php @@ -0,0 +1,76 @@ + [ + [ + 'country' => 'DE', + 'zipcode' => 'invalid' + ], + [ + 'country' => 'AT', + 'zipcode' => 'invalid' + ] + ], + 'rule' => [ + 'data.*.zipcode' => 'zipcode:data.*.country' + ], + 'errors' => [ + 'The value "invalid" of data.0.zipcode is not valid for "DE".' + ] + ], + [ + 'data' => [ + [ + 'country' => 'DE', + 'phonenumber' => 'invalid' + ], + [ + 'country' => 'US', + 'phonenumber' => 'invalid' + ] + ], + 'rule' => [ + 'data.*.phonenumber' => 'phonenumber:data.*.country' + ], + 'errors' => [ + 'The value "invalid" of data.0.phonenumber is not valid for "DE".' + ] + ], + [ + 'data' => [ + [ + 'type' => 10, + 'isbn' => 'invalid' + ], + [ + 'type' => 13, + 'isbn' => 'invalid' + ] + ], + 'rule' => [ + 'data.*.isbn' => 'isbn:data.*.type' + ], + 'errors' => [ + 'The value "invalid" of data.0.isbn is not a valid ISBN.' + ] + ], + [ + 'data' => [ + [ + 'clef' => 2, + 'organisme_type12_norme_b2' => 'invalid' + ], + [ + 'clef' => 2, + 'organisme_type12_norme_b2' => 'invalid' + ] + ], + 'rule' => [ + 'data.*.organisme_type12_norme_b2' => 'organisme_type12_norme_b2:data.*.clef' + ], + 'errors' => [ + 'The value "invalid" of data.0.organisme_type12_norme_b2 is not a valid Organisme Type12 Norme B2.' + ] + ] +]; diff --git a/tests/fixtures/invalid_with_references.php b/tests/fixtures/invalid_with_references.php new file mode 100644 index 0000000..2805014 --- /dev/null +++ b/tests/fixtures/invalid_with_references.php @@ -0,0 +1,8 @@ + [ + [ + 'country' => 'DE', + 'zipcode' => 63741 + ], + [ + 'country' => 'AT', + 'zipcode' => 1180 + ] + ], + 'rule' => [ + 'data.*.zipcode' => 'zipcode:data.*.country' + ] + ], + [ + 'data' => [ + [ + 'country' => 'DE', + 'phonenumber' => '035384-08723' + ], + [ + 'country' => 'US', + 'phonenumber' => '+1-650-798-2800' + ] + ], + 'rule' => [ + 'data.*.phonenumber' => 'phonenumber:data.*.country' + ] + ], + [ + 'data' => [ + [ + 'type' => 10, + 'isbn' => '3-598-21500-2' + ], + [ + 'type' => 13, + 'isbn' => '978-88-8183-718-2' + ] + ], + 'rule' => [ + 'data.*.isbn' => 'isbn:data.*.type' + ] + ], + [ + 'data' => [ + [ + 'clef' => 2, + 'organisme_type12_norme_b2' => '76031208' + ], + [ + 'clef' => 2, + 'organisme_type12_norme_b2' => '76031208' + ] + ], + 'rule' => [ + 'data.*.organisme_type12_norme_b2' => 'organisme_type12_norme_b2:data.*.clef' + ] + ] +]; + + + +// ['organisme_type12_norme_b2', '76031208', 'clef', 2], + diff --git a/tests/fixtures/valid_with_references.php b/tests/fixtures/valid_with_references.php new file mode 100644 index 0000000..2805014 --- /dev/null +++ b/tests/fixtures/valid_with_references.php @@ -0,0 +1,8 @@ +