final class ImplementsInterface extends AbstractConstraint

Constraint that accepts classes that implement given interface.

Traits

Implementation of an inheritance constraint class.

Methods

__construct(string $expected)

Initializes the constraint.

string
toString()

Returns a string representation of the constraint.

bool
matches(mixed $other)

Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise.

string
failureDescription(mixed $other)

Returns the description of the failure.

string
verb()

Returns short description of what we examine, e.g. 'impements interface'.

string
negatedVerb()

Returns short negated description of what we examine, e.g. 'does not impement interface'.

array
inheritance(string $class)

No description

bool
supports(string $subject)

Checks if $subject may be used as an argument to inheritance().

string
toStringInContext(Operator $operator, mixed $role)

Returns a custom string representation of the constraint object when it appears in context of an $operator expression.

string
failureDescriptionInContext(Operator $operator, mixed $role, mixed $other)

Returns the description of the failure when this constraint appears in context of an $operator expression.

create(string $expected)

No description

Details

in AbstractConstraint at line 39
protected __construct(string $expected)

Initializes the constraint.

Parameters

string $expected

in AbstractConstraint at line 47
final string toString()

Returns a string representation of the constraint.

Return Value

string

in AbstractConstraint at line 58
final bool matches(mixed $other)

Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise.

Parameters

mixed $other

value or object to evaluate

Return Value

bool

in AbstractConstraint at line 78
final string failureDescription(mixed $other)

Returns the description of the failure.

The beginning of failure messages is "Failed asserting that" in most cases. This method should return the second part of that sentence.

Parameters

mixed $other

evaluated value or object

Return Value

string

protected string verb()

Returns short description of what we examine, e.g. 'impements interface'.

Return Value

string

protected string negatedVerb()

Returns short negated description of what we examine, e.g. 'does not impement interface'.

Return Value

string

protected array inheritance(string $class)

No description

Parameters

string $class

Return Value

array

Exceptions

InvalidReturnValueException

protected bool supports(string $subject)

Checks if $subject may be used as an argument to inheritance().

Parameters

string $subject

Return Value

bool

in AbstractConstraint at line 122
final protected string toStringInContext(Operator $operator, mixed $role)

Returns a custom string representation of the constraint object when it appears in context of an $operator expression.

The purpose of this method is to provide meaningful descriptive string in context of operators such as LogicalNot. Native PHPUnit constraints are supported out of the box by LogicalNot, but externally developed ones had no way to provide correct strings in this context.

The method shall return empty string, when it does not handle customization by itself.

Parameters

Operator $operator

the $operator of the expression

mixed $role

role of $this constraint in the $operator expression

Return Value

string

in AbstractConstraint at line 149
final protected string failureDescriptionInContext(Operator $operator, mixed $role, mixed $other)

Returns the description of the failure when this constraint appears in context of an $operator expression.

The purpose of this method is to provide meaningful failue description in context of operators such as LogicalNot. Native PHPUnit constraints are supported out of the box by LogicalNot, but externally developed ones had no way to provide correct messages in this context.

The method shall return empty string, when it does not handle customization by itself.

Parameters

Operator $operator

the $operator of the expression

mixed $role

role of $this constraint in the $operator expression

mixed $other

evaluated value or object

Return Value

string

Exceptions

InvalidArgumentException

static ConstraintImplementationTrait create(string $expected)

No description

Parameters

string $expected

Return Value

ConstraintImplementationTrait

Exceptions

InvalidArgumentException