1
0
mirror of synced 2024-11-24 22:36:06 +03:00

Fix isset($response->field) syntax (#35)

This commit is contained in:
Vitaly Bormotov 2017-03-07 12:20:27 +03:00 committed by Alex Lushpai
parent 8c583de05b
commit cf814c5aae
2 changed files with 30 additions and 0 deletions

View File

@ -121,6 +121,18 @@ class ApiResponse implements \ArrayAccess
return $this->response[$name];
}
/**
* Allow to check if the property exists through object property
*
* @param string $name property name
*
* @return bool
*/
public function __isset($name)
{
return isset($this->response[$name]);
}
/**
* Offset set
*

View File

@ -251,4 +251,22 @@ class ApiResponseTest extends TestCase
$response = new ApiResponse(201, '{ "success": true }');
unset($response['sssssssuccess']);
}
/**
* @group unit
*/
public function testMagicIsset()
{
$response = new ApiResponse(201, '{ "success": true }');
$this->assertTrue(
isset($response->success),
'Response object returns property existing'
);
$this->assertFalse(
isset($response->suess),
'Response object returns property existing'
);
}
}