forked from jadell/PHPBuiltinMock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuiltinMock_Mktime_UseTime.php
36 lines (34 loc) · 1.38 KB
/
BuiltinMock_Mktime_UseTime.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
/**
* Mock of the mktime() builtin
* Will always fill in all optional params with the current time() values if
* param is not specified.
* This allows mktime() to always use a mocked time() function instead
* of the real system time.
*/
class BuiltinMock_Mktime_UseTime extends BuiltinMock_Function
{
/////////////////////////////////////////////////////////////////////////////
// PUBLIC //////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
/**
* Return a timestamp built from the params
*
* @param integer $iHour if not given, will use date('H', time()) required=false
* @param integer $iMinute if not given, will use date('i', time()) required=false
* @param integer $iSecond if not given, will use date('s', time()) required=false
* @param integer $iMonth if not given, will use date('n', time()) required=false
* @param integer $iDay if not given, will use date('j', time()) required=false
* @param integer $iYear if not given, will use date('Y', time()) required=false
* @return integer
*/
public function mock($aArgs)
{
$aFormats = array('H', 'i', 's', 'n', 'j', 'Y');
foreach ($aFormats as $iArg => $sFormat) {
$aArgs[$iArg] = (isset($aArgs[$iArg])) ? $aArgs[$iArg] : date($sFormat, time());
}
return $this->callOriginal($aArgs);
}
}
?>