-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove strftime (deprecated in php 8.1)
Add possibility to configure timeFormatter add test
- Loading branch information
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
--TEST-- | ||
Log: Time Format | ||
--INI-- | ||
date.timezone=UTC | ||
--FILE-- | ||
<?php | ||
|
||
require_once 'Log.php'; | ||
|
||
set_error_handler(function ($errno, $errstr, $errfile, $errline) { | ||
echo $errstr . PHP_EOL; | ||
}, E_USER_NOTICE|E_USER_WARNING); | ||
|
||
$tests = array( | ||
array('timeFormat' => 'Y-m-d H:i:s', 'timeFormatter' => null, 'expectedResult' => '2024-01-07 20:17:28'), | ||
array('timeFormat' => 'H:i:s', 'timeFormatter' => null, 'expectedResult' => '20:17:28'), | ||
array('timeFormat' => '%b %d %H:%M:%S', 'timeFormatter' => null, 'expectedResult' => 'Jan 07 20:17:28'), | ||
array('timeFormat' => '%O %d %a %e %A %u %w %j', 'timeFormatter' => null, 'expectedResult' => 'th 07 Sun 7 Sunday 7 0 6'), | ||
array('timeFormat' => '%V', 'timeFormatter' => null, 'expectedResult' => '01'), | ||
array('timeFormat' => '%B %m %b %-m', 'timeFormatter' => null, 'expectedResult' => 'January 01 Jan 1'), | ||
array('timeFormat' => '%G %Y %y', 'timeFormatter' => null, 'expectedResult' => '2024 2024 24'), | ||
array('timeFormat' => '%P %p %l %I %H %M %S', 'timeFormatter' => null, 'expectedResult' => 'pm PM 8 08 20 17 28'), | ||
array('timeFormat' => '%z %Z', 'timeFormatter' => null, 'expectedResult' => '+0000 UTC'), | ||
array('timeFormat' => '%s', 'timeFormatter' => null, 'expectedResult' => '1704658648'), | ||
array('timeFormat' => 'Y-m-d H:i:s', 'timeFormatter' => function($timeFormat, $time) { return $time;}, 'expectedResult' => '1704658648'), | ||
array('timeFormat' => 'Y-m-d H:i:s', 'timeFormatter' => function($timeFormat, $time) { return $timeFormat;}, 'expectedResult' => 'Y-m-d H:i:s'), | ||
); | ||
|
||
foreach ($tests as $config) { | ||
$config['lineFormat'] = '%1$s'; | ||
$logger = Log::factory('display', '', '', $config); | ||
$reflection = new ReflectionObject($logger); | ||
$reflectionMethod = $reflection->getMethod('formatTime'); | ||
$reflectionMethod->setAccessible(true); | ||
$result = $reflectionMethod->invoke($logger, 1704658648, $config['timeFormat'], $config['timeFormatter']); | ||
echo $result . ' ' . ($result == $config['expectedResult'] ? 'OK' : 'FAIL') . PHP_EOL; | ||
} | ||
|
||
--EXPECT-- | ||
2024-01-07 20:17:28 OK | ||
20:17:28 OK | ||
Using strftime-style formatting is deprecated | ||
Jan 07 20:17:28 OK | ||
Using strftime-style formatting is deprecated | ||
th 07 Sun 7 Sunday 7 0 6 OK | ||
Using strftime-style formatting is deprecated | ||
01 OK | ||
Using strftime-style formatting is deprecated | ||
January 01 Jan 1 OK | ||
Using strftime-style formatting is deprecated | ||
2024 2024 24 OK | ||
Using strftime-style formatting is deprecated | ||
pm PM 8 08 20 17 28 OK | ||
Using strftime-style formatting is deprecated | ||
+0000 UTC OK | ||
Using strftime-style formatting is deprecated | ||
1704658648 OK | ||
1704658648 OK | ||
Y-m-d H:i:s OK |