From cf814c5aae18a2c3ea94d53b9178a8c7ecffb4c2 Mon Sep 17 00:00:00 2001 From: Vitaly Bormotov Date: Tue, 7 Mar 2017 12:20:27 +0300 Subject: [PATCH] Fix isset($response->field) syntax (#35) --- lib/RetailCrm/Response/ApiResponse.php | 12 ++++++++++++ .../Tests/Response/ApiResponseTest.php | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/lib/RetailCrm/Response/ApiResponse.php b/lib/RetailCrm/Response/ApiResponse.php index 6959f2c..03ecb82 100644 --- a/lib/RetailCrm/Response/ApiResponse.php +++ b/lib/RetailCrm/Response/ApiResponse.php @@ -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 * diff --git a/tests/RetailCrm/Tests/Response/ApiResponseTest.php b/tests/RetailCrm/Tests/Response/ApiResponseTest.php index 470fd17..43e9f1b 100644 --- a/tests/RetailCrm/Tests/Response/ApiResponseTest.php +++ b/tests/RetailCrm/Tests/Response/ApiResponseTest.php @@ -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' + ); + } }