1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-10 23:24:02 +02:00
This commit is contained in:
Jordi Boggiano
2022-04-19 22:10:02 +02:00
parent e4bb5c5cf3
commit 2695fa86cd
85 changed files with 350 additions and 398 deletions

View File

@@ -54,12 +54,12 @@ class ChromePHPHandlerTest extends TestCase
public static function agentsProvider()
{
return array(
array('Monolog Test; Chrome/1.0'),
array('Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'),
array('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/56.0.2924.76 Chrome/56.0.2924.76 Safari/537.36'),
array('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome Safari/537.36'),
);
return [
['Monolog Test; Chrome/1.0'],
['Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:52.0) Gecko/20100101 Firefox/52.0'],
['Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/56.0.2924.76 Chrome/56.0.2924.76 Safari/537.36'],
['Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome Safari/537.36'],
];
}
public function testHeadersOverflow()

View File

@@ -70,7 +70,7 @@ class DynamoDbHandlerTest extends TestCase
$handler->setFormatter($formatter);
if ($this->isV3) {
$expFormatted = array('foo' => array('N' => 1), 'bar' => array('N' => 2));
$expFormatted = ['foo' => ['N' => 1], 'bar' => ['N' => 2]];
} else {
$expFormatted = $formatted;
}

View File

@@ -15,7 +15,6 @@ use Monolog\Formatter\ElasticaFormatter;
use Monolog\Formatter\NormalizerFormatter;
use Monolog\Test\TestCase;
use Monolog\Level;
use Monolog\LogRecord;
use Elastica\Client;
use Elastica\Request;
use Elastica\Response;

View File

@@ -178,8 +178,8 @@ class FilterHandlerTest extends TestCase
{
$test = new TestHandler();
$handler = new FilterHandler($test);
$handler->handleBatch(array());
$this->assertSame(array(), $test->getRecords());
$handler->handleBatch([]);
$this->assertSame([], $test->getRecords());
}
/**
@@ -202,6 +202,6 @@ class FilterHandlerTest extends TestCase
$this->assertFalse($test->hasInfoRecords());
$this->assertFalse($test->hasInfoRecords());
$this->assertSame(array(), $test->getRecords());
$this->assertSame([], $test->getRecords());
}
}

View File

@@ -55,10 +55,10 @@ class InsightOpsHandlerTest extends TestCase
private function createHandler()
{
$useSSL = extension_loaded('openssl');
$args = array('testToken', 'us', $useSSL, Level::Debug, true);
$args = ['testToken', 'us', $useSSL, Level::Debug, true];
$this->resource = fopen('php://memory', 'a');
$this->handler = $this->getMockBuilder(InsightOpsHandler::class)
->onlyMethods(array('fsockopen', 'streamSetTimeout', 'closeSocket'))
->onlyMethods(['fsockopen', 'streamSetTimeout', 'closeSocket'])
->setConstructorArgs($args)
->getMock();

View File

@@ -24,7 +24,7 @@ class PsrHandlerTest extends TestCase
public function logLevelProvider()
{
return array_map(
fn(Level $level) => [$level->toLevelName(), $level],
fn (Level $level) => [$level->toLevelName(), $level],
Level::cases()
);
}

View File

@@ -59,14 +59,14 @@ class RollbarHandlerTest extends TestCase
private function setupRollbarLoggerMock()
{
$config = array(
$config = [
'access_token' => 'ad865e76e7fb496fab096ac07b1dbabb',
'environment' => 'test',
);
];
$this->rollbarLogger = $this->getMockBuilder(RollbarLogger::class)
->setConstructorArgs(array($config))
->onlyMethods(array('log'))
->setConstructorArgs([$config])
->onlyMethods(['log'])
->getMock();
$this->rollbarLogger

View File

@@ -218,16 +218,16 @@ class RotatingFileHandlerTest extends TestCase
public function rotationWhenSimilarFilesExistTests()
{
return array(
return [
'Rotation is triggered when the file of the current day is not present but similar exists'
=> array(RotatingFileHandler::FILE_PER_DAY),
=> [RotatingFileHandler::FILE_PER_DAY],
'Rotation is triggered when the file of the current month is not present but similar exists'
=> array(RotatingFileHandler::FILE_PER_MONTH),
=> [RotatingFileHandler::FILE_PER_MONTH],
'Rotation is triggered when the file of the current year is not present but similar exists'
=> array(RotatingFileHandler::FILE_PER_YEAR),
);
=> [RotatingFileHandler::FILE_PER_YEAR],
];
}
public function testReuseCurrentFile()

View File

@@ -22,16 +22,16 @@ class SlackRecordTest extends TestCase
{
public function dataGetAttachmentColor()
{
return array(
array(Level::Debug, SlackRecord::COLOR_DEFAULT),
array(Level::Info, SlackRecord::COLOR_GOOD),
array(Level::Notice, SlackRecord::COLOR_GOOD),
array(Level::Warning, SlackRecord::COLOR_WARNING),
array(Level::Error, SlackRecord::COLOR_DANGER),
array(Level::Critical, SlackRecord::COLOR_DANGER),
array(Level::Alert, SlackRecord::COLOR_DANGER),
array(Level::Emergency, SlackRecord::COLOR_DANGER),
);
return [
[Level::Debug, SlackRecord::COLOR_DEFAULT],
[Level::Info, SlackRecord::COLOR_GOOD],
[Level::Notice, SlackRecord::COLOR_GOOD],
[Level::Warning, SlackRecord::COLOR_WARNING],
[Level::Error, SlackRecord::COLOR_DANGER],
[Level::Critical, SlackRecord::COLOR_DANGER],
[Level::Alert, SlackRecord::COLOR_DANGER],
[Level::Emergency, SlackRecord::COLOR_DANGER],
];
}
/**
@@ -70,16 +70,16 @@ class SlackRecordTest extends TestCase
*/
public function dataStringify()
{
$multipleDimensions = array(array(1, 2));
$numericKeys = array('library' => 'monolog');
$singleDimension = array(1, 'Hello', 'Jordi');
$multipleDimensions = [[1, 2]];
$numericKeys = ['library' => 'monolog'];
$singleDimension = [1, 'Hello', 'Jordi'];
return array(
array(array(), '[]'),
array($multipleDimensions, json_encode($multipleDimensions, JSON_PRETTY_PRINT)),
array($numericKeys, json_encode($numericKeys, JSON_PRETTY_PRINT)),
array($singleDimension, json_encode($singleDimension)),
);
return [
[[], '[]'],
[$multipleDimensions, json_encode($multipleDimensions, JSON_PRETTY_PRINT)],
[$numericKeys, json_encode($numericKeys, JSON_PRETTY_PRINT)],
[$singleDimension, json_encode($singleDimension)],
];
}
/**
@@ -179,7 +179,7 @@ class SlackRecordTest extends TestCase
}));
$message = 'Test message';
$record = new SlackRecord(null, null, false, null, false, false, array(), $formatter);
$record = new SlackRecord(null, null, false, null, false, false, [], $formatter);
$data = $record->getSlackData($this->getRecord(Level::Warning, $message));
$this->assertArrayHasKey('text', $data);
@@ -232,21 +232,21 @@ class SlackRecordTest extends TestCase
$level = Level::Error;
$levelName = LevelName::fromLevel($level)->value;
$record = new SlackRecord(null, null, true, null, true);
$data = $record->getSlackData($this->getRecord($level, 'test', array('test' => 1)));
$data = $record->getSlackData($this->getRecord($level, 'test', ['test' => 1]));
$attachment = $data['attachments'][0];
$this->assertArrayHasKey('title', $attachment);
$this->assertArrayHasKey('fields', $attachment);
$this->assertSame($levelName, $attachment['title']);
$this->assertSame(array(), $attachment['fields']);
$this->assertSame([], $attachment['fields']);
}
public function testAddsShortAttachmentWithContextAndExtra()
{
$level = Level::Error;
$levelName = LevelName::fromLevel($level)->value;
$context = array('test' => 1);
$extra = array('tags' => array('web'));
$context = ['test' => 1];
$extra = ['tags' => ['web']];
$record = new SlackRecord(null, null, true, null, true, true);
$loggerRecord = $this->getRecord($level, 'test', $context);
$loggerRecord['extra'] = $extra;
@@ -258,18 +258,18 @@ class SlackRecordTest extends TestCase
$this->assertCount(2, $attachment['fields']);
$this->assertSame($levelName, $attachment['title']);
$this->assertSame(
array(
array(
[
[
'title' => 'Extra',
'value' => sprintf('```%s```', json_encode($extra, JSON_PRETTY_PRINT)),
'short' => false,
),
array(
],
[
'title' => 'Context',
'value' => sprintf('```%s```', json_encode($context, JSON_PRETTY_PRINT)),
'short' => false,
),
),
],
],
$attachment['fields']
);
}
@@ -279,7 +279,7 @@ class SlackRecordTest extends TestCase
$level = Level::Error;
$levelName = LevelName::fromLevel($level)->value;
$record = new SlackRecord(null, null, true, null);
$data = $record->getSlackData($this->getRecord($level, 'test', array('test' => 1)));
$data = $record->getSlackData($this->getRecord($level, 'test', ['test' => 1]));
$attachment = $data['attachments'][0];
$this->assertArrayHasKey('title', $attachment);
@@ -287,11 +287,11 @@ class SlackRecordTest extends TestCase
$this->assertCount(1, $attachment['fields']);
$this->assertSame('Message', $attachment['title']);
$this->assertSame(
array(array(
[[
'title' => 'Level',
'value' => $levelName,
'short' => false,
)),
]],
$attachment['fields']
);
}
@@ -300,30 +300,30 @@ class SlackRecordTest extends TestCase
{
$level = Level::Error;
$levelName = LevelName::fromLevel($level)->value;
$context = array('test' => 1);
$extra = array('tags' => array('web'));
$context = ['test' => 1];
$extra = ['tags' => ['web']];
$record = new SlackRecord(null, null, true, null, false, true);
$loggerRecord = $this->getRecord($level, 'test', $context);
$loggerRecord['extra'] = $extra;
$data = $record->getSlackData($loggerRecord);
$expectedFields = array(
array(
$expectedFields = [
[
'title' => 'Level',
'value' => $levelName,
'short' => false,
),
array(
],
[
'title' => 'Tags',
'value' => sprintf('```%s```', json_encode($extra['tags'])),
'short' => false,
),
array(
],
[
'title' => 'Test',
'value' => $context['test'],
'short' => false,
),
);
],
];
$attachment = $data['attachments'][0];
$this->assertArrayHasKey('title', $attachment);
@@ -349,7 +349,7 @@ class SlackRecordTest extends TestCase
public function testContextHasException()
{
$record = $this->getRecord(Level::Critical, 'This is a critical message.', array('exception' => new \Exception()));
$record = $this->getRecord(Level::Critical, 'This is a critical message.', ['exception' => new \Exception()]);
$slackRecord = new SlackRecord(null, null, true, null, false, true);
$data = $slackRecord->getSlackData($record);
$this->assertIsString($data['attachments'][0]['fields'][1]['value']);
@@ -360,26 +360,26 @@ class SlackRecordTest extends TestCase
$record = $this->getRecord(
Level::Warning,
'test',
context: array('info' => array('library' => 'monolog', 'author' => 'Jordi')),
extra: array('tags' => array('web', 'cli')),
context: ['info' => ['library' => 'monolog', 'author' => 'Jordi']],
extra: ['tags' => ['web', 'cli']],
);
$slackRecord = new SlackRecord(null, null, true, null, false, true, array('context.info.library', 'extra.tags.1'));
$slackRecord = new SlackRecord(null, null, true, null, false, true, ['context.info.library', 'extra.tags.1']);
$data = $slackRecord->getSlackData($record);
$attachment = $data['attachments'][0];
$expected = array(
array(
$expected = [
[
'title' => 'Info',
'value' => sprintf('```%s```', json_encode(array('author' => 'Jordi'), JSON_PRETTY_PRINT)),
'value' => sprintf('```%s```', json_encode(['author' => 'Jordi'], JSON_PRETTY_PRINT)),
'short' => false,
),
array(
],
[
'title' => 'Tags',
'value' => sprintf('```%s```', json_encode(array('web'))),
'value' => sprintf('```%s```', json_encode(['web'])),
'short' => false,
),
);
],
];
foreach ($expected as $field) {
$this->assertNotFalse(array_search($field, $attachment['fields']));

View File

@@ -114,16 +114,16 @@ class SlackHandlerTest extends TestCase
public function provideLevelColors()
{
return array(
array(Level::Debug, urlencode(SlackRecord::COLOR_DEFAULT)),
array(Level::Info, SlackRecord::COLOR_GOOD),
array(Level::Notice, SlackRecord::COLOR_GOOD),
array(Level::Warning, SlackRecord::COLOR_WARNING),
array(Level::Error, SlackRecord::COLOR_DANGER),
array(Level::Critical, SlackRecord::COLOR_DANGER),
array(Level::Alert, SlackRecord::COLOR_DANGER),
array(Level::Emergency,SlackRecord::COLOR_DANGER),
);
return [
[Level::Debug, urlencode(SlackRecord::COLOR_DEFAULT)],
[Level::Info, SlackRecord::COLOR_GOOD],
[Level::Notice, SlackRecord::COLOR_GOOD],
[Level::Warning, SlackRecord::COLOR_WARNING],
[Level::Error, SlackRecord::COLOR_DANGER],
[Level::Critical, SlackRecord::COLOR_DANGER],
[Level::Alert, SlackRecord::COLOR_DANGER],
[Level::Emergency,SlackRecord::COLOR_DANGER],
];
}
private function createHandler($token = 'myToken', $channel = 'channel1', $username = 'Monolog', $useAttachment = true, $iconEmoji = null, $useShortAttachment = false, $includeExtra = false)

View File

@@ -36,27 +36,27 @@ class SlackWebhookHandlerTest extends TestCase
$record = $this->getRecord();
$slackRecord = $handler->getSlackRecord();
$this->assertInstanceOf('Monolog\Handler\Slack\SlackRecord', $slackRecord);
$this->assertEquals(array(
'attachments' => array(
array(
$this->assertEquals([
'attachments' => [
[
'fallback' => 'test',
'text' => 'test',
'color' => SlackRecord::COLOR_WARNING,
'fields' => array(
array(
'fields' => [
[
'title' => 'Level',
'value' => 'WARNING',
'short' => false,
),
),
],
],
'title' => 'Message',
'mrkdwn_in' => array('fields'),
'mrkdwn_in' => ['fields'],
'ts' => $record->datetime->getTimestamp(),
'footer' => null,
'footer_icon' => null,
),
),
), $slackRecord->getSlackData($record));
],
],
], $slackRecord->getSlackData($record));
}
/**
@@ -79,12 +79,12 @@ class SlackWebhookHandlerTest extends TestCase
$slackRecord = $handler->getSlackRecord();
$this->assertInstanceOf('Monolog\Handler\Slack\SlackRecord', $slackRecord);
$this->assertEquals(array(
$this->assertEquals([
'username' => 'test-username',
'text' => 'test',
'channel' => 'test-channel',
'icon_emoji' => ':ghost:',
), $slackRecord->getSlackData($this->getRecord()));
], $slackRecord->getSlackData($this->getRecord()));
}
/**
@@ -108,30 +108,30 @@ class SlackWebhookHandlerTest extends TestCase
$record = $this->getRecord();
$slackRecord = $handler->getSlackRecord();
$this->assertInstanceOf('Monolog\Handler\Slack\SlackRecord', $slackRecord);
$this->assertEquals(array(
$this->assertEquals([
'username' => 'test-username-with-attachment',
'channel' => 'test-channel-with-attachment',
'attachments' => array(
array(
'attachments' => [
[
'fallback' => 'test',
'text' => 'test',
'color' => SlackRecord::COLOR_WARNING,
'fields' => array(
array(
'fields' => [
[
'title' => 'Level',
'value' => LevelName::Warning->value,
'short' => false,
),
),
'mrkdwn_in' => array('fields'),
],
],
'mrkdwn_in' => ['fields'],
'ts' => $record['datetime']->getTimestamp(),
'footer' => 'test-username-with-attachment',
'footer_icon' => 'https://www.example.com/example.png',
'title' => 'Message',
),
),
],
],
'icon_url' => 'https://www.example.com/example.png',
), $slackRecord->getSlackData($record));
], $slackRecord->getSlackData($record));
}
/**

View File

@@ -128,7 +128,7 @@ class SocketHandlerTest extends TestCase
public function testExceptionIsThrownIfCannotSetChunkSize()
{
$this->setMockHandler(array('streamSetChunkSize'));
$this->setMockHandler(['streamSetChunkSize']);
$this->handler->setChunkSize(8192);
$this->handler->expects($this->once())
->method('streamSetChunkSize')

View File

@@ -11,7 +11,6 @@
namespace Monolog\Handler;
use Monolog\Handler\StreamHandler;
use Monolog\Test\TestCase;
use Monolog\Level;

View File

@@ -75,15 +75,15 @@ class SyslogUdpHandlerTest extends TestCase
$host = gethostname();
$handler = $this->getMockBuilder('\Monolog\Handler\SyslogUdpHandler')
->setConstructorArgs(array("127.0.0.1", 514, "authpriv", 'debug', true, "php", \Monolog\Handler\SyslogUdpHandler::RFC3164))
->setConstructorArgs(["127.0.0.1", 514, "authpriv", 'debug', true, "php", \Monolog\Handler\SyslogUdpHandler::RFC3164])
->onlyMethods([])
->getMock();
$handler->setFormatter(new \Monolog\Formatter\ChromePHPFormatter());
$socket = $this->getMockBuilder('\Monolog\Handler\SyslogUdp\UdpSocket')
->setConstructorArgs(array('lol', 999))
->onlyMethods(array('write'))
->setConstructorArgs(['lol', 999])
->onlyMethods(['write'])
->getMock();
$socket->expects($this->atLeast(2))
->method('write')

View File

@@ -32,8 +32,6 @@ class TelegramBotHandlerTest extends TestCase
}
/**
* @param string $apiKey
* @param string $channel
*/
private function createHandler(
string $apiKey = 'testKey',

View File

@@ -93,7 +93,7 @@ class WhatFailureGroupHandlerTest extends TestCase
*/
public function testHandleBatchUsesProcessors()
{
$testHandlers = array(new TestHandler(), new TestHandler());
$testHandlers = [new TestHandler(), new TestHandler()];
$handler = new WhatFailureGroupHandler($testHandlers);
$handler->pushProcessor(function ($record) {
$record->extra['foo'] = true;
@@ -105,7 +105,7 @@ class WhatFailureGroupHandlerTest extends TestCase
return $record;
});
$handler->handleBatch(array($this->getRecord(Level::Debug), $this->getRecord(Level::Info)));
$handler->handleBatch([$this->getRecord(Level::Debug), $this->getRecord(Level::Info)]);
foreach ($testHandlers as $test) {
$this->assertTrue($test->hasDebugRecords());
$this->assertTrue($test->hasInfoRecords());

View File

@@ -12,7 +12,6 @@
namespace Monolog\Handler;
use Monolog\Test\TestCase;
use Monolog\Level;
class ZendMonitorHandlerTest extends TestCase
{