respect-validation/tests/unit/Rules/VersionTest.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

72 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\Version
* @covers \Respect\Validation\Exceptions\VersionException
*/
class VersionTest extends TestCase
{
/**
* @dataProvider providerForValidVersion
*/
public function testValidVersionShouldReturnTrue($input): void
{
$rule = new Version();
self::assertTrue($rule->__invoke($input));
self::assertTrue($rule->assert($input));
$rule->check($input);
}
/**
* @dataProvider providerForInvalidVersion
* @expectedException \Respect\Validation\Exceptions\VersionException
*/
public function testInvalidVersionShouldThrowException($input): void
{
$rule = new Version();
self::assertFalse($rule->__invoke($input));
self::assertFalse($rule->assert($input));
}
public function providerForValidVersion()
{
return [
['1.0.0'],
['1.0.0-alpha'],
['1.0.0-alpha.1'],
['1.0.0-0.3.7'],
['1.0.0-x.7.z.92'],
['1.3.7+build.2.b8f12d7'],
['1.3.7-rc.1'],
];
}
public function providerForInvalidVersion()
{
return [
[''],
['1.3.7--'],
['1.3.7++'],
['foo'],
['1.2.3.4'],
['1.2.3.4-beta'],
['beta'],
];
}
}