respect-validation/tests/integration/rules/length.phpt
Henrique Moody 8a7bc1ab7a
Improve readability of integration tests
The integration tests use the same pattern to test exception messages.
With my changes, we won't validate which exception we throw in those
tests, but matching the message is enough. I created three functions to
replace most of those tests.

Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
2023-04-01 07:40:42 +02:00

54 lines
3 KiB
PHP

--CREDITS--
Danilo Correa <danilosilva87@gmail.com>
Mazen Touati <mazen_touati@hotmail.com>
--FILE--
<?php
declare(strict_types=1);
require_once 'vendor/autoload.php';
use Respect\Validation\Validator as v;
exceptionMessage(static fn() => v::length(0, 5, false)->check('phpsp.org.br'));
exceptionMessage(static fn() => v::length(0, 10)->check('phpsp.org.br'));
exceptionMessage(static fn() => v::length(15, null, false)->check('phpsp.org.br'));
exceptionMessage(static fn() => v::length(20)->check('phpsp.org.br'));
exceptionMessage(static fn() => v::length(5, 10)->check('phpsp.org.br'));
exceptionMessage(static fn() => v::not(v::length(0, 15))->check('phpsp.org.br'));
exceptionMessage(static fn() => v::not(v::length(0, 20, false))->check('phpsp.org.br'));
exceptionMessage(static fn() => v::not(v::length(10, null))->check('phpsp.org.br'));
exceptionMessage(static fn() => v::not(v::length(5, null, false))->check('phpsp.org.br'));
exceptionMessage(static fn() => v::not(v::length(5, 20))->check('phpsp.org.br'));
exceptionFullMessage(static fn() => v::length(0, 5, false)->assert('phpsp.org.br'));
exceptionFullMessage(static fn() => v::length(0, 10)->assert('phpsp.org.br'));
exceptionFullMessage(static fn() => v::length(15, null, false)->assert('phpsp.org.br'));
exceptionFullMessage(static fn() => v::length(20)->assert('phpsp.org.br'));
exceptionFullMessage(static fn() => v::length(5, 10)->assert('phpsp.org.br'));
exceptionFullMessage(static fn() => v::not(v::length(0, 15))->assert('phpsp.org.br'));
exceptionFullMessage(static fn() => v::not(v::length(0, 20, false))->assert('phpsp.org.br'));
exceptionFullMessage(static fn() => v::not(v::length(10, null))->assert('phpsp.org.br'));
exceptionFullMessage(static fn() => v::not(v::length(5, null, false))->assert('phpsp.org.br'));
exceptionFullMessage(static fn() => v::not(v::length(5, 20))->assert('phpsp.org.br'));
?>
--EXPECT--
"phpsp.org.br" must have a length lower than 5
"phpsp.org.br" must have a length lower than or equal to 10
"phpsp.org.br" must have a length greater than 15
"phpsp.org.br" must have a length greater than or equal to 20
"phpsp.org.br" must have a length between 5 and 10
"phpsp.org.br" must not have a length lower than or equal to 15
"phpsp.org.br" must not have a length lower than 20
"phpsp.org.br" must not have a length greater than or equal to 10
"phpsp.org.br" must not have a length greater than 5
"phpsp.org.br" must not have a length between 5 and 20
- "phpsp.org.br" must have a length lower than 5
- "phpsp.org.br" must have a length lower than or equal to 10
- "phpsp.org.br" must have a length greater than 15
- "phpsp.org.br" must have a length greater than or equal to 20
- "phpsp.org.br" must have a length between 5 and 10
- "phpsp.org.br" must not have a length lower than or equal to 15
- "phpsp.org.br" must not have a length lower than 20
- "phpsp.org.br" must not have a length greater than or equal to 10
- "phpsp.org.br" must not have a length greater than 5
- "phpsp.org.br" must not have a length between 5 and 20