mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 23:59:51 +01:00
This abstract class is very similar to "AbstractWrapper" the difference is that "AbstractWapper" will throw the exceptions of the rule that is defined inside it, while "AbstractEnvelope" uses the exception of the rule that extends it. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
83 lines
2 KiB
PHP
83 lines
2 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Respect/Validation.
|
|
*
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
*
|
|
* For the full copyright and license information, please view the "LICENSE.md"
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Respect\Validation\Validatable;
|
|
|
|
/**
|
|
* @test core
|
|
*
|
|
* @covers \Respect\Validation\Rules\AbstractEnvelope
|
|
*
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
*/
|
|
final class AbstractEnvelopeTest extends TestCase
|
|
{
|
|
/**
|
|
* @test
|
|
*/
|
|
public function itShouldValidateUsingTheInnerRule(): void
|
|
{
|
|
$input = 'value';
|
|
|
|
$innerRule = $this->createMock(Validatable::class);
|
|
$innerRule
|
|
->expects($this->once())
|
|
->method('validate')
|
|
->with($input)
|
|
->willReturn(true);
|
|
|
|
$rule = $this->getMockForAbstractClass(AbstractEnvelope::class, [$innerRule, []]);
|
|
|
|
self::assertTrue($rule->validate($input));
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function itShouldInvalidateUsingTheInnerRule(): void
|
|
{
|
|
$input = 'value';
|
|
|
|
$innerRule = $this->createMock(Validatable::class);
|
|
$innerRule
|
|
->expects($this->once())
|
|
->method('validate')
|
|
->with($input)
|
|
->willReturn(false);
|
|
|
|
$rule = $this->getMockForAbstractClass(AbstractEnvelope::class, [$innerRule, []]);
|
|
|
|
self::assertFalse($rule->validate($input));
|
|
}
|
|
|
|
/**
|
|
* @test
|
|
*/
|
|
public function itShouldReportErrorUringProperties(): void
|
|
{
|
|
$input = 'value';
|
|
$parameters = ['foo' => true, 'bar' => false, 'baz' => 42];
|
|
|
|
$rule = $this->getMockForAbstractClass(
|
|
AbstractEnvelope::class,
|
|
[$this->createMock(Validatable::class), $parameters]
|
|
);
|
|
|
|
$exception = $rule->reportError($input);
|
|
|
|
self::assertArraySubset($parameters, $exception->getParams());
|
|
}
|
|
}
|