Skip to content

Commit 28af55b

Browse files
committed
Make castToDateTime and castToBirthday private
1 parent 09ed53b commit 28af55b

File tree

2 files changed

+38
-58
lines changed

2 files changed

+38
-58
lines changed

src/GraphNode/GraphNode.php

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

202-
/**
203-
* Casts a date value from Graph to DateTime.
204-
*
205-
* @param int|string $value
206-
*
207-
* @return \DateTime
208-
*/
209-
public function castToDateTime($value)
210-
{
211-
if (is_int($value)) {
212-
$dt = new \DateTime();
213-
$dt->setTimestamp($value);
214-
} else {
215-
$dt = new \DateTime($value);
216-
}
217-
218-
return $dt;
219-
}
220-
221-
/**
222-
* Casts a birthday value from Graph to Birthday.
223-
*
224-
* @param string $value
225-
*
226-
* @return Birthday
227-
*/
228-
public function castToBirthday($value)
229-
{
230-
return new Birthday($value);
231-
}
232-
233202
/**
234203
* Getter for $graphNodeMap.
235204
*
@@ -337,4 +306,35 @@ private function isIso8601DateString($string)
337306

338307
return preg_match($crazyInsaneRegexThatSomehowDetectsIso8601, $string) === 1;
339308
}
309+
310+
/**
311+
* Casts a date value from Graph to DateTime.
312+
*
313+
* @param int|string $value
314+
*
315+
* @return \DateTime
316+
*/
317+
private function castToDateTime($value)
318+
{
319+
if (is_int($value)) {
320+
$dt = new \DateTime();
321+
$dt->setTimestamp($value);
322+
} else {
323+
$dt = new \DateTime($value);
324+
}
325+
326+
return $dt;
327+
}
328+
329+
/**
330+
* Casts a birthday value from Graph to Birthday.
331+
*
332+
* @param string $value
333+
*
334+
* @return Birthday
335+
*/
336+
private function castToBirthday($value)
337+
{
338+
return new Birthday($value);
339+
}
340340
}

tests/GraphNode/GraphNodeTest.php

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,25 @@ public static function provideDateTimeFieldNames()
6969
/**
7070
* @dataProvider provideValidDateTimeFieldValues
7171
*/
72-
public function testIsCastDateTimeFieldValueToDateTime($value, $message)
72+
public function testIsCastDateTimeFieldValueToDateTime($value, $message, $prettyDate = null)
7373
{
7474
$graphNode = new GraphNode(['created_time' => $value]);
7575

7676
$this->assertInstanceOf(\DateTime::class, $graphNode->getField('created_time'), $message);
77+
78+
if ($prettyDate !== null) {
79+
$this->assertEquals($prettyDate, $graphNode->getField('created_time')->format(\DateTime::RFC1036));
80+
}
7781
}
7882

7983
public static function provideValidDateTimeFieldValues()
8084
{
8185
yield ['1985-10-26T01:21:00+0000', 'Expected the valid ISO 8601 formatted date from Back To The Future to pass.'];
86+
yield ['2014-07-15T03:44:53+0000', 'Expected the valid ISO 8601 formatted date to pass.', 'Tue, 15 Jul 14 03:44:53 +0000'];
8287
yield ['1999-12-31', 'Expected the valid ISO 8601 formatted date to party like it\'s 1999.'];
8388
yield ['2009-05-19T14:39Z', 'Expected the valid ISO 8601 formatted date to pass.'];
8489
yield ['2014-W36', 'Expected the valid ISO 8601 formatted date to pass.'];
90+
yield [1405547020, 'Expected the valid timestamp to pass.', 'Wed, 16 Jul 14 23:43:40 +0200'];
8591
}
8692

8793
/**
@@ -100,32 +106,6 @@ public static function provideInvalidDateTimeFieldValues()
100106
yield ['foo_time', 'Expected the invalid ISO 8601 format to fail.'];
101107
}
102108

103-
public function testATimeStampCanBeConvertedToADateTimeObject()
104-
{
105-
$someTimeStampFromGraph = 1405547020;
106-
$graphNode = new GraphNode();
107-
$dateTime = $graphNode->castToDateTime($someTimeStampFromGraph);
108-
$prettyDate = $dateTime->format(\DateTime::RFC1036);
109-
$timeStamp = $dateTime->getTimestamp();
110-
111-
$this->assertInstanceOf(\DateTime::class, $dateTime);
112-
$this->assertEquals('Wed, 16 Jul 14 23:43:40 +0200', $prettyDate);
113-
$this->assertEquals(1405547020, $timeStamp);
114-
}
115-
116-
public function testAGraphDateStringCanBeConvertedToADateTimeObject()
117-
{
118-
$someDateStringFromGraph = '2014-07-15T03:44:53+0000';
119-
$graphNode = new GraphNode();
120-
$dateTime = $graphNode->castToDateTime($someDateStringFromGraph);
121-
$prettyDate = $dateTime->format(\DateTime::RFC1036);
122-
$timeStamp = $dateTime->getTimestamp();
123-
124-
$this->assertInstanceOf(\DateTime::class, $dateTime);
125-
$this->assertEquals('Tue, 15 Jul 14 03:44:53 +0000', $prettyDate);
126-
$this->assertEquals(1405395893, $timeStamp);
127-
}
128-
129109
public function testGettingGraphNodeAsAnArrayWillNotUncastTheDateTimeObject()
130110
{
131111
$graphNode = new GraphNode([

0 commit comments

Comments
 (0)