diff --git a/src/GraphNode/GraphNode.php b/src/GraphNode/GraphNode.php index 8f4ff35dd..e89553af5 100644 --- a/src/GraphNode/GraphNode.php +++ b/src/GraphNode/GraphNode.php @@ -275,28 +275,6 @@ public function isIso8601DateString($string) return preg_match($crazyInsaneRegexThatSomehowDetectsIso8601, $string) === 1; } - /** - * Determines if a value from Graph should be cast to DateTime. - * - * @param string $key - * - * @return bool - */ - public function shouldCastAsDateTime($key) - { - return in_array($key, [ - 'created_time', - 'updated_time', - 'start_time', - 'stop_time', - 'end_time', - 'backdated_time', - 'issued_at', - 'expires_at', - 'publish_time' - ], true); - } - /** * Casts a date value from Graph to DateTime. * @@ -337,4 +315,26 @@ public static function getNodeMap() { return static::$graphNodeMap; } + + /** + * Determines if a value from Graph should be cast to DateTime. + * + * @param string $key + * + * @return bool + */ + private function shouldCastAsDateTime($key) + { + return in_array($key, [ + 'created_time', + 'updated_time', + 'start_time', + 'stop_time', + 'end_time', + 'backdated_time', + 'issued_at', + 'expires_at', + 'publish_time' + ], true); + } } diff --git a/tests/GraphNode/GraphNodeTest.php b/tests/GraphNode/GraphNodeTest.php index 84f8c8c9d..713179844 100644 --- a/tests/GraphNode/GraphNodeTest.php +++ b/tests/GraphNode/GraphNodeTest.php @@ -43,6 +43,29 @@ public function testAGraphNodeCanInstantiateWithData() $this->assertEquals(['foo' => 'bar'], $backingData); } + /** + * @dataProvider provideDateTimeFieldNames + */ + public function testIsCastDateTimeFieldsToDateTime($fieldName) + { + $graphNode = new GraphNode([$fieldName => '1989-11-02']); + + $this->assertInstanceOf(\DateTime::class, $graphNode->getField($fieldName)); + } + + public static function provideDateTimeFieldNames() + { + yield ['created_time']; + yield ['updated_time']; + yield ['start_time']; + yield ['stop_time']; + yield ['end_time']; + yield ['backdated_time']; + yield ['issued_at']; + yield ['expires_at']; + yield ['publish_time']; + } + public function testDatesThatShouldBeCastAsDateTimeObjectsAreDetected() { $graphNode = new GraphNode();