mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 23:35:45 +01:00
Whenever is possible it is better to declare our classes as final. The PHPUnit tests should not be extended, therefore there is no reason for them to not be final. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
79 lines
2.2 KiB
PHP
79 lines
2.2 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\Exceptions;
|
|
|
|
use DirectoryIterator;
|
|
use ReflectionClass;
|
|
use Respect\Validation\Test\TestCase;
|
|
|
|
/**
|
|
* @coversNothing
|
|
*
|
|
* @author Andy Wendt <andy@awendt.com>
|
|
* @author Augusto Pascutti <augusto@phpsp.org.br>
|
|
* @author Gabriel Caruso <carusogabriel34@gmail.com>
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
*/
|
|
final class CheckExceptionsTest extends TestCase
|
|
{
|
|
/**
|
|
* @return string[][]
|
|
*/
|
|
public function provideListOfRuleNames(): array
|
|
{
|
|
$rulesDirectory = 'library/Rules';
|
|
$rulesDirectoryIterator = new DirectoryIterator($rulesDirectory);
|
|
$ruleNames = [];
|
|
foreach ($rulesDirectoryIterator as $fileInfo) {
|
|
if ($fileInfo->isDir()) {
|
|
continue;
|
|
}
|
|
|
|
$ruleName = mb_substr($fileInfo->getBasename(), 0, -4);
|
|
if (($fileInfo->getExtension() !== 'php')) {
|
|
continue;
|
|
}
|
|
|
|
$className = 'Respect\\Validation\\Rules\\'.$ruleName;
|
|
$reflectionClass = new ReflectionClass($className);
|
|
if ($reflectionClass->isAbstract() || $reflectionClass->isInterface()) {
|
|
continue;
|
|
}
|
|
|
|
$ruleNames[] = [$ruleName];
|
|
}
|
|
|
|
return $ruleNames;
|
|
}
|
|
|
|
/**
|
|
* @dataProvider provideListOfRuleNames
|
|
*
|
|
* @test
|
|
*/
|
|
public function ruleHasAnExceptionWhichHasValidApi(string $ruleName): void
|
|
{
|
|
$exceptionClass = 'Respect\\Validation\\Exceptions\\'.$ruleName.'Exception';
|
|
self::assertTrue(
|
|
class_exists($exceptionClass),
|
|
sprintf('Expected exception class to exist: %s.', $ruleName)
|
|
);
|
|
|
|
$reflectionClass = new ReflectionClass($exceptionClass);
|
|
self::assertTrue(
|
|
$reflectionClass->isSubclassOf(ValidationException::class),
|
|
'Every Respect/Validation exception must extend ValidationException.'
|
|
);
|
|
}
|
|
}
|