32 $dir = __DIR__.
'/Fixtures';
34 if (!is_writable($dir)) {
35 $this->markTestSkipped($dir.
' must be writable to test the RotatingFileHandler.');
37 $this->lastError = null;
41 $self->lastError =
array(
50 if (empty($this->lastError)) {
53 'Failed asserting that error with code `%d` and message `%s` was triggered',
59 $this->assertEquals(
$code, $this->lastError[
'code'], sprintf(
'Expected an error with code %d to be triggered, got `%s` instead',
$code, $this->lastError[
'code']));
60 $this->assertEquals(
$message, $this->lastError[
'message'], sprintf(
'Expected an error with message `%d` to be triggered, got `%s` instead',
$message, $this->lastError[
'message']));
65 touch(__DIR__.
'/Fixtures/foo-'.
date(
'Y-m-d',
time() - 86400).
'.rot');
71 $log = __DIR__.
'/Fixtures/foo-'.
date(
'Y-m-d').
'.rot';
72 $this->assertTrue(file_exists(
$log));
73 $this->assertEquals(
'test', file_get_contents(
$log));
79 public function testRotation($createFile, $dateFormat, $timeCallback)
81 touch($old1 = __DIR__.
'/Fixtures/foo-'.
date($dateFormat, $timeCallback(-1)).
'.rot');
82 touch($old2 = __DIR__.
'/Fixtures/foo-'.
date($dateFormat, $timeCallback(-2)).
'.rot');
83 touch($old3 = __DIR__.
'/Fixtures/foo-'.
date($dateFormat, $timeCallback(-3)).
'.rot');
84 touch($old4 = __DIR__.
'/Fixtures/foo-'.
date($dateFormat, $timeCallback(-4)).
'.rot');
86 $log = __DIR__.
'/Fixtures/foo-'.
date($dateFormat).
'.rot';
94 $handler->setFilenameFormat(
'{filename}-{date}', $dateFormat);
99 $this->assertTrue(file_exists(
$log));
100 $this->assertTrue(file_exists($old1));
101 $this->assertEquals($createFile, file_exists($old2));
102 $this->assertEquals($createFile, file_exists($old3));
103 $this->assertEquals($createFile, file_exists($old4));
104 $this->assertEquals(
'test', file_get_contents(
$log));
110 $dayCallback =
function($ago) use ($now) {
111 return $now + 86400 * $ago;
113 $monthCallback =
function($ago) {
114 return gmmktime(0, 0, 0,
date(
'n') + $ago,
date(
'd'),
date(
'Y'));
116 $yearCallback =
function($ago) {
117 return gmmktime(0, 0, 0,
date(
'n'),
date(
'd'),
date(
'Y') + $ago);
121 'Rotation is triggered when the file of the current day is not present' 123 'Rotation is not triggered when the file of the current day is already present' 126 'Rotation is triggered when the file of the current month is not present' 128 'Rotation is not triggered when the file of the current month is already present' 131 'Rotation is triggered when the file of the current year is not present' 133 'Rotation is not triggered when the file of the current year is already present' 144 $handler->setFilenameFormat(
'{filename}-{date}', $dateFormat);
148 'Invalid date format - format must be one of RotatingFileHandler::FILE_PER_DAY ("Y-m-d"), '.
149 'RotatingFileHandler::FILE_PER_MONTH ("Y-m") or RotatingFileHandler::FILE_PER_YEAR ("Y"), '.
150 'or you can set one of the date formats using slashes, underscores and/or dots instead of dashes.' 161 array(
'm-d-Y',
false),
162 array(
'Y-m-d-h-i',
false)
176 'Invalid filename format - format should contain at least `{date}`, because otherwise rotating is impossible.' 184 array(
'{filename}',
false),
185 array(
'{filename}-{date}',
true),
186 array(
'{date}',
true),
187 array(
'foobar-{date}',
true),
188 array(
'foo-{date}-bar',
true),
189 array(
'{date}-foobar',
true),
190 array(
'foobar',
false),
196 $log = __DIR__.
'/Fixtures/foo-'.
date(
'Y-m-d').
'.rot';
197 file_put_contents(
$log,
"foo");
201 $this->assertEquals(
'footest', file_get_contents(
$log));
206 foreach (glob(__DIR__.
'/Fixtures/*.rot') as
$file) {
209 restore_error_handler();
testDisallowFilenameFormatsWithoutDate($filenameFormat, $valid)
filenameFormatProvider
testRotation($createFile, $dateFormat, $timeCallback)
rotationTests
testRotationCreatesNewFile()
$lastError
This var should be private but then the anonymous function in the setUp method won't be able to set i...
Stores logs to files that are rotated every day and a limited number of files are kept...
getRecord($level=Logger::WARNING, $message='test', $context=array())
testAllowOnlyFixedDefinedDateFormats($dateFormat, $valid)
dateFormatProvider
catch(Exception $e) $message
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
Create styles array
The data for the language used.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
assertErrorWasTriggered($code, $message)