respect-validation/tests/unit/Rules/RomanTest.php
Henrique Moody 30dc089565
Method check() 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

83 lines
1.9 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\Roman
* @covers \Respect\Validation\Exceptions\RomanException
*/
class RomanTest extends TestCase
{
protected $romanValidator;
protected function setUp(): void
{
$this->romanValidator = new Roman();
}
/**
* @dataProvider providerForRoman
*/
public function testValidRomansShouldReturnTrue($input): void
{
self::assertTrue($this->romanValidator->__invoke($input));
self::assertTrue($this->romanValidator->assert($input));
$this->romanValidator->check($input);
}
/**
* @dataProvider providerForNotRoman
* @expectedException \Respect\Validation\Exceptions\RomanException
*/
public function testInvalidRomansShouldThrowRomanException($input): void
{
self::assertFalse($this->romanValidator->__invoke($input));
self::assertFalse($this->romanValidator->assert($input));
}
public function providerForRoman()
{
return [
[''],
['III'],
['IV'],
['VI'],
['XIX'],
['XLII'],
['LXII'],
['CXLIX'],
['CLIII'],
['MCCXXXIV'],
['MMXXIV'],
['MCMLXXV'],
['MMMMCMXCIX'],
];
}
public function providerForNotRoman()
{
return [
[' '],
['IIII'],
['IVVVX'],
['CCDC'],
['MXM'],
['XIIIIIIII'],
['MIMIMI'],
];
}
}