Increase tests for "CountryCode" rule

- Add alpha-3 and numeric country codes and unit test for it
- Add new integration tests for CountryCode rule alpha-3 and numeric
This commit is contained in:
Felipe Martins 2015-10-17 16:16:07 -03:00 committed by Henrique Moody
parent 31f1f1c25e
commit cbbf082c15
18 changed files with 180 additions and 0 deletions

View file

@ -0,0 +1,13 @@
--TEST--
countryCode()
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator;
use Respect\Validation\Rules\CountryCode;
var_dump(Validator::countryCode(CountryCode::ALPHA3)->validate('BRA'));
?>
--EXPECTF--
bool(true)

View file

@ -0,0 +1,13 @@
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
use Respect\Validation\Rules\CountryCode;
v::countryCode(CountryCode::ALPHA3)->assert('BRA');
v::countryCode(CountryCode::ALPHA3)->assert('DEU');
v::countryCode(CountryCode::ALPHA3)->check('BRA');
v::countryCode(CountryCode::ALPHA3)->check('DEU');
?>
--EXPECTF--

View file

@ -0,0 +1,16 @@
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
use Respect\Validation\Rules\CountryCode;
use Respect\Validation\Exceptions\CountryCodeException;
try {
v::countryCode(CountryCode::ALPHA3)->check('1');
} catch (CountryCodeException $exception) {
echo $exception->getMainMessage();
}
?>
--EXPECTF--
"1" must be a valid country

View file

@ -0,0 +1,16 @@
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
use Respect\Validation\Rules\CountryCode;
use Respect\Validation\Exceptions\AllOfException;
try {
v::countryCode(CountryCode::ALPHA3)->assert('1');
} catch (AllOfException $exception) {
echo $exception->getFullMessage();
}
?>
--EXPECTF--
\-"1" must be a valid country

View file

@ -0,0 +1,16 @@
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
use Respect\Validation\Rules\CountryCode;
use Respect\Validation\Exceptions\CountryCodeException;
try {
v::not(v::countryCode(CountryCode::ALPHA3))->check('BRA');
} catch (CountryCodeException $exception) {
echo $exception->getMainMessage();
}
?>
--EXPECTF--
"BRA" must not be a valid country

View file

@ -0,0 +1,16 @@
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
use Respect\Validation\Rules\CountryCode;
use Respect\Validation\Exceptions\AllOfException;
try {
v::not(v::countryCode(CountryCode::ALPHA3))->assert('BRA');
} catch (AllOfException $exception) {
echo $exception->getFullMessage();
}
?>
--EXPECTF--
\-"BRA" must not be a valid country

View file

@ -0,0 +1,13 @@
--TEST--
countryCode()
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator;
use Respect\Validation\Rules\CountryCode;
var_dump(Validator::countryCode(CountryCode::NUMERIC)->validate('076'));
?>
--EXPECTF--
bool(true)

View file

@ -0,0 +1,13 @@
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
use Respect\Validation\Rules\CountryCode;
v::countryCode(CountryCode::NUMERIC)->assert('076');
v::countryCode(CountryCode::NUMERIC)->assert('276');
v::countryCode(CountryCode::NUMERIC)->check('076');
v::countryCode(CountryCode::NUMERIC)->check('276');
?>
--EXPECTF--

View file

@ -0,0 +1,16 @@
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
use Respect\Validation\Rules\CountryCode;
use Respect\Validation\Exceptions\CountryCodeException;
try {
v::countryCode(CountryCode::NUMERIC)->check('BRA');
} catch (CountryCodeException $exception) {
echo $exception->getMainMessage();
}
?>
--EXPECTF--
"BRA" must be a valid country

View file

@ -0,0 +1,16 @@
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
use Respect\Validation\Rules\CountryCode;
use Respect\Validation\Exceptions\AllOfException;
try {
v::countryCode(CountryCode::NUMERIC)->assert('BRA');
} catch (AllOfException $exception) {
echo $exception->getFullMessage();
}
?>
--EXPECTF--
\-"BRA" must be a valid country

View file

@ -0,0 +1,16 @@
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
use Respect\Validation\Rules\CountryCode;
use Respect\Validation\Exceptions\CountryCodeException;
try {
v::not(v::countryCode(CountryCode::NUMERIC))->check('076');
} catch (CountryCodeException $exception) {
echo $exception->getMainMessage();
}
?>
--EXPECTF--
"076" must not be a valid country

View file

@ -0,0 +1,16 @@
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
use Respect\Validation\Rules\CountryCode;
use Respect\Validation\Exceptions\AllOfException;
try {
v::not(v::countryCode(CountryCode::NUMERIC))->assert('076');
} catch (AllOfException $exception) {
echo $exception->getFullMessage();
}
?>
--EXPECTF--
\-"076" must not be a valid country