mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 15:50:03 +01:00
68 lines
1.7 KiB
PHP
68 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.
|
|
*/
|
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
/**
|
|
* @group rule
|
|
* @covers Respect\Validation\Rules\Version
|
|
* @covers Respect\Validation\Exceptions\VersionException
|
|
*/
|
|
class VersionTest extends \PHPUnit_Framework_TestCase
|
|
{
|
|
/**
|
|
* @dataProvider providerForValidVersion
|
|
*/
|
|
public function testValidVersionShouldReturnTrue($input)
|
|
{
|
|
$rule = new Version();
|
|
$this->assertTrue($rule->__invoke($input));
|
|
$this->assertTrue($rule->assert($input));
|
|
$this->assertTrue($rule->check($input));
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerForInvalidVersion
|
|
* @expectedException Respect\Validation\Exceptions\VersionException
|
|
*/
|
|
public function testInvalidVersionShouldThrowException($input)
|
|
{
|
|
$rule = new Version();
|
|
$this->assertFalse($rule->__invoke($input));
|
|
$this->assertFalse($rule->assert($input));
|
|
}
|
|
|
|
public function providerForValidVersion()
|
|
{
|
|
return array(
|
|
array(''),
|
|
array('1.0.0'),
|
|
array('1.0.0-alpha'),
|
|
array('1.0.0-alpha.1'),
|
|
array('1.0.0-0.3.7'),
|
|
array('1.0.0-x.7.z.92'),
|
|
array('1.3.7+build.2.b8f12d7'),
|
|
array('1.3.7-rc.1'),
|
|
);
|
|
}
|
|
|
|
public function providerForInvalidVersion()
|
|
{
|
|
return array(
|
|
array('1.3.7--'),
|
|
array('1.3.7++'),
|
|
array('foo'),
|
|
array('1.2.3.4'),
|
|
array('1.2.3.4-beta'),
|
|
array('beta'),
|
|
);
|
|
}
|
|
}
|