respect-validation/tests/integration/rules/optional.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

29 lines
1.1 KiB
PHP

--CREDITS--
Henrique Moody <henriquemoody@gmail.com>
--FILE--
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
exceptionMessage(static fn() => v::optional(v::alpha())->check(1234));
exceptionMessage(static fn() => v::optional(v::alpha())->setName('Name')->check(1234));
exceptionMessage(static fn() => v::not(v::optional(v::alpha()))->check('abcd'));
exceptionMessage(static fn() => v::not(v::optional(v::alpha()))->setName('Name')->check('abcd'));
exceptionFullMessage(static fn() => v::optional(v::alpha())->assert(1234));
exceptionFullMessage(static fn() => v::optional(v::alpha())->setName('Name')->assert(1234));
exceptionFullMessage(static fn() => v::not(v::optional(v::alpha()))->assert('abcd'));
exceptionFullMessage(static fn() => v::not(v::optional(v::alpha()))->setName('Name')->assert('abcd'));
?>
--EXPECT--
1234 must contain only letters (a-z)
Name must contain only letters (a-z)
The value must not be optional
Name must not be optional
- 1234 must contain only letters (a-z)
- Name must contain only letters (a-z)
- The value must not be optional
- Name must not be optional