PHPUnit_Framework_Constraint_IsType::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)
    {
        switch ($this->type) {
            case 'numeric':
                return is_numeric($other);
            case 'integer':
            case 'int':
                return is_integer($other);
            case 'float':
                return is_float($other);
            case 'string':
                return is_string($other);
            case 'boolean':
            case 'bool':
                return is_bool($other);
            case 'null':
                return is_null($other);
            case 'array':
                return is_array($other);
            case 'object':
                return is_object($other);
            case 'resource':
                return is_resource($other);
            case 'scalar':
                return is_scalar($other);
        }
    }

Usage Example

示例#1
0
 public function testConstraintIsType()
 {
     $constraint = new PHPUnit_Framework_Constraint_IsType('string');
     $this->assertFalse($constraint->evaluate(0));
     $this->assertTrue($constraint->evaluate(''));
     $this->assertEquals('is of type "string"', $constraint->toString());
     try {
         $constraint->fail(new stdClass(), '');
     } catch (PHPUnit_Framework_ExpectationFailedException $e) {
         $this->assertEquals("Failed asserting that \nstdClass Object\n(\n)\n is of type \"string\".", $e->getDescription());
         return;
     }
     $this->fail();
 }
All Usage Examples Of PHPUnit_Framework_Constraint_IsType::evaluate
PHPUnit_Framework_Constraint_IsType