Skip to content

Commit

Permalink
Make shouldCastAsDateTime private
Browse files Browse the repository at this point in the history
  • Loading branch information
yguedidi committed Dec 19, 2017
1 parent 61272c3 commit 11529c4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/GraphNode/GraphNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
}
}
23 changes: 23 additions & 0 deletions tests/GraphNode/GraphNodeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 11529c4

Please sign in to comment.