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

Commit a20d03b

Browse files
authored
Merge pull request #1034 from foaly-nr1/id
Conserve id when next to data key, resolves #700
2 parents 2d0b785 + 0174934 commit a20d03b

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Version 5 of the Facebook PHP SDK is a complete refactor of version 4. It comes
1212
- Fixed HTTP/2 support (#1079)
1313
- Fixed resumable upload error (#1001)
1414
- Strip 'enforce_https' param (#1084)
15+
- Conserve id when next to data key, resolves #700 (#1034)
1516
- 5.6.3 (2018-07-01)
1617
- Add fix for countable error in PHP 7.2 (originally #969 by @andreybolonin)
1718
- 5.6.2 (2018-02-15)

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)