Create integration tests for "KeyValue" rule

This commit is contained in:
Edson Lima 2015-10-17 17:52:55 -03:00 committed by Henrique Moody
parent 5dc5410617
commit 16ad8f804d
5 changed files with 93 additions and 0 deletions

View file

@ -0,0 +1,16 @@
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
$data = array(
'password' => 'shuberry',
'password_confirmation' => 'shuberry',
'valid_passwords' => array('shuberry', 'monty-python')
);
v::keyValue('password', 'equals', 'password_confirmation')->check($data);
v::keyValue('password', 'in', 'valid_passwords')->assert($data);
?>
--EXPECTF--

View file

@ -0,0 +1,20 @@
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
use Respect\Validation\Exceptions\EqualsException;
$data = array(
'password' => 'shuberry',
'password_confirmation' => '_shuberry_'
);
try {
v::keyValue('password', 'equals', 'password_confirmation')->check($data);
} catch (EqualsException $e) {
echo $e->getMainMessage();
}
?>
--EXPECTF--
password must be equals "password_confirmation"

View file

@ -0,0 +1,19 @@
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
use Respect\Validation\Exceptions\AllOfException;
$data = array(
'password' => 'shazam',
'password_confirmation' => 'batman'
);
try {
v::keyValue('password', 'equals', 'password_confirmation')->assert($data);
} catch (AllOfException $e) {
echo $e->getMainMessage();
}
--EXPECTF--
All of the required rules must pass for { "password": "shazam", "password_confirmation": "batman" }

View file

@ -0,0 +1,19 @@
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
use Respect\Validation\Exceptions\KeyValuException;
$data = array(
'password' => '123',
'invalid_passwords' => array('123', 'secreta')
);
try {
v::not(v::keyValue('password', 'in', 'invalid_passwords'))->check($data);
} catch (Exception $e) {
echo $e->getMainMessage();
}
--EXPECTF--
Key { "password": "123", "invalid_passwords": { "123", "secreta" } } must not be present

View file

@ -0,0 +1,19 @@
--FILE--
<?php
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
use Respect\Validation\Exceptions\AllOfException;
$data = array(
'password' => '123',
'invalid_passwords' => array('123', 'secreta')
);
try {
v::not(v::keyValue('password', 'in', 'invalid_passwords'))->assert($data);
} catch (AllOfException $e) {
echo $e->getFullMessage();
}
--EXPECTF--
\-Key { "password": "123", "invalid_passwords": { "123", "secreta" } } must not be present