/** * @dataProvider rotationTests */ public function testRotation($createFile) { 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($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'); $log = __DIR__ . '/Fixtures/foo-' . date('Y-m-d') . '.rot'; if ($createFile) { touch($log); } $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->assertEquals($createFile, file_exists($old2)); $this->assertEquals($createFile, file_exists($old3)); $this->assertEquals($createFile, file_exists($old4)); $this->assertEquals('test', file_get_contents($log)); }
/** * @dataProvider rotationTests */ public function testRotation($createFile) { 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($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'); $log = __DIR__ . '/Fixtures/foo-' . date('Y-m-d') . '.rot'; if ($createFile) { touch($log); } $handler = new RotatingFileHandler(__DIR__ . '/Fixtures/foo.rot', 2); $handler->setFormatter($this->getIdentityFormatter()); $handler->handle($this->getRecord()); $handler->close(); $this->assertTrue(file_exists($log)); $this->assertTrue(file_exists($old1)); $this->assertEquals($createFile, file_exists($old2)); $this->assertEquals($createFile, file_exists($old3)); $this->assertEquals($createFile, file_exists($old4)); $this->assertEquals('test', file_get_contents($log)); }
/** * @dataProvider rotationTests */ public function testRotation($createFile, $dateFormat, $timeCallback) { touch($old1 = __DIR__ . '/Fixtures/foo-' . date($dateFormat, $timeCallback(-1)) . '.rot'); touch($old2 = __DIR__ . '/Fixtures/foo-' . date($dateFormat, $timeCallback(-2)) . '.rot'); touch($old3 = __DIR__ . '/Fixtures/foo-' . date($dateFormat, $timeCallback(-3)) . '.rot'); touch($old4 = __DIR__ . '/Fixtures/foo-' . date($dateFormat, $timeCallback(-4)) . '.rot'); $log = __DIR__ . '/Fixtures/foo-' . date($dateFormat) . '.rot'; if ($createFile) { touch($log); } $handler = new RotatingFileHandler(__DIR__ . '/Fixtures/foo.rot', 2); $handler->setFormatter($this->getIdentityFormatter()); $handler->setFilenameFormat('{filename}-{date}', $dateFormat); $handler->handle($this->getRecord()); $handler->close(); $this->assertTrue(file_exists($log)); $this->assertTrue(file_exists($old1)); $this->assertEquals($createFile, file_exists($old2)); $this->assertEquals($createFile, file_exists($old3)); $this->assertEquals($createFile, file_exists($old4)); $this->assertEquals('test', file_get_contents($log)); }