Skip to content

Commit fe0728d

Browse files
authored
Merge pull request facebookarchive#715 from qpautrat/overwrite_graph_edge_map
Fix map implementation in GraphEdge class.
2 parents 73b8b44 + 34bf650 commit fe0728d

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/Facebook/GraphNodes/GraphEdge.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,18 @@ public function getTotalCount()
235235

236236
return null;
237237
}
238+
239+
/**
240+
* @inheritDoc
241+
*/
242+
public function map(\Closure $callback)
243+
{
244+
return new static(
245+
$this->request,
246+
array_map($callback, $this->items, array_keys($this->items)),
247+
$this->metaData,
248+
$this->parentEdgeEndpoint,
249+
$this->subclassName
250+
);
251+
}
238252
}

tests/GraphNodes/GraphEdgeTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
use Facebook\FacebookApp;
2727
use Facebook\FacebookRequest;
2828
use Facebook\GraphNodes\GraphEdge;
29+
use Facebook\GraphNodes\GraphNode;
2930

3031
class GraphEdgeTest extends \PHPUnit_Framework_TestCase
3132
{
@@ -96,4 +97,34 @@ public function testCanInstantiateNewPaginationRequest()
9697
$this->assertEquals('/v1337/998899/photos?access_token=foo_token&after=foo_after_cursor&appsecret_proof=857d5f035a894f16b4180f19966e055cdeab92d4d53017b13dccd6d43b6497af&foo=bar&limit=25&pretty=0', $nextPage->getUrl());
9798
$this->assertEquals('/v1337/998899/photos?access_token=foo_token&appsecret_proof=857d5f035a894f16b4180f19966e055cdeab92d4d53017b13dccd6d43b6497af&before=foo_before_cursor&foo=bar&limit=25&pretty=0', $prevPage->getUrl());
9899
}
100+
101+
public function testCanMapOverNodes()
102+
{
103+
$graphEdge = new GraphEdge(
104+
$this->request,
105+
[
106+
new GraphNode(['name' => 'dummy']),
107+
new GraphNode(['name' => 'dummy']),
108+
],
109+
['paging' => $this->pagination],
110+
'/1234567890/likes'
111+
);
112+
113+
$graphEdge = $graphEdge->map(function (GraphNode $node) {
114+
$node['name'] = str_replace('dummy', 'foo', $node['name']);
115+
return $node;
116+
});
117+
118+
$graphEdgeToCompare = new GraphEdge(
119+
$this->request,
120+
[
121+
new GraphNode(['name' => 'foo']),
122+
new GraphNode(['name' => 'foo'])
123+
],
124+
['paging' => $this->pagination],
125+
'/1234567890/likes'
126+
);
127+
128+
$this->assertEquals($graphEdgeToCompare, $graphEdge);
129+
}
99130
}

0 commit comments

Comments
 (0)