class ClassAttributeTargetsCheckTest extends CheckTestCase (View source)

Constants

private TARGET_METHOD

private TARGET_PROPERTY

private TARGET_CLASS_CONSTANT

Methods

createMockStorageManager()

Create a stubbed StubDataQueryInterface.

createStorageManagerMock()

Create a StubDataQueryInterface mock, for tests that constrain arguments with with() or assert call counts with expects().

createMockFunction(string $name, array $parameters = [], $returnType = null)

Create a mock PHPFunction with the given id/name.

createMockClass(string $name, array $methods = [])

Create a mock PHPClass with the given id/name.

createMockClassWithProperties(string $name, string|null $namespace = null, bool|null $isFinal = null, bool|null $isReadonly = null, array $methods = [], PHPClass|null $parentClass = null, array $interfaces = [], array $properties = [])

Create a mock PHPClass with properties (isFinal, isReadonly, namespace, parentClass).

createMockProperty(string $name, string|null $sinceVersion = null, string|null $removedVersion = null)

Create a mock PHPProperty with the given name and optional version bounds.

createMockMethod(string $name, array $parameters = [], $returnType = null)

Create a mock PHPMethod with the given name.

createMockParameter(string $name, mixed|null $type = null, string|null $sinceVersion = null, string|null $removedVersion = null, bool $isDeprecated = false, string|null $deprecatedSinceVersion = null)

Create a mock PHPParameter with the given name and type.

createType(string $typeName)

Create a StandaloneType with the given type name.

object
createMockType(string $typeString)

Create a mock type that returns a string representation.

__construct(string $typeName)

No description

string
__toString()

No description

string
getTypeName()

No description

void
testSupportsPhp80AndAbove()

No description

void
void
testMatchingTargetsPasses()

No description

void
testNonAttributeClassPasses()

No description

void
void
testMissingTargetFails()

No description

void
testUnexpectedTargetFails()

No description

void
void
void
void
testClassNotFoundInStubs()

No description

void
testSingleSymbolicFlagIsResolvedNotCastToZero()

The stub parser falls back to a symbolic name when the constant is not defined on the runtime that parsed the stubs. Casting that with (int) yields 0, so a stub declaring exactly the right target was reported as declaring none.

void
testMixedSymbolicBitwiseOrIsResolvedNotTruncated()

The worst case: "1|Attribute::TARGET_CONSTANT" casts to 1, which is a valid-looking bitmask, so the check reported a confident, wrong "missing target(s)" result.

void
void
testSymbolicResolutionStillDetectsARealMismatch()

A genuine mismatch must still be reported — the resolution must not mask real defects.

void
testUnresolvableFlagsFailWithTheRawValue()

An unresolvable value must fail loudly with the raw text rather than being cast to a plausible-looking number and compared.

void
testBareAttributeUsesTheVersionsTargetAllOn85AndLater()

#[Attribute] with no flags means TARGET_ALL, which widened from 63 to 127 in PHP 8.5 when TARGET_CONSTANT was added. The old code hardcoded 63 as its fallback.

void
testBareAttributeIsVersionSensitive()

The same bare stub declaration must not satisfy both 63 and 127 — otherwise the version map is being ignored.

Details

protected StubDataQueryInterface&Stub createMockStorageManager()

Create a stubbed StubDataQueryInterface.

A stub rather than a mock: these doubles only supply return values and never verify interactions, so createMock() made PHPUnit emit "No expectations were configured for the mock object" for every one of them — 1777 notices from this helper alone.

The return type names the double explicitly (&Stub) instead of just the interface, so ->method(...) resolves for static analysis; previously every such call across ~90 test files was reported as an undefined method, burying real warnings.

Return Value

StubDataQueryInterface&Stub

protected StubDataQueryInterface&MockObject createStorageManagerMock()

Create a StubDataQueryInterface mock, for tests that constrain arguments with with() or assert call counts with expects().

Those only work on a mock: on a stub, with() is silently ignored (PHPUnit deprecates it and will remove it in 13), so a test using the stub helper would appear to pin the argument while actually accepting anything.

Return Value

StubDataQueryInterface&MockObject

protected PHPFunction createMockFunction(string $name, array $parameters = [], $returnType = null)

Create a mock PHPFunction with the given id/name.

Parameters

string $name
array $parameters
$returnType

Return Value

PHPFunction

protected PHPClass createMockClass(string $name, array $methods = [])

Create a mock PHPClass with the given id/name.

Parameters

string $name
array $methods

Return Value

PHPClass

protected PHPClass createMockClassWithProperties(string $name, string|null $namespace = null, bool|null $isFinal = null, bool|null $isReadonly = null, array $methods = [], PHPClass|null $parentClass = null, array $interfaces = [], array $properties = [])

Create a mock PHPClass with properties (isFinal, isReadonly, namespace, parentClass).

Parameters

string $name

Class name/ID

string|null $namespace

Class namespace

bool|null $isFinal

Whether class is final

bool|null $isReadonly

Whether class is readonly

array $methods

Array of methods

PHPClass|null $parentClass

Parent class object

array $interfaces
array $properties

Return Value

PHPClass

protected PHPProperty createMockProperty(string $name, string|null $sinceVersion = null, string|null $removedVersion = null)

Create a mock PHPProperty with the given name and optional version bounds.

Parameters

string $name
string|null $sinceVersion
string|null $removedVersion

Return Value

PHPProperty

protected PHPMethod createMockMethod(string $name, array $parameters = [], $returnType = null)

Create a mock PHPMethod with the given name.

Parameters

string $name
array $parameters
$returnType

Return Value

PHPMethod

protected PHPParameter createMockParameter(string $name, mixed|null $type = null, string|null $sinceVersion = null, string|null $removedVersion = null, bool $isDeprecated = false, string|null $deprecatedSinceVersion = null)

Create a mock PHPParameter with the given name and type.

Note: Supports both getDeclaredType() and getType() methods to be compatible with different validators (ParameterNamesCheck uses getName, ParameterTypesCheck uses getType).

Parameters

string $name

Parameter name

mixed|null $type

Parameter type (optional)

string|null $sinceVersion

Version when parameter was introduced (optional)

string|null $removedVersion

Version when parameter was removed (optional)

bool $isDeprecated

Whether the parameter is marked deprecated

string|null $deprecatedSinceVersion

PHP version the deprecation starts at; null means "deprecated in every version"

Return Value

PHPParameter

protected StandaloneType createType(string $typeName)

Create a StandaloneType with the given type name.

Parameters

string $typeName

Return Value

StandaloneType

protected object createMockType(string $typeString)

Create a mock type that returns a string representation.

Parameters

string $typeString

Return Value

object

__construct(string $typeName)

No description

Parameters

string $typeName

string __toString()

No description

Return Value

string

string getTypeName()

No description

Return Value

string

void testSupportsPhp80AndAbove()

No description

Return Value

void

void testDoesNotSupportOlderPhpVersions()

No description

Return Value

void

void testMatchingTargetsPasses()

No description

Return Value

void

void testNonAttributeClassPasses()

No description

Return Value

void

void testOtherAttributesAreIgnored()

No description

Return Value

void

void testMissingTargetFails()

No description

Return Value

void

void testUnexpectedTargetFails()

No description

Return Value

void

void testAttributeInReflectionButNotInStubsFails()

No description

Return Value

void

void testAttributeInStubsButNotInReflectionFails()

No description

Return Value

void

void testDefaultFlagsTreatedAsTargetAll()

No description

Return Value

void

void testNamedFlagsArgumentSupported()

No description

Return Value

void

void testClassNotFoundInReflection()

No description

Return Value

void

void testClassNotFoundInStubs()

No description

Return Value

void

void testSingleSymbolicFlagIsResolvedNotCastToZero()

The stub parser falls back to a symbolic name when the constant is not defined on the runtime that parsed the stubs. Casting that with (int) yields 0, so a stub declaring exactly the right target was reported as declaring none.

Return Value

void

void testMixedSymbolicBitwiseOrIsResolvedNotTruncated()

The worst case: "1|Attribute::TARGET_CONSTANT" casts to 1, which is a valid-looking bitmask, so the check reported a confident, wrong "missing target(s)" result.

Return Value

void

void testFullySymbolicBitwiseOrIsResolved()

No description

Return Value

void

void testSymbolicResolutionStillDetectsARealMismatch()

A genuine mismatch must still be reported — the resolution must not mask real defects.

Return Value

void

void testUnresolvableFlagsFailWithTheRawValue()

An unresolvable value must fail loudly with the raw text rather than being cast to a plausible-looking number and compared.

Return Value

void

void testBareAttributeUsesTheVersionsTargetAllOn85AndLater()

#[Attribute] with no flags means TARGET_ALL, which widened from 63 to 127 in PHP 8.5 when TARGET_CONSTANT was added. The old code hardcoded 63 as its fallback.

Return Value

void

void testBareAttributeUsesTheNarrowerTargetAllBefore85()

No description

Return Value

void

void testBareAttributeIsVersionSensitive()

The same bare stub declaration must not satisfy both 63 and 127 — otherwise the version map is being ignored.

Return Value

void