class UnaryOperator
@no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Hierarchy
- class \PHPUnit\Framework\Constraint\Constraint implements \Countable, \PHPUnit\Framework\SelfDescribing
- class \PHPUnit\Framework\Constraint\Operator extends \PHPUnit\Framework\Constraint\Constraint
- class \PHPUnit\Framework\Constraint\UnaryOperator extends \PHPUnit\Framework\Constraint\Operator
- class \PHPUnit\Framework\Constraint\Operator extends \PHPUnit\Framework\Constraint\Constraint
Expanded class hierarchy of UnaryOperator
File
-
vendor/
phpunit/ phpunit/ src/ Framework/ Constraint/ Operator/ UnaryOperator.php, line 17
Namespace
PHPUnit\Framework\ConstraintView source
abstract class UnaryOperator extends Operator {
private readonly Constraint $constraint;
public function __construct(mixed $constraint) {
$this->constraint = $this->checkConstraint($constraint);
}
/**
* Returns the number of operands (constraints).
*/
public function arity() : int {
return 1;
}
/**
* Returns a string representation of the constraint.
*/
public function toString() : string {
$reduced = $this->reduce();
if ($reduced !== $this) {
return $reduced->toString();
}
$constraint = $this->constraint
->reduce();
if ($this->constraintNeedsParentheses($constraint)) {
return $this->operator() . '( ' . $constraint->toString() . ' )';
}
$string = $constraint->toStringInContext($this, 0);
if ($string === '') {
return $this->transformString($constraint->toString());
}
return $string;
}
/**
* Counts the number of constraint elements.
*/
public function count() : int {
return count($this->constraint);
}
/**
* 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.
*/
protected function failureDescription(mixed $other) : string {
$reduced = $this->reduce();
if ($reduced !== $this) {
return $reduced->failureDescription($other);
}
$constraint = $this->constraint
->reduce();
if ($this->constraintNeedsParentheses($constraint)) {
return $this->operator() . '( ' . $constraint->failureDescription($other) . ' )';
}
$string = $constraint->failureDescriptionInContext($this, 0, $other);
if ($string === '') {
return $this->transformString($constraint->failureDescription($other));
}
return $string;
}
/**
* Transforms string returned by the member constraint's toString() or
* failureDescription() such that it reflects constraint's participation in
* this expression.
*
* The method may be overwritten in a subclass to apply default
* transformation in case the operand constraint does not provide its own
* custom strings via toStringInContext() or failureDescriptionInContext().
*/
protected function transformString(string $string) : string {
return $string;
}
/**
* Provides access to $this->constraint for subclasses.
*/
protected final function constraint() : Constraint {
return $this->constraint;
}
/**
* Returns true if the $constraint needs to be wrapped with parentheses.
*/
protected function constraintNeedsParentheses(Constraint $constraint) : bool {
$constraint = $constraint->reduce();
return $constraint instanceof self || parent::constraintNeedsParentheses($constraint);
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
Constraint::additionalFailureDescription | protected | function | Return additional failure description where needed. | 7 | |
Constraint::evaluate | public | function | Evaluates the constraint for parameter $other. | 7 | |
Constraint::exporter | protected | function | |||
Constraint::fail | protected | function | Throws an exception for the given compared value and test description. | 1 | |
Constraint::failureDescriptionInContext | protected | function | Returns the description of the failure when this constraint appears in context of an $operator expression. |
||
Constraint::matches | protected | function | Evaluates the constraint for parameter $other. Returns true if the constraint is met, false otherwise. |
70 | |
Constraint::reduce | protected | function | Reduces the sub-expression starting at $this by skipping degenerate sub-expression and returns first descendant constraint that starts a non-reducible sub-expression. |
2 | |
Constraint::toStringInContext | protected | function | Returns a custom string representation of the constraint object when it appears in context of an $operator expression. |
||
Constraint::valueToTypeStringFragment | protected | function | @psalm-return non-empty-string | ||
Operator::checkConstraint | protected | function | Validates $constraint argument. | ||
Operator::operator | abstract public | function | Returns the name of this operator. | 4 | |
Operator::precedence | abstract public | function | Returns this operator's precedence. | 4 | |
UnaryOperator::$constraint | private | property | |||
UnaryOperator::arity | public | function | Returns the number of operands (constraints). | Overrides Operator::arity | |
UnaryOperator::constraint | final protected | function | Provides access to $this->constraint for subclasses. | ||
UnaryOperator::constraintNeedsParentheses | protected | function | Returns true if the $constraint needs to be wrapped with parentheses. | Overrides Operator::constraintNeedsParentheses | |
UnaryOperator::count | public | function | Counts the number of constraint elements. | Overrides Constraint::count | |
UnaryOperator::failureDescription | protected | function | Returns the description of the failure. | Overrides Constraint::failureDescription | |
UnaryOperator::toString | public | function | Returns a string representation of the constraint. | Overrides SelfDescribing::toString | |
UnaryOperator::transformString | protected | function | Transforms string returned by the member constraint's toString() or failureDescription() such that it reflects constraint's participation in this expression. |
1 | |
UnaryOperator::__construct | public | function |