diff --git a/.circleci/config.yml b/.circleci/config.yml index b42ea03..c3411c8 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,6 +3,7 @@ jobs: build: environment: CC_TEST_REPORTER_ID: 8ec926841c6dfead9c848fd063c569e11b06be11442a8175d588e10607ee2150 + XDEBUG_MODE: coverage docker: - image: circleci/php:7-cli-node-browsers-legacy working_directory: ~/repo diff --git a/src/RootedJsonData.php b/src/RootedJsonData.php index 506e409..c13a080 100644 --- a/src/RootedJsonData.php +++ b/src/RootedJsonData.php @@ -87,7 +87,7 @@ public function __toString() */ public function get(string $path) { - if ($this->__isset($path) === false) { + if (!isset($this->{$path})) { return null; } return $this->data->get($path); @@ -103,7 +103,7 @@ public function get(string $path) */ public function __get(string $path) { - return $this->data->get($path); + return $this->get($path); } /** @@ -146,9 +146,17 @@ public function __set($path, $value) public function __isset($name) { $notSmart = new JsonObject("{$this->data}"); - return $notSmart->get($name) ? true : false; + $thing = $notSmart->get($name); + return ($thing === false) ? false : true; } + public function __unset($name) + { + $field = str_replace('$.', '', $name); + $this->data->remove('$', $field); + } + + public function getSchema() { return $this->schema; diff --git a/tests/RootedJsonDatatTest.php b/tests/RootedJsonDatatTest.php index 03b4f52..11d4838 100644 --- a/tests/RootedJsonDatatTest.php +++ b/tests/RootedJsonDatatTest.php @@ -119,4 +119,12 @@ public function testSchemaGetter() $data = new RootedJsonData($json, $schema); $this->assertEquals($schema, $data->getSchema()); } + + public function testUnset() + { + $json = '{"number":51}'; + $data = new RootedJsonData($json); + unset($data->{'$.number'}); + $this->assertNull($data->{'$.number'}); + } }