class BinaryOperator
@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\BinaryOperator extends \PHPUnit\Framework\Constraint\Operator
- class \PHPUnit\Framework\Constraint\Operator extends \PHPUnit\Framework\Constraint\Constraint
Expanded class hierarchy of BinaryOperator
File
-
vendor/
phpunit/ phpunit/ src/ Framework/ Constraint/ Operator/ BinaryOperator.php, line 18
Namespace
PHPUnit\Framework\ConstraintView source
abstract class BinaryOperator extends Operator {
/**
* @psalm-var list<Constraint>
*/
private readonly array $constraints;
protected function __construct(mixed ...$constraints) {
$this->constraints = array_map(fn($constraint): Constraint => $this->checkConstraint($constraint), $constraints);
}
/**
* Returns the number of operands (constraints).
*/
public final function arity() : int {
return count($this->constraints);
}
/**
* Returns a string representation of the constraint.
*/
public function toString() : string {
$reduced = $this->reduce();
if ($reduced !== $this) {
return $reduced->toString();
}
$text = '';
foreach ($this->constraints as $key => $constraint) {
$constraint = $constraint->reduce();
$text .= $this->constraintToString($constraint, $key);
}
return $text;
}
/**
* Counts the number of constraint elements.
*/
public function count() : int {
$count = 0;
foreach ($this->constraints as $constraint) {
$count += count($constraint);
}
return $count;
}
/**
* @psalm-return list<Constraint>
*/
protected final function constraints() : array {
return $this->constraints;
}
/**
* Returns true if the $constraint needs to be wrapped with braces.
*/
protected final function constraintNeedsParentheses(Constraint $constraint) : bool {
return $this->arity() > 1 && parent::constraintNeedsParentheses($constraint);
}
/**
* Reduces the sub-expression starting at $this by skipping degenerate
* sub-expression and returns first descendant constraint that starts
* a non-reducible sub-expression.
*
* See Constraint::reduce() for more.
*/
protected function reduce() : Constraint {
if ($this->arity() === 1 && $this->constraints[0] instanceof Operator) {
return $this->constraints[0]
->reduce();
}
return parent::reduce();
}
/**
* Returns string representation of given operand in context of this operator.
*/
private function constraintToString(Constraint $constraint, int $position) : string {
$prefix = '';
if ($position > 0) {
$prefix = ' ' . $this->operator() . ' ';
}
if ($this->constraintNeedsParentheses($constraint)) {
return $prefix . '( ' . $constraint->toString() . ' )';
}
$string = $constraint->toStringInContext($this, $position);
if ($string === '') {
$string = $constraint->toString();
}
return $prefix . $string;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
BinaryOperator::$constraints | private | property | @psalm-var list<Constraint> | ||
BinaryOperator::arity | final public | function | Returns the number of operands (constraints). | Overrides Operator::arity | |
BinaryOperator::constraintNeedsParentheses | final protected | function | Returns true if the $constraint needs to be wrapped with braces. | Overrides Operator::constraintNeedsParentheses | |
BinaryOperator::constraints | final protected | function | @psalm-return list<Constraint> | ||
BinaryOperator::constraintToString | private | function | Returns string representation of given operand in context of this operator. | ||
BinaryOperator::count | public | function | Counts the number of constraint elements. | Overrides Constraint::count | |
BinaryOperator::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. |
Overrides Constraint::reduce | |
BinaryOperator::toString | public | function | Returns a string representation of the constraint. | Overrides SelfDescribing::toString | |
BinaryOperator::__construct | protected | function | |||
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::failureDescription | protected | function | Returns the description of the failure. | 51 | |
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::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 |