mirror of
https://github.com/Respect/Validation.git
synced 2026-03-16 15:25:45 +01:00
This commit will make sure that every class, interface, or trait will have the "@author" annotation in it. In order to create a list of authors, I used the "git blame" command, which means that if someone changed or even created the file but does not have any remaining line will not be shown in the list; it's a trade-off worth but it is worth it. The other way to do it would be carefully checking each file. Signed-off-by: Henrique Moody <henriquemoody@gmail.com>
80 lines
2.3 KiB
PHP
80 lines
2.3 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 PHPUnit\Framework\TestCase;
|
|
use ReflectionClass;
|
|
|
|
/**
|
|
* @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>
|
|
*/
|
|
class CheckExceptionsTest extends TestCase
|
|
{
|
|
protected $deprecateds = [];
|
|
|
|
public function provideListOfRuleNames()
|
|
{
|
|
$rulesDirectory = 'library/Rules';
|
|
$rulesDirectoryIterator = new DirectoryIterator($rulesDirectory);
|
|
$ruleNames = [];
|
|
foreach ($rulesDirectoryIterator as $fileInfo) {
|
|
if ($fileInfo->isDir()) {
|
|
continue;
|
|
}
|
|
|
|
$ruleName = mb_substr($fileInfo->getBasename(), 0, -4);
|
|
$ruleIsDeprecated = in_array($ruleName, $this->deprecateds);
|
|
$isRuleClassFile = (bool) ('php' !== $fileInfo->getExtension());
|
|
if ($ruleIsDeprecated || $isRuleClassFile) {
|
|
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($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.'
|
|
);
|
|
}
|
|
}
|