mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 23:35:45 +01:00
This commit addresses the skipped tests by modifying certain core concepts in the library. The way names work has always been somewhat confusing, even to me. I’ve established that existing names will never be overwritten, and if a path is already defined, we will change the name to also include the path. I’m not very happy with how I’m solving this problem, because the `FirstResultStringFormatter` is changing some behaviour in the results that seems to be something that should always happen before. But, for the moment, I will keep it as is.
119 lines
5.9 KiB
PHP
119 lines
5.9 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
test('Missing property', catchAll(
|
|
fn() => v::property('foo', v::intType())->assert(new stdClass()),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` must be present')
|
|
->and($fullMessage)->toBe('- `.foo` must be present')
|
|
->and($messages)->toBe(['foo' => '`.foo` must be present']),
|
|
));
|
|
|
|
test('Default', catchAll(
|
|
fn() => v::property('foo', v::intType())->assert((object) ['foo' => 'string']),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` must be an integer')
|
|
->and($fullMessage)->toBe('- `.foo` must be an integer')
|
|
->and($messages)->toBe(['foo' => '`.foo` must be an integer']),
|
|
));
|
|
|
|
test('Inverted', catchAll(
|
|
fn() => v::not(v::property('foo', v::intType()))->assert((object) ['foo' => 12]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` must not be an integer')
|
|
->and($fullMessage)->toBe('- `.foo` must not be an integer')
|
|
->and($messages)->toBe(['foo' => '`.foo` must not be an integer']),
|
|
));
|
|
|
|
test('Double-inverted with missing property', catchAll(
|
|
fn() => v::not(v::not(v::property('foo', v::intType())))->assert(new stdClass()),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` must be present')
|
|
->and($fullMessage)->toBe('- `.foo` must be present')
|
|
->and($messages)->toBe(['foo' => '`.foo` must be present']),
|
|
));
|
|
|
|
test('With wrapped name, missing property', catchAll(
|
|
fn() => v::property('foo', v::intType()->setName('Wrapped'))->assert(new stdClass()),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('Wrapped must be present')
|
|
->and($fullMessage)->toBe('- Wrapped must be present')
|
|
->and($messages)->toBe(['foo' => 'Wrapped must be present']),
|
|
));
|
|
|
|
test('With wrapped name, default', catchAll(
|
|
fn() => v::property('foo', v::intType()->setName('Wrapped'))->setName('Wrapper')->assert((object) ['foo' => 'string']),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('Wrapped must be an integer')
|
|
->and($fullMessage)->toBe('- Wrapped must be an integer')
|
|
->and($messages)->toBe(['foo' => 'Wrapped must be an integer']),
|
|
));
|
|
|
|
test('With wrapped name, inverted', catchAll(
|
|
fn() => v::not(
|
|
v::property('foo', v::intType()->setName('Wrapped'))->setName('Wrapper'),
|
|
)
|
|
->setName('Not')
|
|
->assert((object) ['foo' => 12]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('Wrapped must not be an integer')
|
|
->and($fullMessage)->toBe('- Wrapped must not be an integer')
|
|
->and($messages)->toBe(['foo' => 'Wrapped must not be an integer']),
|
|
));
|
|
|
|
test('With wrapper name, default', catchAll(
|
|
fn() => v::property('foo', v::intType())->setName('Wrapper')->assert((object) ['foo' => 'string']),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` (<- Wrapper) must be an integer')
|
|
->and($fullMessage)->toBe('- `.foo` (<- Wrapper) must be an integer')
|
|
->and($messages)->toBe(['foo' => '`.foo` (<- Wrapper) must be an integer']),
|
|
));
|
|
|
|
test('With wrapper name, missing property', catchAll(
|
|
fn() => v::property('foo', v::intType())->setName('Wrapper')->assert(new stdClass()),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` (<- Wrapper) must be present')
|
|
->and($fullMessage)->toBe('- `.foo` (<- Wrapper) must be present')
|
|
->and($messages)->toBe(['foo' => '`.foo` (<- Wrapper) must be present']),
|
|
));
|
|
|
|
test('With wrapper name, inverted', catchAll(
|
|
fn() => v::not(v::property('foo', v::intType())->setName('Wrapper'))->setName('Not')
|
|
->assert((object) ['foo' => 12]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` (<- Wrapper) must not be an integer')
|
|
->and($fullMessage)->toBe('- `.foo` (<- Wrapper) must not be an integer')
|
|
->and($messages)->toBe(['foo' => '`.foo` (<- Wrapper) must not be an integer']),
|
|
));
|
|
|
|
test('With "Not" name, inverted', catchAll(
|
|
fn() => v::not(v::property('foo', v::intType()))->setName('Not')->assert((object) ['foo' => 12]),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('`.foo` (<- Not) must not be an integer')
|
|
->and($fullMessage)->toBe('- `.foo` (<- Not) must not be an integer')
|
|
->and($messages)->toBe(['foo' => '`.foo` (<- Not) must not be an integer']),
|
|
));
|
|
|
|
test('With template, default', catchAll(
|
|
fn() => v::property('foo', v::intType())
|
|
->assert((object) ['foo' => 'string'], 'Particularly precautions perplexing property'),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('Particularly precautions perplexing property')
|
|
->and($fullMessage)->toBe('- Particularly precautions perplexing property')
|
|
->and($messages)->toBe(['foo' => 'Particularly precautions perplexing property']),
|
|
));
|
|
|
|
test('With template, inverted', catchAll(
|
|
fn() => v::not(v::property('foo', v::intType()))
|
|
->assert((object) ['foo' => 12], 'Not a prompt prospect of a particularly primitive property'),
|
|
fn(string $message, string $fullMessage, array $messages) => expect()
|
|
->and($message)->toBe('Not a prompt prospect of a particularly primitive property')
|
|
->and($fullMessage)->toBe('- Not a prompt prospect of a particularly primitive property')
|
|
->and($messages)->toBe(['foo' => 'Not a prompt prospect of a particularly primitive property']),
|
|
));
|