mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-30 08:21:05 +02:00
Merge branch '1.x'
This commit is contained in:
@@ -131,22 +131,22 @@ class JsonFormatterTest extends TestCase
|
||||
$message = $this->formatRecordWithExceptionInContext($formatter, $throwable);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"...":"Over 0 items, aborting normalization"}'."\n",
|
||||
'{"...":"Over 0 items (6 total), aborting normalization"}'."\n",
|
||||
$message
|
||||
);
|
||||
}
|
||||
|
||||
public function testMaxNormalizeItemCountWith3ItemsMax()
|
||||
public function testMaxNormalizeItemCountWith2ItemsMax()
|
||||
{
|
||||
$formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_JSON, true);
|
||||
$formatter->setMaxNormalizeDepth(9);
|
||||
$formatter->setMaxNormalizeItemCount(3);
|
||||
$formatter->setMaxNormalizeItemCount(2);
|
||||
$throwable = new \Error('Foo');
|
||||
|
||||
$message = $this->formatRecordWithExceptionInContext($formatter, $throwable);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"level_name":"CRITICAL","channel":"core","...":"Over 3 items, aborting normalization"}'."\n",
|
||||
'{"level_name":"CRITICAL","channel":"core","...":"Over 2 items (6 total), aborting normalization"}'."\n",
|
||||
$message
|
||||
);
|
||||
}
|
||||
@@ -217,4 +217,40 @@ class JsonFormatterTest extends TestCase
|
||||
|
||||
return $formattedException;
|
||||
}
|
||||
|
||||
public function testNormalizeHandleLargeArraysWithExactly1000Items()
|
||||
{
|
||||
$formatter = new NormalizerFormatter();
|
||||
$largeArray = range(1, 1000);
|
||||
|
||||
$res = $formatter->format(array(
|
||||
'level_name' => 'CRITICAL',
|
||||
'channel' => 'test',
|
||||
'message' => 'bar',
|
||||
'context' => array($largeArray),
|
||||
'datetime' => new \DateTime,
|
||||
'extra' => array(),
|
||||
));
|
||||
|
||||
$this->assertCount(1000, $res['context'][0]);
|
||||
$this->assertArrayNotHasKey('...', $res['context'][0]);
|
||||
}
|
||||
|
||||
public function testNormalizeHandleLargeArrays()
|
||||
{
|
||||
$formatter = new NormalizerFormatter();
|
||||
$largeArray = range(1, 2000);
|
||||
|
||||
$res = $formatter->format(array(
|
||||
'level_name' => 'CRITICAL',
|
||||
'channel' => 'test',
|
||||
'message' => 'bar',
|
||||
'context' => array($largeArray),
|
||||
'datetime' => new \DateTime,
|
||||
'extra' => array(),
|
||||
));
|
||||
|
||||
$this->assertCount(1001, $res['context'][0]);
|
||||
$this->assertEquals('Over 1000 items (2000 total), aborting normalization', $res['context'][0]['...']);
|
||||
}
|
||||
}
|
||||
|
@@ -227,6 +227,24 @@ class NormalizerFormatterTest extends \PHPUnit\Framework\TestCase
|
||||
$this->assertEquals(@json_encode([$resource]), $res);
|
||||
}
|
||||
|
||||
public function testNormalizeHandleLargeArraysWithExactly1000Items()
|
||||
{
|
||||
$formatter = new NormalizerFormatter();
|
||||
$largeArray = range(1, 1000);
|
||||
|
||||
$res = $formatter->format(array(
|
||||
'level_name' => 'CRITICAL',
|
||||
'channel' => 'test',
|
||||
'message' => 'bar',
|
||||
'context' => array($largeArray),
|
||||
'datetime' => new \DateTime,
|
||||
'extra' => array(),
|
||||
));
|
||||
|
||||
$this->assertCount(1000, $res['context'][0]);
|
||||
$this->assertArrayNotHasKey('...', $res['context'][0]);
|
||||
}
|
||||
|
||||
public function testNormalizeHandleLargeArrays()
|
||||
{
|
||||
$formatter = new NormalizerFormatter();
|
||||
@@ -241,7 +259,7 @@ class NormalizerFormatterTest extends \PHPUnit\Framework\TestCase
|
||||
'extra' => array(),
|
||||
));
|
||||
|
||||
$this->assertCount(1000, $res['context'][0]);
|
||||
$this->assertCount(1001, $res['context'][0]);
|
||||
$this->assertEquals('Over 1000 items (2000 total), aborting normalization', $res['context'][0]['...']);
|
||||
}
|
||||
|
||||
|
@@ -195,6 +195,40 @@ class RotatingFileHandlerTest extends TestCase
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider rotationWhenSimilarFilesExistTests
|
||||
*/
|
||||
public function testRotationWhenSimilarFileNamesExist($dateFormat)
|
||||
{
|
||||
touch($old1 = __DIR__.'/Fixtures/foo-foo-'.date($dateFormat).'.rot');
|
||||
touch($old2 = __DIR__.'/Fixtures/foo-bar-'.date($dateFormat).'.rot');
|
||||
|
||||
$log = __DIR__.'/Fixtures/foo-'.date($dateFormat).'.rot';
|
||||
|
||||
$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));
|
||||
}
|
||||
|
||||
public function rotationWhenSimilarFilesExistTests()
|
||||
{
|
||||
|
||||
return [
|
||||
'Rotation is triggered when the file of the current day is not present but similar exists'
|
||||
=> [RotatingFileHandler::FILE_PER_DAY],
|
||||
|
||||
'Rotation is triggered when the file of the current month is not present but similar exists'
|
||||
=> [RotatingFileHandler::FILE_PER_MONTH],
|
||||
|
||||
'Rotation is triggered when the file of the current year is not present but similar exists'
|
||||
=> [RotatingFileHandler::FILE_PER_YEAR],
|
||||
];
|
||||
}
|
||||
|
||||
public function testReuseCurrentFile()
|
||||
{
|
||||
$log = __DIR__.'/Fixtures/foo-'.date('Y-m-d').'.rot';
|
||||
|
Reference in New Issue
Block a user