respect-validation/tests/unit/Rules/NumericValTest.php
2016-11-06 18:45:44 +01:00

70 lines
1.5 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\NumericVal
* @covers Respect\Validation\Exceptions\NumericValException
*/
class NumericValTest extends \PHPUnit_Framework_TestCase
{
protected $object;
protected function setUp()
{
$this->object = new NumericVal();
}
/**
* @dataProvider providerForNumeric
*/
public function testNumeric($input)
{
$this->assertTrue($this->object->__invoke($input));
$this->assertTrue($this->object->check($input));
$this->assertTrue($this->object->assert($input));
}
/**
* @dataProvider providerForNotNumeric
* @expectedException Respect\Validation\Exceptions\NumericValException
*/
public function testNotNumeric($input)
{
$this->assertFalse($this->object->__invoke($input));
$this->assertFalse($this->object->assert($input));
}
public function providerForNumeric()
{
return [
[165],
[165.0],
[-165],
['165'],
['165.0'],
['+165.0'],
];
}
public function providerForNotNumeric()
{
return [
[''],
[null],
['a'],
[' '],
['Foo'],
];
}
}