Skip to content
This repository has been archived by the owner on Jul 25, 2023. It is now read-only.

Commit

Permalink
Merge pull request #13 from alanwillms/fix-isset
Browse files Browse the repository at this point in the history
Fix __isset missing `isset`
  • Loading branch information
Rob Wells committed Jan 5, 2020
2 parents bacb19a + 4a8f84f commit e26f543
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 41 deletions.
75 changes: 37 additions & 38 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ public function __set($name, $value)
*/
public function __isset($name)
{
return $this->data->{$name};
return isset($this->data->{$name});
}

/**
* @param $name
*/
Expand Down
14 changes: 13 additions & 1 deletion tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,16 @@ public function testIssetReturnsCorrectly()
static::assertTrue(isset($response->One->translations[0]->code));
static::assertNotTrue(isset($response->Two->translations[0]->code));
}
}

public function testIssetReturnsCorrectlyWithMissingField()
{
$data = '{"data":{"One":1}}';

$jsonObj = json_decode($data);

$response = new Response($jsonObj);

static::assertTrue(isset($response->One));
static::assertNotTrue(isset($response->Two));
}
}

0 comments on commit e26f543

Please sign in to comment.