Skip to content

Commit

Permalink
Remove asJson from GraphNode
Browse files Browse the repository at this point in the history
  • Loading branch information
yguedidi committed Dec 19, 2017
1 parent 21e76be commit 0673ccd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
14 changes: 1 addition & 13 deletions src/GraphNode/GraphNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,6 @@ public function asArray()
}, $this->fields);
}

/**
* Get all fields as JSON.
*
* @param int $options
*
* @return string
*/
public function asJson($options = 0)
{
return json_encode($this->uncastFields(), $options);
}

/**
* Get an iterator for the fields.
*
Expand Down Expand Up @@ -184,7 +172,7 @@ public function offsetUnset($key)
*/
public function __toString()
{
return $this->asJson();
return json_encode($this->uncastFields());
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/GraphNode/GraphNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ public function testGettingGraphNodeAsAnArrayWillNotUncastTheDateTimeObject()
$this->assertInstanceOf(\DateTime::class, $graphNodeAsArray['created_time']);
}

public function testGettingAGraphNodeAsJSONWillSafelyRepresentDateTimes()
public function testGettingAGraphNodeAsAStringWillSafelyRepresentDateTimes()
{
$graphNode = new GraphNode([
'id' => '123',
'created_time' => '2014-07-15T03:44:53+0000',
]);

$graphNodeAsString = $graphNode->asJson();
$graphNodeAsString = (string) $graphNode;

$this->assertEquals('{"id":"123","created_time":"2014-07-15T03:44:53+0000"}', $graphNodeAsString);
}
Expand Down Expand Up @@ -186,11 +186,11 @@ public function testAnArrayCanBeInjectedViaTheConstructor()
$this->assertEquals(['foo', 'bar'], $graphNode->asArray());
}

public function testACollectionCanBeConvertedToProperJson()
public function testAGraphNodeCanBeConvertedToAString()
{
$graphNode = new GraphNode(['foo', 'bar', 123]);

$graphNodeAsString = $graphNode->asJson();
$graphNodeAsString = (string) $graphNode;

$this->assertEquals('["foo","bar",123]', $graphNodeAsString);
}
Expand Down

0 comments on commit 0673ccd

Please sign in to comment.