Skip to content

Commit

Permalink
Add timestamp() and microtime() to globals
Browse files Browse the repository at this point in the history
  • Loading branch information
nohponex committed Jan 20, 2016
1 parent 9787b43 commit 0c7b639
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/Globals.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ protected static function initializeGlobals()
static::$globals->{'rand-boolean'} = function () {
return (boolean)rand(0, 1);
};

static::$globals->{'timestamp'} = function () {
return time();
};

static::$globals->{'microtime'} = function ($get_as_float = false) {
return microtime((bool)$get_as_float);
};
}

/**
Expand Down Expand Up @@ -108,8 +116,8 @@ public static function exists($key)
*
* Globals::get('myArray[1]'); //Get second array element
* ```
* @throws Exception When expression key is invalid.
* @throws Phramework\Exceptions\NotFoundException When key is not found.
* @throws \Exception When expression key is invalid.
* @throws \Phramework\Exceptions\NotFoundException When key is not found.
*/
public static function get($key = null, $operators = null)
{
Expand Down Expand Up @@ -178,7 +186,7 @@ public static function get($key = null, $operators = null)
* Globals::get('dots()'); //Will return a string of 4 dots
* Globals::get('dots(10)'); //Will return a string of 10 dots
* ```
* @throws Exception When key is invalid, *see Expression::PATTERN_KEY*
* @throws \Exception When key is invalid, *see Expression::PATTERN_KEY*
*/
public static function set($key, $value)
{
Expand All @@ -202,7 +210,6 @@ public static function toString()
$return = [];

foreach (static::$globals as $key => $value) {
$valueString = '';
$type = gettype($value);

if (is_callable($value)) {
Expand Down
23 changes: 23 additions & 0 deletions tests/src/GlobalsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,29 @@ public function testGetRandInteger()
);
}

/**
* @covers Phramework\Testphase\Globals::get
*
*/
public function testGetTimestamp()
{
$return = Globals::get('timestamp');

$this->assertInternalType(
'callable',
$return,
'Expect to return a function'
);

$return = Globals::get('timestamp()');

$this->assertInternalType(
'integer',
$return,
'Expect to return integer'
);
}

/**
* @covers Phramework\Testphase\Globals::exists
*/
Expand Down

0 comments on commit 0c7b639

Please sign in to comment.