Skip to content

Commit 1355b82

Browse files
committed
Fix map implementation in GraphEdge class.
1 parent 73b8b44 commit 1355b82

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-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+
* @{inherited}
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: 25 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,28 @@ 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+
[new GraphNode(['name' => 'dummy'])],
106+
['paging' => $this->pagination],
107+
'/1234567890/likes'
108+
);
109+
110+
$graphEdge = $graphEdge->map(function (GraphNode $node) {
111+
$node['name'] = str_replace('dummy', 'foo', $node['name']);
112+
return $node;
113+
});
114+
115+
$graphEdgeToCompare = new GraphEdge(
116+
$this->request,
117+
[new GraphNode(['name' => 'foo'])],
118+
['paging' => $this->pagination],
119+
'/1234567890/likes'
120+
);
121+
122+
$this->assertEquals($graphEdgeToCompare, $graphEdge);
123+
}
99124
}

0 commit comments

Comments
 (0)