PHPUnit_Framework_Constraint_StringContains::evaluate PHP Method

evaluate() public method

Evaluates the constraint for parameter $other. Returns TRUE if the constraint is met, FALSE otherwise.
public evaluate ( mixed $other ) : boolean
$other mixed Value or object to evaluate.
return boolean
    public function evaluate($other)
    {
        if ($this->ignoreCase) {
            return stripos($other, $this->string) !== FALSE;
        } else {
            return strpos($other, $this->string) !== FALSE;
        }
    }

Usage Example

示例#1
0
 public static function assertException($runnable, $class, $message)
 {
     try {
         $runnable();
         self::fail('No exception thrown');
     } catch (Exception $e) {
         if ($e instanceof $class) {
             $messageConstraint = new PHPUnit_Framework_Constraint_StringContains($message, true);
             if (!$messageConstraint->evaluate($e->getMessage())) {
                 throw $messageConstraint->fail($e->getMessage(), PHP_EOL . $e->getTraceAsString());
             }
             self::assertTrue(true);
             // update assertion counter
             self::assertTrue(true);
             // update assertion counter
         } else {
             if ($e instanceof PHPUnit_Framework_AssertionFailedError && $e->getMessage() === 'No exception thrown') {
                 throw $e;
             }
             $constraint = new PHPUnit_Framework_Constraint_IsInstanceOf($class);
             throw $constraint->fail($e, 'Expected ' . $class . ' but ' . get_class($e) . ' with message "' . $e->getMessage() . '"' . PHP_EOL . $e->getTraceAsString());
         }
     }
 }
All Usage Examples Of PHPUnit_Framework_Constraint_StringContains::evaluate
PHPUnit_Framework_Constraint_StringContains