mirror of
https://github.com/Seldaek/monolog.git
synced 2025-07-16 19:16:27 +02:00
Merge similar tests together
This commit is contained in:
@ -36,47 +36,43 @@ class RotatingFileHandlerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('test', file_get_contents($log));
|
$this->assertEquals('test', file_get_contents($log));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRotationDeletesOldFiles()
|
/**
|
||||||
|
* @dataProvider rotationTests
|
||||||
|
*/
|
||||||
|
public function testRotation($createFile)
|
||||||
{
|
{
|
||||||
touch($old1 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400).'.rot');
|
touch($old1 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400).'.rot');
|
||||||
touch($old2 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400 * 2).'.rot');
|
touch($old2 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400 * 2).'.rot');
|
||||||
touch($old3 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400 * 3).'.rot');
|
touch($old3 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400 * 3).'.rot');
|
||||||
touch($old4 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400 * 4).'.rot');
|
touch($old4 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400 * 4).'.rot');
|
||||||
|
|
||||||
|
$log = __DIR__.'/Fixtures/foo-'.date('Y-m-d').'.rot';
|
||||||
|
|
||||||
|
if ($createFile) {
|
||||||
|
touch($log);
|
||||||
|
}
|
||||||
|
|
||||||
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2);
|
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2);
|
||||||
$handler->write(array('message' => 'test'));
|
$handler->write(array('message' => 'test'));
|
||||||
$log = __DIR__.'/Fixtures/foo-'.date('Y-m-d').'.rot';
|
|
||||||
|
|
||||||
$handler->close();
|
$handler->close();
|
||||||
|
|
||||||
$this->assertTrue(file_exists($log));
|
$this->assertTrue(file_exists($log));
|
||||||
$this->assertTrue(file_exists($old1));
|
$this->assertTrue(file_exists($old1));
|
||||||
$this->assertFalse(file_exists($old2));
|
$this->assertEquals($createFile, file_exists($old2));
|
||||||
$this->assertFalse(file_exists($old3));
|
$this->assertEquals($createFile, file_exists($old3));
|
||||||
$this->assertFalse(file_exists($old4));
|
$this->assertEquals($createFile, file_exists($old4));
|
||||||
$this->assertEquals('test', file_get_contents($log));
|
$this->assertEquals('test', file_get_contents($log));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testRotationNotTriggeredTwiceTheSameDay()
|
public function rotationTests()
|
||||||
{
|
{
|
||||||
touch($old1 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400).'.rot');
|
return array(
|
||||||
touch($old2 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400 * 2).'.rot');
|
'Rotation is triggered when the file of the current day is not present'
|
||||||
touch($old3 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400 * 3).'.rot');
|
=> array(true),
|
||||||
touch($old4 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400 * 4).'.rot');
|
'Rotation is not triggered when the file is already present'
|
||||||
$log = __DIR__.'/Fixtures/foo-'.date('Y-m-d').'.rot';
|
=> array(false),
|
||||||
file_put_contents($log, 'test');
|
);
|
||||||
|
|
||||||
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2);
|
|
||||||
$handler->write(array('message' => 'test'));
|
|
||||||
|
|
||||||
$handler->close();
|
|
||||||
|
|
||||||
$this->assertTrue(file_exists($log));
|
|
||||||
$this->assertTrue(file_exists($old1));
|
|
||||||
$this->assertTrue(file_exists($old2));
|
|
||||||
$this->assertTrue(file_exists($old3));
|
|
||||||
$this->assertTrue(file_exists($old4));
|
|
||||||
$this->assertEquals('testtest', file_get_contents($log));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReuseCurrentFile()
|
public function testReuseCurrentFile()
|
||||||
|
Reference in New Issue
Block a user