2015-01-02 20:21:08 +01:00
|
|
|
<?php
|
|
|
|
|
2015-06-08 17:09:25 +02:00
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2015-06-08 17:09:25 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-01-02 20:21:08 +01:00
|
|
|
namespace Respect\Validation\Exceptions;
|
|
|
|
|
|
|
|
use DirectoryIterator;
|
2015-10-18 03:44:47 +02:00
|
|
|
use ReflectionClass;
|
2018-12-05 08:36:38 +01:00
|
|
|
use Respect\Validation\Test\TestCase;
|
2020-07-21 22:54:41 +02:00
|
|
|
|
2019-02-17 19:41:55 +01:00
|
|
|
use function class_exists;
|
|
|
|
use function mb_substr;
|
|
|
|
use function sprintf;
|
2015-01-02 20:21:08 +01:00
|
|
|
|
2018-07-23 21:37:38 +02:00
|
|
|
/**
|
|
|
|
* @coversNothing
|
2018-11-25 17:56:04 +01:00
|
|
|
*
|
|
|
|
* @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>
|
2018-07-23 21:37:38 +02:00
|
|
|
*/
|
2019-02-09 14:31:56 +01:00
|
|
|
final class CheckExceptionsTest extends TestCase
|
2015-01-02 20:21:08 +01:00
|
|
|
{
|
2023-04-02 16:00:37 +02:00
|
|
|
/**
|
|
|
|
* @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.'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-07 21:22:10 +01:00
|
|
|
/**
|
|
|
|
* @return string[][]
|
|
|
|
*/
|
2023-04-02 16:00:37 +02:00
|
|
|
public static function provideListOfRuleNames(): array
|
2015-01-02 20:21:08 +01:00
|
|
|
{
|
2015-08-11 18:32:15 +02:00
|
|
|
$rulesDirectory = 'library/Rules';
|
2015-01-02 20:21:08 +01:00
|
|
|
$rulesDirectoryIterator = new DirectoryIterator($rulesDirectory);
|
2015-10-18 03:44:47 +02:00
|
|
|
$ruleNames = [];
|
2015-01-02 20:21:08 +01:00
|
|
|
foreach ($rulesDirectoryIterator as $fileInfo) {
|
|
|
|
if ($fileInfo->isDir()) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-07-12 23:01:13 +02:00
|
|
|
|
2016-10-30 10:44:52 +01:00
|
|
|
$ruleName = mb_substr($fileInfo->getBasename(), 0, -4);
|
2019-02-09 13:28:08 +01:00
|
|
|
if (($fileInfo->getExtension() !== 'php')) {
|
2015-01-02 20:21:08 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-07-21 22:54:41 +02:00
|
|
|
$className = 'Respect\\Validation\\Rules\\' . $ruleName;
|
2020-07-22 14:02:39 +02:00
|
|
|
if (!class_exists($className)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-01-02 20:21:08 +01:00
|
|
|
$reflectionClass = new ReflectionClass($className);
|
2015-07-12 23:01:13 +02:00
|
|
|
if ($reflectionClass->isAbstract() || $reflectionClass->isInterface()) {
|
2015-01-02 20:21:08 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-10-18 03:44:47 +02:00
|
|
|
$ruleNames[] = [$ruleName];
|
2015-01-02 20:21:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $ruleNames;
|
|
|
|
}
|
|
|
|
}
|