respect-validation/tests/unit/Rules/AnyOfTest.php
Henrique Moody c80524b457
Method assert() should not have a return value
One this method should throw an exception when the input is not valid,
returning `TRUE` when it succeeds is not really consistent.
2018-01-28 17:38:40 +01:00

70 lines
1.7 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;
/**
* @group rule
* @covers \Respect\Validation\Rules\AnyOf
* @covers \Respect\Validation\Exceptions\AnyOfException
*/
class AnyOfTest extends TestCase
{
public function testValid(): void
{
$valid1 = new Callback(function () {
return false;
});
$valid2 = new Callback(function () {
return true;
});
$valid3 = new Callback(function () {
return false;
});
$o = new AnyOf($valid1, $valid2, $valid3);
self::assertTrue($o->validate('any'));
$o->assert('any');
$o->check('any');
}
/**
* @expectedException \Respect\Validation\Exceptions\AnyOfException
*/
public function testInvalid(): void
{
$valid1 = new Callback(function () {
return false;
});
$valid2 = new Callback(function () {
return false;
});
$valid3 = new Callback(function () {
return false;
});
$o = new AnyOf($valid1, $valid2, $valid3);
self::assertFalse($o->validate('any'));
$o->assert('any');
}
/**
* @expectedException \Respect\Validation\Exceptions\XdigitException
*/
public function testInvalidCheck(): void
{
$o = new AnyOf(new Xdigit(), new Alnum());
self::assertFalse($o->validate(-10));
$o->check(-10);
}
}