ValidatorTestBase
abstract class ValidatorTestBase extends TestCase (View source)
Abstract base class for validator tests.
Provides common functionality for:
- Building data providers from PHP version ranges
- Loading reflection and stub data
- Running validation checks
- Asserting results
Subclasses can register checks in one of two ways:
-
Declarative (preferred): Override getCheckDescriptors() to return an array mapping check names to [checkClass, fromVersion, toVersion, messageTemplate]. The base entityProvider() and testEntity() handle everything automatically.
-
Attribute-based (legacy): Define individual methods annotated with
[PhpVersionRange] that call executeCheck(). Used when custom entityProvider
or non-standard dispatch logic is needed (e.g. PhpDocValidatorTest).
Methods
No description
Return check descriptors for declarative test registration.
Generic data provider that yields [checkName, entityId, phpVersion] for each entity.
No description
Get entities to test based on the method name.
Get the unique identifier for an entity.
Build a unique test name from method, entity, and version.
Execute a validation check and assert results.
Details
protected void
setUp()
No description
static protected array
getCheckDescriptors()
Return check descriptors for declarative test registration.
Each entry maps a logical check name to a CheckDescriptor.
static iterable
entityProvider()
Generic data provider that yields [checkName, entityId, phpVersion] for each entity.
When getCheckDescriptors() returns entries, iterates those descriptors. Otherwise falls back to scanning methods for PhpVersionRange attributes.
void
testEntity(string $methodName, string $entityId, string $phpVersion)
No description
static protected iterable
getEntitiesForMethod(string $methodName, StubDataQueryInterface $reflection)
Get entities to test based on the method name.
Subclasses should override to return specific entity types.
static protected string
getEntityId(mixed $entity)
Get the unique identifier for an entity.
static protected string
buildTestName(string $methodName, string $entityId, string $phpVersion)
Build a unique test name from method, entity, and version.
protected void
executeCheck(CheckInterface $check, string $entityId, string $phpVersion, string|null $customMessage = null)
Execute a validation check and assert results.