respect-validation/tests/unit/Rules/BaseTest.php

118 lines
2.8 KiB
PHP
Raw Normal View History

<?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);
2015-06-08 16:47:14 +02:00
namespace Respect\Validation\Rules;
2017-11-04 11:21:40 +01:00
use PHPUnit\Framework\TestCase;
/**
* @group rule
2017-02-04 14:01:14 +01:00
* @covers \Respect\Validation\Rules\Base
* @covers \Respect\Validation\Exceptions\BaseException
*/
2017-11-04 11:21:40 +01:00
class BaseTest extends TestCase
{
protected $object;
/**
* @dataProvider providerForBase
*/
public function testBase($base, $input): void
{
$object = new Base($base);
self::assertTrue($object->__invoke($input));
self::assertTrue($object->check($input));
self::assertTrue($object->assert($input));
}
/**
* @dataProvider providerForInvalidBase
*/
public function testInvalidBase($base, $input): void
{
$object = new Base($base);
self::assertFalse($object->__invoke($input));
}
/**
* @dataProvider providerForExceptionBase
2017-02-04 14:01:14 +01:00
* @expectedException \Respect\Validation\Exceptions\BaseException
*/
public function testExceptionBase($base, $input): void
{
$object = new Base($base);
self::assertTrue($object->__invoke($input));
self::assertTrue($object->assert($input));
}
/**
* @dataProvider providerForCustomBase
*/
public function testCustomBase($base, $custom, $input): void
{
$object = new Base($base, $custom);
self::assertTrue($object->__invoke($input));
self::assertTrue($object->check($input));
self::assertTrue($object->assert($input));
}
public function providerForBase()
{
2015-10-18 03:44:47 +02:00
return [
[2, '011010001'],
[3, '0120122001'],
[8, '01234567520'],
[16, '012a34f5675c20d'],
[20, '012ah34f5675hic20dj'],
[50, '012ah34f56A75FGhic20dj'],
[62, 'Z01xSsg5675hic20dj'],
];
}
public function providerForInvalidBase()
{
2015-10-18 03:44:47 +02:00
return [
[2, ''],
[3, ''],
[8, ''],
[16, ''],
[20, ''],
[50, ''],
[62, ''],
[2, '01210103001'],
[3, '0120125f2001'],
[8, '01234dfZ567520'],
[16, '012aXS34f5675c20d'],
[20, '012ahZX34f5675hic20dj'],
[50, '012ahGZ34f56A75FGhic20dj'],
[61, 'Z01xSsg5675hic20dj'],
];
}
public function providerForCustomBase()
{
2015-10-18 03:44:47 +02:00
return [
[2, 'xy', 'xyyxyxxy'],
[3, 'pfg', 'gfpffp'],
];
}
public function providerForExceptionBase()
{
2015-10-18 03:44:47 +02:00
return [
[63, '01210103001'],
[125, '0120125f2001'],
];
}
}