objectHasAttribute() public static method

Returns a PHPUnit_Framework_Constraint_ObjectHasAttribute matcher object.
public static objectHasAttribute ( string $attributeName ) : PHPUnit_Framework_Constraint_ObjectHasAttribute
$attributeName string
return PHPUnit_Framework_Constraint_ObjectHasAttribute
 /**
  * @covers PHPUnit_Framework_Constraint_ObjectHasAttribute
  * @covers PHPUnit_Framework_Constraint_Not
  * @covers PHPUnit_Framework_Assert::objectHasAttribute
  * @covers PHPUnit_Framework_Assert::logicalNot
  */
 public function testConstraintObjectNotHasAttribute2()
 {
     $constraint = PHPUnit_Framework_Assert::logicalNot(PHPUnit_Framework_Assert::objectHasAttribute('foo'));
     $o = new stdClass();
     $o->foo = 'bar';
     try {
         $constraint->fail($o, 'custom message', TRUE);
     } catch (PHPUnit_Framework_ExpectationFailedException $e) {
         $this->assertEquals("custom message\nFailed asserting that object of class \"stdClass\" does not have attribute \"foo\".", $e->getDescription());
         return;
     }
     $this->fail();
 }
Ejemplo n.º 2
0
/**
 * Returns a PHPUnit_Framework_Constraint_ObjectHasAttribute matcher object.
 *
 * @param  string $attributeName
 * @return PHPUnit_Framework_Constraint_ObjectHasAttribute
 * @since  Method available since Release 3.0.0
 */
function objectHasAttribute($attributeName)
{
    return PHPUnit_Framework_Assert::objectHasAttribute($attributeName);
}
    /**
     * @covers PHPUnit_Framework_Constraint_ObjectHasAttribute
     * @covers PHPUnit_Framework_Constraint_Not
     * @covers PHPUnit_Framework_Assert::objectHasAttribute
     * @covers PHPUnit_Framework_Assert::logicalNot
     * @covers PHPUnit_Framework_TestFailure::exceptionToString
     */
    public function testConstraintObjectNotHasAttribute2()
    {
        $constraint = PHPUnit_Framework_Assert::logicalNot(PHPUnit_Framework_Assert::objectHasAttribute('privateAttribute'));
        try {
            $constraint->evaluate(new ClassWithNonPublicAttributes(), 'custom message');
        } catch (PHPUnit_Framework_ExpectationFailedException $e) {
            $this->assertEquals(<<<EOF
custom message
Failed asserting that object of class "ClassWithNonPublicAttributes" does not have attribute "privateAttribute".

EOF
, PHPUnit_Framework_TestFailure::exceptionToString($e));
            return;
        }
        $this->fail();
    }