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
    /**
     * @covers PHPUnit_Framework_Constraint_TraversableContains
     * @covers PHPUnit_Framework_TestFailure::exceptionToString
     */
    public function testConstraintSplObjectStorageContains2()
    {
        $object = new StdClass();
        $constraint = new PHPUnit_Framework_Constraint_TraversableContains($object);
        try {
            $constraint->evaluate(new SplObjectStorage(), 'custom message');
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
            $this->assertStringMatchesFormat(<<<EOF
custom message
Failed asserting that a traversable contains stdClass Object &%x ().

EOF
, PHPUnit_Framework_TestFailure::exceptionToString($e));
            return;
        }
        $this->fail();
    }
 /**
  * @covers PHPUnit_Framework_Constraint_TraversableContains
  * @covers PHPUnit_Framework_Constraint::count
  */
 public function testConstraintSplObjectStorageContains()
 {
     $object = new StdClass();
     $constraint = new PHPUnit_Framework_Constraint_TraversableContains($object);
     $this->assertEquals("contains \nstdClass Object\n(\n)\n", $constraint->toString());
     $storage = new SplObjectStorage();
     $this->assertFalse($constraint->evaluate($storage));
     $storage->attach($object);
     $this->assertTrue($constraint->evaluate($storage));
     try {
         $constraint->fail(new SplObjectStorage(), '');
     } catch (PHPUnit_Framework_ExpectationFailedException $e) {
         $this->assertEquals("Failed asserting that an iterator contains \nstdClass Object\n(\n)\n.", $e->getDescription());
         return;
     }
     $this->fail();
 }
Ejemplo n.º 3
0
 public function testConstraintTraversableContains()
 {
     $constraint = new PHPUnit_Framework_Constraint_TraversableContains('foo');
     $this->assertFalse($constraint->evaluate(array('bar')));
     $this->assertTrue($constraint->evaluate(array('foo')));
     $this->assertEquals('contains <string:foo>', $constraint->toString());
     try {
         $constraint->fail(array('bar'), '');
     } catch (PHPUnit_Framework_ExpectationFailedException $e) {
         $this->assertEquals("Failed asserting that \nArray\n(\n    [0] => bar\n)\n contains <string:foo>.", $e->getDescription());
         return;
     }
     $this->fail();
 }