Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit a7d9703

Browse files
committed
Conserve data on same level as data array
1 parent 2d0b785 commit a7d9703

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/Facebook/GraphNodes/GraphNodeFactory.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ public function castAsGraphNodeOrGraphEdge(array $data, $subclassName = null, $p
304304
return $this->safelyMakeGraphEdge($data, $subclassName, $parentKey, $parentNodeId);
305305
}
306306
// Sometimes Graph is a weirdo and returns a GraphNode under the "data" key
307-
$data = $data['data'];
307+
$outerData = $data;
308+
unset($outerData['data']);
309+
$data = $data['data'] + $outerData;
308310
}
309311

310312
// Create GraphNode

tests/GraphNodes/GraphNodeFactoryTest.php

+27
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,33 @@ public function testAGraphNodeWithARootDataKeyWillBeCastAsAGraphNode()
247247
], $graphData);
248248
}
249249

250+
public function testAGraphNodeWithARootDataKeyWillConserveRootKeys()
251+
{
252+
$data = json_encode([
253+
'id' => '123',
254+
'foo' => 'bar',
255+
'data' => [
256+
'name' => 'Foo McBar',
257+
'link' => 'http://facebook/foo',
258+
],
259+
]);
260+
261+
$res = new FacebookResponse($this->request, $data);
262+
$factory = new GraphNodeFactory($res);
263+
$graphNode = $factory->makeGraphNode();
264+
265+
$this->assertInstanceOf('\Facebook\GraphNodes\GraphNode', $graphNode);
266+
267+
$graphData = $graphNode->asArray();
268+
269+
$this->assertEquals([
270+
'id' => '123',
271+
'foo' => 'bar',
272+
'name' => 'Foo McBar',
273+
'link' => 'http://facebook/foo',
274+
], $graphData);
275+
}
276+
250277
public function testAGraphEdgeWillBeCastRecursively()
251278
{
252279
$someUser = [

0 commit comments

Comments
 (0)