The attribute name is passed in the constructor.
public function testFailureObjectHasAttribute2() { $constraint = new PHPUnit_Framework_Constraint_ObjectHasAttribute('foo'); try { $constraint->fail(new stdClass(), 'custom message'); } catch (PHPUnit_Framework_ExpectationFailedException $e) { $this->assertEquals("custom message\nFailed asserting that object of class \"stdClass\" has attribute \"foo\".\n", PHPUnit_Framework_TestFailure::exceptionToString($e)); return; } $this->fail(); }
public function testConstraintObjectHasAttribute2() { $constraint = new PHPUnit_Framework_Constraint_ObjectHasAttribute('foo'); try { $constraint->fail(new stdClass(), 'custom message'); } catch (PHPUnit_Framework_ExpectationFailedException $e) { $this->assertEquals("custom message\nFailed asserting that \nstdClass Object\n(\n)\n has attribute \"foo\".", $e->getDescription()); return; } $this->fail(); }
public function testConstraintObjectHasAttribute() { $constraint = new PHPUnit_Framework_Constraint_ObjectHasAttribute('foo'); $this->assertFalse($constraint->evaluate(new stdClass())); $this->assertEquals('has attribute "foo"', $constraint->toString()); try { $constraint->fail(new stdClass(), ''); } catch (PHPUnit_Framework_ExpectationFailedException $e) { $this->assertEquals("Failed asserting that \nstdClass Object\n(\n)\n has attribute \"foo\".", $e->getDescription()); return; } $this->fail(); }