-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a new validator to check if country code is in the format ISO-3…
…166-1 ALPHA-2.
- Loading branch information
Luís Nóbrega
committed
Nov 29, 2019
1 parent
73689e2
commit 4541cd1
Showing
12 changed files
with
330 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
namespace Lfbn\JsonResumeValidator\Exception\Validation; | ||
|
||
use Exception; | ||
|
||
/** | ||
* Class InvalidCountryCodeException | ||
* @package Lfbn\JsonResumeValidator\Exception | ||
*/ | ||
class InvalidCountryCodeException extends Exception | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Lfbn\JsonResumeValidator\Validator\Handler; | ||
|
||
use Adbar\Dot; | ||
use Exception; | ||
use League\ISO3166\ISO3166; | ||
use Lfbn\JsonResumeValidator\Exception\Validation\InvalidCountryCodeException; | ||
|
||
/** | ||
* Class CountryCodeValidationHandler | ||
* @package Lfbn\JsonResumeValidator\Validator\Handler | ||
*/ | ||
class CountryCodeValidationHandler extends AbstractValidationHandler | ||
{ | ||
|
||
/** | ||
* @param array $jsonResume | ||
* @return bool | ||
* @throws InvalidCountryCodeException | ||
*/ | ||
public function handle(array $jsonResume): bool | ||
{ | ||
$dot = new Dot($jsonResume); | ||
$countryCode = $dot->get('basics.location.countryCode'); | ||
|
||
if (empty($countryCode)) { | ||
return true; | ||
} | ||
|
||
try { | ||
(new ISO3166())->alpha2($countryCode); | ||
} catch (Exception $e) { | ||
throw new InvalidCountryCodeException( | ||
"The country code ({$countryCode}) is not compliant." | ||
); | ||
} | ||
|
||
return parent::handle($jsonResume); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Lfbn\JsonResumeValidator\Tests\Integration; | ||
|
||
use Lfbn\JsonResumeValidator\Exception\FileDoesNotExistsException; | ||
use Lfbn\JsonResumeValidator\Exception\FileIsNotAValidJsonException; | ||
use Lfbn\JsonResumeValidator\Exception\Validation\InvalidCountryCodeException; | ||
use Lfbn\JsonResumeValidator\Exception\Validation\MandatoryFieldsMissingException; | ||
use Lfbn\JsonResumeValidator\Exception\Validation\SchemaViolationException; | ||
use Lfbn\JsonResumeValidator\JsonResumeValidator; | ||
|
||
/** | ||
* Class InvalidCountryTest | ||
* @package Lfbn\JsonResumeValidator\Tests\Integration | ||
*/ | ||
class InvalidCountryTest extends BaseTest | ||
{ | ||
|
||
/** | ||
* @throws FileDoesNotExistsException | ||
* @throws FileIsNotAValidJsonException | ||
* @throws MandatoryFieldsMissingException | ||
* @throws SchemaViolationException | ||
* @throws InvalidCountryCodeException | ||
*/ | ||
public function testItShouldValidateIfTheCountryIsValid(): void | ||
{ | ||
$this->expectException(InvalidCountryCodeException::class); | ||
|
||
$resume = JsonResumeValidator::load( | ||
$this->getDataFullPath('invalid/invalid-country.json') | ||
); | ||
|
||
$this->assertTrue($resume->isValid()); | ||
} | ||
} |
Oops, something went wrong.