PHPUnit_Framework_Constraint_Not::toString PHP Method

toString() public method

Returns a string representation of the constraint.
public toString ( ) : string
return string
    public function toString()
    {
        switch (get_class($this->constraint)) {
            case 'PHPUnit_Framework_Constraint_And':
            case 'PHPUnit_Framework_Constraint_Not':
            case 'PHPUnit_Framework_Constraint_Or':
                return 'not( ' . $this->constraint->toString() . ' )';
                break;
            default:
                return PHPUnit_Framework_Constraint::negate($this->constraint->toString());
        }
    }

Usage Example

Esempio n. 1
0
 public function testConstraintTraversableNotContains()
 {
     $constraint = new PHPUnit_Framework_Constraint_Not(new PHPUnit_Framework_Constraint_TraversableContains('foo'));
     $this->assertTrue($constraint->evaluate(array('bar')));
     $this->assertFalse($constraint->evaluate(array('foo')));
     $this->assertEquals('does not contain <string:foo>', $constraint->toString());
     try {
         $constraint->fail(array('foo'), '');
     } catch (PHPUnit_Framework_ExpectationFailedException $e) {
         $this->assertEquals("Failed asserting that \nArray\n(\n    [0] => foo\n)\n does not contain <string:foo>.", $e->getDescription());
         return;
     }
     $this->fail();
 }