PHPUnit_Framework_Assert::assertObjectHasAttribute PHP Method

assertObjectHasAttribute() public static method

Asserts that an object has a specified attribute.
public static assertObjectHasAttribute ( string $attributeName, object $object, string $message = '' )
$attributeName string
$object object
$message string
    public static function assertObjectHasAttribute($attributeName, $object, $message = '')
    {
        if (!is_string($attributeName)) {
            throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
        }
        if (!preg_match('/[a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*/', $attributeName)) {
            throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'valid attribute name');
        }
        if (!is_object($object)) {
            throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'object');
        }
        $constraint = new PHPUnit_Framework_Constraint_ObjectHasAttribute($attributeName);
        static::assertThat($object, $constraint, $message);
    }

Usage Example

    /**
     * @When I create an expense list named :name
     */
    public function iCreateAnExpenseListNamed($name)
    {
        $json = <<<JSON
{
  "name": "{$name}"
}
JSON;
        $this->client->request('POST', '/expense_list/', [], [], ['CONTENT_TYPE' => 'application/json'], $json);
        $response = $this->client->getResponse();
        PHPUnit_Framework_Assert::assertEquals(Response::HTTP_CREATED, $response->getStatusCode());
        PHPUnit_Framework_Assert::assertJson($response->getContent());
        $responseData = json_decode($response->getContent());
        PHPUnit_Framework_Assert::assertNotNull($responseData);
        PHPUnit_Framework_Assert::assertObjectHasAttribute('id', $responseData);
        $this->expenseListId = $responseData->id;
    }
All Usage Examples Of PHPUnit_Framework_Assert::assertObjectHasAttribute
PHPUnit_Framework_Assert