respect-validation/tests/unit/Rules/VowelTest.php
Henrique Moody c80524b457
Method assert() 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

108 lines
2.6 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\Vowel
* @covers \Respect\Validation\Exceptions\VowelException
*/
class VowelTest extends TestCase
{
/**
* @dataProvider providerForValidVowels
*/
public function testValidDataWithVowelsShouldReturnTrue($validVowels, $additional = ''): void
{
$validator = new Vowel($additional);
self::assertTrue($validator->validate($validVowels));
}
/**
* @dataProvider providerForInvalidVowels
* @expectedException \Respect\Validation\Exceptions\VowelException
*/
public function testInvalidVowelsShouldFailAndThrowVowelException($invalidVowels, $additional = ''): void
{
$validator = new Vowel($additional);
self::assertFalse($validator->validate($invalidVowels));
$validator->assert($invalidVowels);
}
/**
* @dataProvider providerForInvalidParams
* @expectedException \Respect\Validation\Exceptions\ComponentException
*/
public function testInvalidConstructorParamsShouldThrowComponentExceptionUponInstantiation($additional): void
{
$validator = new Vowel($additional);
}
/**
* @dataProvider providerAdditionalChars
*/
public function testAdditionalCharsShouldBeRespected($additional, $query): void
{
$validator = new Vowel($additional);
self::assertTrue($validator->validate($query));
}
public function providerAdditionalChars()
{
return [
['!@#$%^&*(){}', '!@#$%^&*(){} aeo iu'],
['[]?+=/\\-_|"\',<>.', "[]?+=/\\-_|\"',<>. \t \n aeo iu"],
];
}
public function providerForInvalidParams()
{
return [
[new \stdClass()],
[[]],
[0x2],
];
}
public function providerForValidVowels()
{
return [
['a'],
['e'],
['i'],
['o'],
['u'],
['aeiou'],
['aei ou'],
["\na\t"],
['uoiea'],
];
}
public function providerForInvalidVowels()
{
return [
[''],
[null],
['16'],
['F'],
['g'],
['Foo'],
[-50],
['basic'],
];
}
}