respect-validation/tests/integration/assert-with-attributes.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

57 lines
1.6 KiB
PHP

--CREDITS--
Henrique Moody <henriquemoody@gmail.com>
Jonathan Stewmon <jstewmon@rmn.com>
--FILE--
<?php
declare(strict_types=1);
require 'vendor/autoload.php';
use Respect\Validation\Validator as v;
exceptionFullMessage(static function () {
$array = [
'mysql' => [
'host' => 42,
'user' => 'user',
'password' => 'password',
'schema' => 'schema',
],
'postgresql' => [
'host' => 'host',
'user' => 42,
'password' => 'password',
'schema' => 'schema',
],
];
$object = json_decode((string) json_encode($array));
v::create()
->attribute(
'mysql',
v::create()
->attribute('host', v::stringType(), true)
->attribute('user', v::stringType(), true)
->attribute('password', v::stringType(), true)
->attribute('schema', v::stringType(), true),
true
)
->attribute(
'postgresql',
v::create()
->attribute('host', v::stringType(), true)
->attribute('user', v::stringType(), true)
->attribute('password', v::stringType(), true)
->attribute('schema', v::stringType(), true),
true
)
->setName('the given data')
->assert($object);
});
?>
--EXPECT--
- All of the required rules must pass for the given data
- These rules must pass for mysql
- host must be of type string
- These rules must pass for postgresql
- user must be of type string