mirror of
https://github.com/Respect/Validation.git
synced 2026-03-18 08:09:51 +01:00
Because of how the validation engine works, there's no reason to keep adding templates to each rule. Instead, creating a single rule that handles templating rules will simplify the library greatly and shrink the `Rule` interface. Personally, I think this API is much more straightforward than the `setTemplate()` method, as it's way more explicit which rule is being templated.
48 lines
1.1 KiB
PHP
48 lines
1.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Rules\Core;
|
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
|
use PHPUnit\Framework\Attributes\Group;
|
|
use PHPUnit\Framework\Attributes\Test;
|
|
use Respect\Validation\Test\Rules\Core\ConcreteWrapper;
|
|
use Respect\Validation\Test\Rules\Stub;
|
|
use Respect\Validation\Test\TestCase;
|
|
|
|
#[Group('core')]
|
|
#[CoversClass(Wrapper::class)]
|
|
final class WrapperTest extends TestCase
|
|
{
|
|
#[Test]
|
|
public function shouldUseWrappedToEvaluate(): void
|
|
{
|
|
$wrapped = Stub::pass(2);
|
|
|
|
$wrapper = new ConcreteWrapper($wrapped);
|
|
|
|
$input = 'Whatever';
|
|
|
|
self::assertEquals($wrapped->evaluate($input), $wrapper->evaluate($input));
|
|
}
|
|
|
|
#[Test]
|
|
public function shouldPassNameOnToWrapped(): void
|
|
{
|
|
$name = 'Whatever';
|
|
|
|
$rule = Stub::pass(1);
|
|
|
|
$sut = new ConcreteWrapper($rule);
|
|
$sut->setName($name);
|
|
|
|
self::assertSame($name, $rule->getName());
|
|
self::assertSame($name, $sut->getName());
|
|
}
|
|
}
|