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:

  1. Declarative (preferred): Override getCheckDescriptors() to return an array mapping check names to [checkClass, fromVersion, toVersion, messageTemplate]. The base entityProvider() and testEntity() handle everything automatically.

  2. 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

void
setUp()

No description

static array
getCheckDescriptors()

Return check descriptors for declarative test registration.

static iterable
entityProvider()

Generic data provider that yields [checkName, entityId, phpVersion] for each entity.

void
testEntity(string $methodName, string $entityId, string $phpVersion)

No description

static iterable
getEntitiesForMethod(string $methodName, StubDataQueryInterface $reflection)

Get entities to test based on the method name.

static string
getEntityId(mixed $entity)

Get the unique identifier for an entity.

static string
buildTestName(string $methodName, string $entityId, string $phpVersion)

Build a unique test name from method, entity, and version.

void
executeCheck(CheckInterface $check, string $entityId, string $phpVersion, string|null $customMessage = null)

Execute a validation check and assert results.

Details

protected void setUp()

No description

Return Value

void

static protected array getCheckDescriptors()

Return check descriptors for declarative test registration.

Each entry maps a logical check name to a CheckDescriptor.

Return Value

array

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.

Return Value

iterable

void testEntity(string $methodName, string $entityId, string $phpVersion)

No description

Parameters

string $methodName
string $entityId
string $phpVersion

Return Value

void

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.

Parameters

string $methodName
StubDataQueryInterface $reflection

Return Value

iterable

static protected string getEntityId(mixed $entity)

Get the unique identifier for an entity.

Parameters

mixed $entity

Return Value

string

static protected string buildTestName(string $methodName, string $entityId, string $phpVersion)

Build a unique test name from method, entity, and version.

Parameters

string $methodName
string $entityId
string $phpVersion

Return Value

string

protected void executeCheck(CheckInterface $check, string $entityId, string $phpVersion, string|null $customMessage = null)

Execute a validation check and assert results.

Parameters

CheckInterface $check

The validation check to run

string $entityId

The entity identifier

string $phpVersion

The PHP version

string|null $customMessage

Optional custom assertion message

Return Value

void