respect-validation/tests/integration/rules/iban.phpt
Henrique Moody ed304f3406
Check "bcmath" extension before executing tests
Although BCMath is necessary to execute "Ip" and "Iban" rules, we not
required that in the "composer.json" file. That's because if someone
wants to use the library, but doesn't want to use those rules, they
would not need to install that extension.

However, when executing the tests, they will break. This commit will
verify whether the extension exists to test "Ip" and "Iban" rules.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2020-10-04 11:21:36 +02:00

49 lines
1.2 KiB
PHP

--CREDITS--
Mazen Touati <mazen_touati@hotmail.com>
--FILE--
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Respect\Validation\Exceptions\IbanException;
use Respect\Validation\Exceptions\NestedValidationException;
use Respect\Validation\Validator as v;
try {
v::iban()->check('SE35 5000 5880 7742');
} catch (IbanException $exception) {
echo $exception->getMessage() . PHP_EOL;
}
try {
v::not(v::iban())->check('GB82 WEST 1234 5698 7654 32');
} catch (IbanException $exception) {
echo $exception->getMessage() . PHP_EOL;
}
try {
v::iban()->assert('NOT AN IBAN');
} catch (NestedValidationException $exception) {
echo $exception->getFullMessage() . PHP_EOL;
}
try {
v::not(v::iban())->assert('HU93 1160 0006 0000 0000 1234 5676');
} catch (NestedValidationException $exception) {
echo $exception->getFullMessage() . PHP_EOL;
}
?>
--SKIPIF--
<?php
if (!extension_loaded('bcmath')) {
echo 'skip: Extension "bcmath" is required to execute this test';
}
?>
--EXPECT--
"SE35 5000 5880 7742" must be a valid IBAN
"GB82 WEST 1234 5698 7654 32" must not be a valid IBAN
- "NOT AN IBAN" must be a valid IBAN
- "HU93 1160 0006 0000 0000 1234 5676" must not be a valid IBAN