Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. LogicalNot.php

class LogicalNot

@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\LogicalNot extends \PHPUnit\Framework\Constraint\UnaryOperator

Expanded class hierarchy of LogicalNot

2 files declare their use of LogicalNot
Assert.php in vendor/phpunit/phpunit/src/Framework/Assert.php
Functions.php in vendor/phpunit/phpunit/src/Framework/Assert/Functions.php

File

vendor/phpunit/phpunit/src/Framework/Constraint/Operator/LogicalNot.php, line 22

Namespace

PHPUnit\Framework\Constraint
View source
final class LogicalNot extends UnaryOperator {
    public static function negate(string $string) : string {
        $positives = [
            'contains ',
            'exists',
            'has ',
            'is ',
            'are ',
            'matches ',
            'starts with ',
            'ends with ',
            'reference ',
            'not not ',
        ];
        $negatives = [
            'does not contain ',
            'does not exist',
            'does not have ',
            'is not ',
            'are not ',
            'does not match ',
            'starts not with ',
            'ends not with ',
            'don\'t reference ',
            'not ',
        ];
        preg_match('/(\'[\\w\\W]*\')([\\w\\W]*)("[\\w\\W]*")/i', $string, $matches);
        if (count($matches) === 0) {
            preg_match('/(\'[\\w\\W]*\')([\\w\\W]*)(\'[\\w\\W]*\')/i', $string, $matches);
        }
        $positives = array_map(static fn(string $s) => '/\\b' . preg_quote($s, '/') . '/', $positives);
        if (count($matches) > 0) {
            $nonInput = $matches[2];
            $negatedString = preg_replace('/' . preg_quote($nonInput, '/') . '/', preg_replace($positives, $negatives, $nonInput), $string);
        }
        else {
            $negatedString = preg_replace($positives, $negatives, $string);
        }
        return $negatedString;
    }
    
    /**
     * Returns the name of this operator.
     */
    public function operator() : string {
        return 'not';
    }
    
    /**
     * Returns this operator's precedence.
     *
     * @see https://www.php.net/manual/en/language.operators.precedence.php
     */
    public function precedence() : int {
        return 5;
    }
    
    /**
     * Evaluates the constraint for parameter $other. Returns true if the
     * constraint is met, false otherwise.
     *
     * @throws ExpectationFailedException
     */
    protected function matches(mixed $other) : bool {
        return !$this->constraint()
            ->evaluate($other, '', true);
    }
    
    /**
     * Applies additional transformation to strings returned by toString() or
     * failureDescription().
     */
    protected function transformString(string $string) : string {
        return self::negate($string);
    }
    
    /**
     * 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 {
        $constraint = $this->constraint();
        if ($constraint instanceof self) {
            return $constraint->constraint()
                ->reduce();
        }
        return parent::reduce();
    }

}

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::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
LogicalNot::matches protected function Evaluates the constraint for parameter $other. Returns true if the
constraint is met, false otherwise.
Overrides Constraint::matches
LogicalNot::negate public static function
LogicalNot::operator public function Returns the name of this operator. Overrides Operator::operator
LogicalNot::precedence public function Returns this operator's precedence. Overrides Operator::precedence
LogicalNot::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
LogicalNot::transformString protected function Applies additional transformation to strings returned by toString() or
failureDescription().
Overrides UnaryOperator::transformString
Operator::checkConstraint protected function Validates $constraint argument.
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::__construct public function

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal