respect-validation/tests/unit/Rules/AbstractWrapperTest.php
Alexandre Gomes Gaigalas ab3732f91f Use SPDX IDs for licensing
SPDX IDs are shorter than licensing notes previously used, and
adhere better to FOSS standards. It is also machine-readable.
2023-02-19 00:19:10 -03:00

102 lines
2.4 KiB
PHP

<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
declare(strict_types=1);
namespace Respect\Validation\Rules;
use Respect\Validation\Test\TestCase;
use Respect\Validation\Validatable;
/**
* @test core
*
* @covers \Respect\Validation\Rules\AbstractWrapper
*
* @author Alasdair North <alasdair@runway.io>
* @author Gabriel Caruso <carusogabriel34@gmail.com>
* @author Henrique Moody <henriquemoody@gmail.com>
*/
final class AbstractWrapperTest extends TestCase
{
/**
* @test
*/
public function shouldUseWrappedToValidate(): void
{
$input = 'Whatever';
$validatable = $this->createMock(Validatable::class);
$validatable
->expects(self::once())
->method('validate')
->with($input)
->will(self::returnValue(true));
$wrapper = $this->getMockForAbstractClass(AbstractWrapper::class, [$validatable]);
self::assertTrue($wrapper->validate($input));
}
/**
* @test
*/
public function shouldUseWrappedToAssert(): void
{
$input = 'Whatever';
$validatable = $this->createMock(Validatable::class);
$validatable
->expects(self::once())
->method('assert')
->with($input)
->will(self::returnValue(true));
$wrapper = $this->getMockForAbstractClass(AbstractWrapper::class, [$validatable]);
$wrapper->assert($input);
}
/**
* @test
*/
public function shouldUseWrappedToCheck(): void
{
$input = 'Whatever';
$validatable = $this->createMock(Validatable::class);
$validatable
->expects(self::once())
->method('check')
->with($input)
->will(self::returnValue(true));
$wrapper = $this->getMockForAbstractClass(AbstractWrapper::class, [$validatable]);
$wrapper->check($input);
}
/**
* @test
*/
public function shouldPassNameOnToWrapped(): void
{
$name = 'Whatever';
$validatable = $this->createMock(Validatable::class);
$validatable
->expects(self::once())
->method('setName')
->with($name)
->will(self::returnValue($validatable));
$wrapper = $this->getMockForAbstractClass(AbstractWrapper::class, [$validatable]);
self::assertSame($wrapper, $wrapper->setName($name));
}
}