respect-validation/tests/library/Respect/Validation/Rules/PerfectSquareTest.php
Kleber Hamada Sato 21aa5bf0a0 Insert validation, tests and exception for perfect square numbers.
About perfect square numbers:
Perfect square numbers are numbers which is a product of some integer
with itself. A square root of a perfect square numbers is always a integer
number.

Signed-off-by: Kleber Hamada Sato <kleberhs007@yahoo.com>
2012-03-20 13:24:55 -03:00

70 lines
1.5 KiB
PHP

<?php
namespace Respect\Validation\Rules;
class PerfectSquareTest extends \PHPUnit_Framework_TestCase
{
protected $object;
protected function setUp()
{
$this->object = new PerfectSquare;
}
/**
* @dataProvider providerForPerfectSquare
*
*/
public function testPerfectSquare($input)
{
$this->assertTrue($this->object->validate($input));
$this->assertTrue($this->object->check($input));
$this->assertTrue($this->object->assert($input));
}
/**
* @dataProvider providerForNotPerfectSquare
* @expectedException Respect\Validation\Exceptions\PerfectSquareException
*
*/
public function testNotPerfectSquare($input)
{
$this->assertFalse($this->object->validate($input));
$this->assertFalse($this->object->assert($input));
}
public function providerForPerfectSquare()
{
return array(
array(1),
array(9),
array(25),
array('25'),
array(400),
array('400'),
array('0'),
array(81),
array(0),
array(250),
);
}
public function providerForNotPerfectSquare()
{
return array(
array(null),
array(7),
array(-1),
array(6),
array(2),
array('-1'),
array('a'),
array(' '),
array('Foo'),
array(''),
);
}
}