Skip to content

Commit 09ed53b

Browse files
committed
Make uncastFields private
1 parent 54853d7 commit 09ed53b

File tree

2 files changed

+24
-42
lines changed

2 files changed

+24
-42
lines changed

src/GraphNode/GraphNode.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -199,25 +199,6 @@ public function __toString()
199199
return $this->asJson();
200200
}
201201

202-
/**
203-
* Uncasts any auto-casted datatypes.
204-
* Basically the reverse of castFields().
205-
*
206-
* @return array
207-
*/
208-
public function uncastFields()
209-
{
210-
$fields = $this->asArray();
211-
212-
return array_map(function ($v) {
213-
if ($v instanceof \DateTime) {
214-
return $v->format(\DateTime::ISO8601);
215-
}
216-
217-
return $v;
218-
}, $fields);
219-
}
220-
221202
/**
222203
* Casts a date value from Graph to DateTime.
223204
*
@@ -289,6 +270,25 @@ private function castFields(array $data)
289270
return $fields;
290271
}
291272

273+
/**
274+
* Uncasts any auto-casted datatypes.
275+
* Basically the reverse of castFields().
276+
*
277+
* @return array
278+
*/
279+
private function uncastFields()
280+
{
281+
$fields = $this->asArray();
282+
283+
return array_map(function ($v) {
284+
if ($v instanceof \DateTime) {
285+
return $v->format(\DateTime::ISO8601);
286+
}
287+
288+
return $v;
289+
}, $fields);
290+
}
291+
292292
/**
293293
* Determines if a value from Graph should be cast to DateTime.
294294
*

tests/GraphNode/GraphNodeTest.php

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -126,46 +126,28 @@ public function testAGraphDateStringCanBeConvertedToADateTimeObject()
126126
$this->assertEquals(1405395893, $timeStamp);
127127
}
128128

129-
public function testUncastingAGraphNodeWillUncastTheDateTimeObject()
130-
{
131-
$graphNodeOne = new GraphNode(['foo', 'bar']);
132-
$graphNodeTwo = new GraphNode([
133-
'id' => '123',
134-
'date' => new \DateTime('2014-07-15T03:44:53+0000'),
135-
'some_collection' => $graphNodeOne,
136-
]);
137-
138-
$uncastArray = $graphNodeTwo->uncastFields();
139-
140-
$this->assertEquals([
141-
'id' => '123',
142-
'date' => '2014-07-15T03:44:53+0000',
143-
'some_collection' => ['foo', 'bar'],
144-
], $uncastArray);
145-
}
146-
147129
public function testGettingGraphNodeAsAnArrayWillNotUncastTheDateTimeObject()
148130
{
149131
$graphNode = new GraphNode([
150132
'id' => '123',
151-
'date' => new \DateTime('2014-07-15T03:44:53+0000'),
133+
'created_time' => '2014-07-15T03:44:53+0000',
152134
]);
153135

154136
$graphNodeAsArray = $graphNode->asArray();
155137

156-
$this->assertInstanceOf(\DateTime::class, $graphNodeAsArray['date']);
138+
$this->assertInstanceOf(\DateTime::class, $graphNodeAsArray['created_time']);
157139
}
158140

159-
public function testReturningACollectionAsJasonWillSafelyRepresentDateTimes()
141+
public function testGettingAGraphNodeAsJSONWillSafelyRepresentDateTimes()
160142
{
161143
$graphNode = new GraphNode([
162144
'id' => '123',
163-
'date' => new \DateTime('2014-07-15T03:44:53+0000'),
145+
'created_time' => '2014-07-15T03:44:53+0000',
164146
]);
165147

166148
$graphNodeAsString = $graphNode->asJson();
167149

168-
$this->assertEquals('{"id":"123","date":"2014-07-15T03:44:53+0000"}', $graphNodeAsString);
150+
$this->assertEquals('{"id":"123","created_time":"2014-07-15T03:44:53+0000"}', $graphNodeAsString);
169151
}
170152

171153
public function testAnExistingPropertyCanBeAccessed()

0 commit comments

Comments
 (0)