1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-26 22:44:29 +02:00

Code cleanups

This commit is contained in:
Jordi Boggiano
2022-03-05 14:03:57 +01:00
parent b586dbe8e6
commit 5eb9b8ed93
109 changed files with 418 additions and 549 deletions

View File

@@ -43,7 +43,7 @@ class JsonFormatterTest extends TestCase
$formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_JSON, false);
$record = $this->getRecord();
$this->assertEquals('{"message":"test","context":{},"level":300,"level_name":"WARNING","channel":"test","datetime":"'.$record['datetime']->format('Y-m-d\TH:i:s.uP').'","extra":{}}', $formatter->format($record));
$this->assertEquals('{"message":"test","context":{},"level":300,"level_name":"WARNING","channel":"test","datetime":"'.$record->datetime->format('Y-m-d\TH:i:s.uP').'","extra":{}}', $formatter->format($record));
}
/**
@@ -66,7 +66,7 @@ class JsonFormatterTest extends TestCase
"level": 300,
"level_name": "WARNING",
"channel": "test",
"datetime": "'.$record['datetime']->format('Y-m-d\TH:i:s.uP').'",
"datetime": "'.$record->datetime->format('Y-m-d\TH:i:s.uP').'",
"extra": {}
}',
$formatter->format($record)
@@ -74,7 +74,7 @@ class JsonFormatterTest extends TestCase
$formatter->setJsonPrettyPrint(false);
$record = $this->getRecord();
$this->assertEquals('{"message":"test","context":{},"level":300,"level_name":"WARNING","channel":"test","datetime":"'.$record['datetime']->format('Y-m-d\TH:i:s.uP').'","extra":{}}', $formatter->format($record));
$this->assertEquals('{"message":"test","context":{},"level":300,"level_name":"WARNING","channel":"test","datetime":"'.$record->datetime->format('Y-m-d\TH:i:s.uP').'","extra":{}}', $formatter->format($record));
}
/**
@@ -187,7 +187,7 @@ class JsonFormatterTest extends TestCase
$record = $this->getRecord(
context: ['field_resource' => opendir(__DIR__)],
);
$this->assertEquals('{"message":"test","context":{"field_resource":"[resource(stream)]"},"level":300,"level_name":"WARNING","channel":"test","datetime":"'.$record['datetime']->format('Y-m-d\TH:i:s.uP').'","extra":{}}', $formatter->format($record));
$this->assertEquals('{"message":"test","context":{"field_resource":"[resource(stream)]"},"level":300,"level_name":"WARNING","channel":"test","datetime":"'.$record->datetime->format('Y-m-d\TH:i:s.uP').'","extra":{}}', $formatter->format($record));
}
/**

View File

@@ -36,6 +36,6 @@ class LogglyFormatterTest extends TestCase
$formatted_decoded = json_decode($formatter->format($record), true);
$this->assertArrayNotHasKey("datetime", $formatted_decoded);
$this->assertArrayHasKey("timestamp", $formatted_decoded);
$this->assertEquals($record["datetime"]->format('Y-m-d\TH:i:s.uO'), $formatted_decoded["timestamp"]);
$this->assertEquals($record->datetime->format('Y-m-d\TH:i:s.uO'), $formatted_decoded["timestamp"]);
}
}

View File

@@ -145,7 +145,7 @@ class BufferHandlerTest extends TestCase
$test = new TestHandler();
$handler = new BufferHandler($test);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
});

View File

@@ -122,7 +122,7 @@ class DeduplicationHandlerTest extends TestCase
// log is written as none of them are duplicate
$handler->flush();
$this->assertSame(
$record['datetime']->getTimestamp() . ":ERROR:test\n" .
$record->datetime->getTimestamp() . ":ERROR:test\n" .
$record2['datetime']->getTimestamp() . ":CRITICAL:test\n" .
$record3['datetime']->getTimestamp() . ":CRITICAL:test\n",
file_get_contents(sys_get_temp_dir() . '/monolog_dedup.log')
@@ -144,7 +144,7 @@ class DeduplicationHandlerTest extends TestCase
// log should now contain the new errors and the previous one that was recent enough
$this->assertSame(
$record3['datetime']->getTimestamp() . ":CRITICAL:test\n" .
$record['datetime']->getTimestamp() . ":ERROR:test\n" .
$record->datetime->getTimestamp() . ":ERROR:test\n" .
$record2['datetime']->getTimestamp() . ":CRITICAL:test\n",
file_get_contents(sys_get_temp_dir() . '/monolog_dedup.log')
);

View File

@@ -38,7 +38,7 @@ class DoctrineCouchDBHandlerTest extends TestCase
'level' => Logger::WARNING,
'level_name' => 'WARNING',
'channel' => 'test',
'datetime' => (string) $record['datetime'],
'datetime' => (string) $record->datetime,
'extra' => [],
];

View File

@@ -98,7 +98,7 @@ class FallbackGroupHandlerTest extends TestCase
$test = new TestHandler();
$handler = new FallbackGroupHandler([$test]);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
});
@@ -118,12 +118,12 @@ class FallbackGroupHandlerTest extends TestCase
$testHandlers = [$testHandlerOne, $testHandlerTwo];
$handler = new FallbackGroupHandler($testHandlers);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
});
$handler->pushProcessor(function ($record) {
$record['extra']['foo2'] = true;
$record->extra['foo2'] = true;
return $record;
});

View File

@@ -110,7 +110,7 @@ class FilterHandlerTest extends TestCase
$handler = new FilterHandler($test, Logger::DEBUG, Logger::EMERGENCY);
$handler->pushProcessor(
function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
}

View File

@@ -56,8 +56,8 @@ class GelfHandlerTest extends TestCase
$expectedMessage
->setLevel(7)
->setFacility("test")
->setShortMessage($record['message'])
->setTimestamp($record['datetime'])
->setShortMessage($record->message)
->setTimestamp($record->datetime)
;
$messagePublisher = $this->getMessagePublisher();
@@ -77,8 +77,8 @@ class GelfHandlerTest extends TestCase
$expectedMessage
->setLevel(4)
->setFacility("test")
->setShortMessage($record['message'])
->setTimestamp($record['datetime'])
->setShortMessage($record->message)
->setTimestamp($record->datetime)
;
$messagePublisher = $this->getMessagePublisher();
@@ -105,8 +105,8 @@ class GelfHandlerTest extends TestCase
->setLevel(4)
->setFacility("test")
->setHost("mysystem")
->setShortMessage($record['message'])
->setTimestamp($record['datetime'])
->setShortMessage($record->message)
->setTimestamp($record->datetime)
->setAdditional("EXTblarg", 'yep')
->setAdditional("CTXfrom", 'logger')
;

View File

@@ -78,7 +78,7 @@ class GroupHandlerTest extends TestCase
$test = new TestHandler();
$handler = new GroupHandler([$test]);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
});
@@ -96,12 +96,12 @@ class GroupHandlerTest extends TestCase
$testHandlers = [new TestHandler(), new TestHandler()];
$handler = new GroupHandler($testHandlers);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
});
$handler->pushProcessor(function ($record) {
$record['extra']['foo2'] = true;
$record->extra['foo2'] = true;
return $record;
});

View File

@@ -65,7 +65,7 @@ class MailHandlerTest extends TestCase
$record = $this->getRecord();
$records = [$record];
$records[0]['formatted'] = '['.$record['datetime'].'] test.WARNING: test [] []'."\n";
$records[0]['formatted'] = '['.$record->datetime.'] test.WARNING: test [] []'."\n";
$handler->expects($this->once())
->method('send')

View File

@@ -44,7 +44,7 @@ class MongoDBHandlerTest extends TestCase
$record = $this->getRecord();
$expected = $record->toArray();
$expected['datetime'] = new \MongoDB\BSON\UTCDateTime((int) floor(((float) $record['datetime']->format('U.u')) * 1000));
$expected['datetime'] = new \MongoDB\BSON\UTCDateTime((int) floor(((float) $record->datetime->format('U.u')) * 1000));
$collection->expects($this->once())
->method('insertOne')

View File

@@ -67,7 +67,7 @@ class NewRelicHandlerTest extends TestCase
public function testThehandlerCanAddExtraParamsToTheNewRelicTrace()
{
$record = $this->getRecord(Logger::ERROR, 'log message');
$record['extra'] = ['c' => 'd'];
$record->extra = ['c' => 'd'];
$handler = new StubNewRelicHandler();
$handler->handle($record);
@@ -78,7 +78,7 @@ class NewRelicHandlerTest extends TestCase
public function testThehandlerCanAddExplodedExtraParamsToTheNewRelicTrace()
{
$record = $this->getRecord(Logger::ERROR, 'log message');
$record['extra'] = ['c' => ['key1' => 'value1', 'key2' => 'value2']];
$record->extra = ['c' => ['key1' => 'value1', 'key2' => 'value2']];
$handler = new StubNewRelicHandler(Logger::ERROR, true, self::$appname, true);
$handler->handle($record);
@@ -92,7 +92,7 @@ class NewRelicHandlerTest extends TestCase
public function testThehandlerCanAddExtraContextAndParamsToTheNewRelicTrace()
{
$record = $this->getRecord(Logger::ERROR, 'log message', ['a' => 'b']);
$record['extra'] = ['c' => 'd'];
$record->extra = ['c' => 'd'];
$handler = new StubNewRelicHandler();
$handler->handle($record);

View File

@@ -168,7 +168,7 @@ class SlackRecordTest extends TestCase
->expects($this->any())
->method('format')
->will($this->returnCallback(function ($record) {
return $record['message'] . 'test';
return $record->message . 'test';
}));
$formatter2 = $this->createMock('Monolog\\Formatter\\FormatterInterface');
@@ -176,7 +176,7 @@ class SlackRecordTest extends TestCase
->expects($this->any())
->method('format')
->will($this->returnCallback(function ($record) {
return $record['message'] . 'test1';
return $record->message . 'test1';
}));
$message = 'Test message';
@@ -345,7 +345,7 @@ class SlackRecordTest extends TestCase
$attachment = $data['attachments'][0];
$this->assertArrayHasKey('ts', $attachment);
$this->assertSame($record['datetime']->getTimestamp(), $attachment['ts']);
$this->assertSame($record->datetime->getTimestamp(), $attachment['ts']);
}
public function testContextHasException()
@@ -361,9 +361,9 @@ class SlackRecordTest extends TestCase
$record = $this->getRecord(
Logger::WARNING,
'test',
array('info' => array('library' => 'monolog', 'author' => 'Jordi'))
context: array('info' => array('library' => 'monolog', 'author' => 'Jordi')),
extra: array('tags' => array('web', 'cli')),
);
$record['extra'] = array('tags' => array('web', 'cli'));
$slackRecord = new SlackRecord(null, null, true, null, false, true, array('context.info.library', 'extra.tags.1'));
$data = $slackRecord->getSlackData($record);

View File

@@ -50,7 +50,7 @@ class SlackWebhookHandlerTest extends TestCase
),
'title' => 'Message',
'mrkdwn_in' => array('fields'),
'ts' => $record['datetime']->getTimestamp(),
'ts' => $record->datetime->getTimestamp(),
'footer' => null,
'footer_icon' => null,
),

View File

@@ -78,7 +78,7 @@ class WhatFailureGroupHandlerTest extends TestCase
$test = new TestHandler();
$handler = new WhatFailureGroupHandler([$test]);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
});
@@ -96,12 +96,12 @@ class WhatFailureGroupHandlerTest extends TestCase
$testHandlers = array(new TestHandler(), new TestHandler());
$handler = new WhatFailureGroupHandler($testHandlers);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
});
$handler->pushProcessor(function ($record) {
$record['extra']['foo2'] = true;
$record->extra['foo2'] = true;
return $record;
});
@@ -127,7 +127,7 @@ class WhatFailureGroupHandlerTest extends TestCase
$exception = new ExceptionTestHandler();
$handler = new WhatFailureGroupHandler([$exception, $test, $exception]);
$handler->pushProcessor(function ($record) {
$record['extra']['foo'] = true;
$record->extra['foo'] = true;
return $record;
});

View File

@@ -32,7 +32,7 @@ class ZendMonitorHandlerTest extends TestCase
{
$record = $this->getRecord();
$formatterResult = [
'message' => $record['message'],
'message' => $record->message,
];
$zendMonitor = $this->getMockBuilder('Monolog\Handler\ZendMonitorHandler')
@@ -56,10 +56,10 @@ class ZendMonitorHandlerTest extends TestCase
$zendMonitor->expects($this->once())
->method('writeZendMonitorCustomEvent')
->with(
Logger::getLevelName($record['level']),
$record['message'],
Logger::getLevelName($record->level),
$record->message,
$formatterResult,
$levelMap[$record['level']]
$levelMap[$record->level]
);
$zendMonitor->handle($record);

View File

@@ -82,7 +82,7 @@ class LoggerTest extends TestCase
$logger->pushHandler($handler);
$logger->warning('test');
list($record) = $handler->getRecords();
$this->assertEquals('foo', $record['channel']);
$this->assertEquals('foo', $record->channel);
}
/**
@@ -229,13 +229,13 @@ class LoggerTest extends TestCase
$handler = new TestHandler;
$logger->pushHandler($handler);
$logger->pushProcessor(function ($record) {
$record['extra']['win'] = true;
$record->extra['win'] = true;
return $record;
});
$logger->error('test');
list($record) = $handler->getRecords();
$this->assertTrue($record['extra']['win']);
$this->assertTrue($record->extra['win']);
}
/**
@@ -478,7 +478,7 @@ class LoggerTest extends TestCase
$logger->pushHandler($handler);
$logger->{$method}('test');
list($record) = $handler->getRecords();
$this->assertEquals($expectedLevel, $record['level']);
$this->assertEquals($expectedLevel, $record->level);
}
public function logMethodProvider()
@@ -508,7 +508,7 @@ class LoggerTest extends TestCase
$logger->pushHandler($handler);
$logger->info('test');
list($record) = $handler->getRecords();
$this->assertEquals($tz, $record['datetime']->getTimezone());
$this->assertEquals($tz, $record->datetime->getTimezone());
}
public function setTimezoneProvider()
@@ -538,8 +538,8 @@ class LoggerTest extends TestCase
$logger->info('test');
list($record) = $handler->getRecords();
$this->assertEquals($tz, $record['datetime']->getTimezone());
$this->assertEquals($dt->format('Y/m/d H:i'), $record['datetime']->format('Y/m/d H:i'), 'Time should match timezone with microseconds set to: '.var_export($microseconds, true));
$this->assertEquals($tz, $record->datetime->getTimezone());
$this->assertEquals($dt->format('Y/m/d H:i'), $record->datetime->format('Y/m/d H:i'), 'Time should match timezone with microseconds set to: '.var_export($microseconds, true));
}
}
@@ -561,8 +561,8 @@ class LoggerTest extends TestCase
$logger->info('test');
list($record) = $handler->getRecords();
$this->assertEquals($tz, $record['datetime']->getTimezone());
$this->assertEquals($dt->format('Y/m/d H:i'), $record['datetime']->format('Y/m/d H:i'), 'Time should match timezone with microseconds set to: '.var_export($microseconds, true));
$this->assertEquals($tz, $record->datetime->getTimezone());
$this->assertEquals($dt->format('Y/m/d H:i'), $record->datetime->format('Y/m/d H:i'), 'Time should match timezone with microseconds set to: '.var_export($microseconds, true));
}
}
@@ -588,8 +588,8 @@ class LoggerTest extends TestCase
$logger->pushHandler($handler);
$logger->info('test');
list($record) = $handler->getRecords();
$this->{$assert}('000000', $record['datetime']->format('u'));
$this->assertSame($record['datetime']->format($assertFormat), (string) $record['datetime']);
$this->{$assert}('000000', $record->datetime->format('u'));
$this->assertSame($record->datetime->format($assertFormat), (string) $record->datetime);
}
public function useMicrosecondTimestampsProvider()
@@ -648,7 +648,7 @@ class LoggerTest extends TestCase
$logger->setExceptionHandler(function ($e, $record) use ($that) {
$that->assertEquals($e->getMessage(), 'Some handler exception');
$that->assertInstanceOf(LogRecord::class, $record);
$that->assertEquals($record['message'], 'test');
$that->assertEquals($record->message, 'test');
});
$handler = $this->getMockBuilder('Monolog\Handler\HandlerInterface')->getMock();
$handler->expects($this->any())

View File

@@ -23,7 +23,7 @@ class GitProcessorTest extends TestCase
$processor = new GitProcessor();
$record = $processor($this->getRecord());
$this->assertArrayHasKey('git', $record['extra']);
$this->assertTrue(!is_array($record['extra']['git']['branch']));
$this->assertArrayHasKey('git', $record->extra);
$this->assertTrue(!is_array($record->extra['git']['branch']));
}
}

View File

@@ -22,9 +22,9 @@ class HostnameProcessorTest extends TestCase
{
$processor = new HostnameProcessor();
$record = $processor($this->getRecord());
$this->assertArrayHasKey('hostname', $record['extra']);
$this->assertIsString($record['extra']['hostname']);
$this->assertNotEmpty($record['extra']['hostname']);
$this->assertEquals(gethostname(), $record['extra']['hostname']);
$this->assertArrayHasKey('hostname', $record->extra);
$this->assertIsString($record->extra['hostname']);
$this->assertNotEmpty($record->extra['hostname']);
$this->assertEquals(gethostname(), $record->extra['hostname']);
}
}

View File

@@ -47,10 +47,10 @@ class IntrospectionProcessorTest extends TestCase
$tester = new \Acme\Tester;
$tester->test($handler, $this->getRecord());
list($record) = $handler->getRecords();
$this->assertEquals(__FILE__, $record['extra']['file']);
$this->assertEquals(18, $record['extra']['line']);
$this->assertEquals('Acme\Tester', $record['extra']['class']);
$this->assertEquals('test', $record['extra']['function']);
$this->assertEquals(__FILE__, $record->extra['file']);
$this->assertEquals(18, $record->extra['line']);
$this->assertEquals('Acme\Tester', $record->extra['class']);
$this->assertEquals('test', $record->extra['function']);
}
public function testProcessorFromFunc()
@@ -58,10 +58,10 @@ class IntrospectionProcessorTest extends TestCase
$handler = $this->getHandler();
\Acme\tester($handler, $this->getRecord());
list($record) = $handler->getRecords();
$this->assertEquals(__FILE__, $record['extra']['file']);
$this->assertEquals(24, $record['extra']['line']);
$this->assertEquals(null, $record['extra']['class']);
$this->assertEquals('Acme\tester', $record['extra']['function']);
$this->assertEquals(__FILE__, $record->extra['file']);
$this->assertEquals(24, $record->extra['line']);
$this->assertEquals(null, $record->extra['class']);
$this->assertEquals('Acme\tester', $record->extra['function']);
}
public function testLevelTooLow()

View File

@@ -23,8 +23,8 @@ class MemoryPeakUsageProcessorTest extends TestCase
{
$processor = new MemoryPeakUsageProcessor();
$record = $processor($this->getRecord());
$this->assertArrayHasKey('memory_peak_usage', $record['extra']);
$this->assertMatchesRegularExpression('#[0-9.]+ (M|K)?B$#', $record['extra']['memory_peak_usage']);
$this->assertArrayHasKey('memory_peak_usage', $record->extra);
$this->assertMatchesRegularExpression('#[0-9.]+ (M|K)?B$#', $record->extra['memory_peak_usage']);
}
/**
@@ -35,8 +35,8 @@ class MemoryPeakUsageProcessorTest extends TestCase
{
$processor = new MemoryPeakUsageProcessor(true, false);
$record = $processor($this->getRecord());
$this->assertArrayHasKey('memory_peak_usage', $record['extra']);
$this->assertIsInt($record['extra']['memory_peak_usage']);
$this->assertGreaterThan(0, $record['extra']['memory_peak_usage']);
$this->assertArrayHasKey('memory_peak_usage', $record->extra);
$this->assertIsInt($record->extra['memory_peak_usage']);
$this->assertGreaterThan(0, $record->extra['memory_peak_usage']);
}
}

View File

@@ -23,8 +23,8 @@ class MemoryUsageProcessorTest extends TestCase
{
$processor = new MemoryUsageProcessor();
$record = $processor($this->getRecord());
$this->assertArrayHasKey('memory_usage', $record['extra']);
$this->assertMatchesRegularExpression('#[0-9.]+ (M|K)?B$#', $record['extra']['memory_usage']);
$this->assertArrayHasKey('memory_usage', $record->extra);
$this->assertMatchesRegularExpression('#[0-9.]+ (M|K)?B$#', $record->extra['memory_usage']);
}
/**
@@ -35,8 +35,8 @@ class MemoryUsageProcessorTest extends TestCase
{
$processor = new MemoryUsageProcessor(true, false);
$record = $processor($this->getRecord());
$this->assertArrayHasKey('memory_usage', $record['extra']);
$this->assertIsInt($record['extra']['memory_usage']);
$this->assertGreaterThan(0, $record['extra']['memory_usage']);
$this->assertArrayHasKey('memory_usage', $record->extra);
$this->assertIsInt($record->extra['memory_usage']);
$this->assertGreaterThan(0, $record->extra['memory_usage']);
}
}

View File

@@ -35,8 +35,8 @@ class MercurialProcessorTest extends TestCase
$processor = new MercurialProcessor();
$record = $processor($this->getRecord());
$this->assertArrayHasKey('hg', $record['extra']);
$this->assertTrue(!is_array($record['extra']['hg']['branch']));
$this->assertTrue(!is_array($record['extra']['hg']['revision']));
$this->assertArrayHasKey('hg', $record->extra);
$this->assertTrue(!is_array($record->extra['hg']['branch']));
$this->assertTrue(!is_array($record->extra['hg']['revision']));
}
}

View File

@@ -22,9 +22,9 @@ class ProcessIdProcessorTest extends TestCase
{
$processor = new ProcessIdProcessor();
$record = $processor($this->getRecord());
$this->assertArrayHasKey('process_id', $record['extra']);
$this->assertIsInt($record['extra']['process_id']);
$this->assertGreaterThan(0, $record['extra']['process_id']);
$this->assertEquals(getmypid(), $record['extra']['process_id']);
$this->assertArrayHasKey('process_id', $record->extra);
$this->assertIsInt($record->extra['process_id']);
$this->assertGreaterThan(0, $record->extra['process_id']);
$this->assertEquals(getmypid(), $record->extra['process_id']);
}
}

View File

@@ -24,7 +24,7 @@ class TagProcessorTest extends TestCase
$processor = new TagProcessor($tags);
$record = $processor($this->getRecord());
$this->assertEquals($tags, $record['extra']['tags']);
$this->assertEquals($tags, $record->extra['tags']);
}
/**
@@ -36,14 +36,14 @@ class TagProcessorTest extends TestCase
$processor = new TagProcessor($tags);
$record = $processor($this->getRecord());
$this->assertEquals($tags, $record['extra']['tags']);
$this->assertEquals($tags, $record->extra['tags']);
$processor->setTags(['a', 'b']);
$record = $processor($this->getRecord());
$this->assertEquals(['a', 'b'], $record['extra']['tags']);
$this->assertEquals(['a', 'b'], $record->extra['tags']);
$processor->addTags(['a', 'c', 'foo' => 'bar']);
$record = $processor($this->getRecord());
$this->assertEquals(['a', 'b', 'a', 'c', 'foo' => 'bar'], $record['extra']['tags']);
$this->assertEquals(['a', 'b', 'a', 'c', 'foo' => 'bar'], $record->extra['tags']);
}
}

View File

@@ -22,7 +22,7 @@ class UidProcessorTest extends TestCase
{
$processor = new UidProcessor();
$record = $processor($this->getRecord());
$this->assertArrayHasKey('uid', $record['extra']);
$this->assertArrayHasKey('uid', $record->extra);
}
public function testGetUid()

View File

@@ -28,12 +28,12 @@ class WebProcessorTest extends TestCase
$processor = new WebProcessor($server);
$record = $processor($this->getRecord());
$this->assertEquals($server['REQUEST_URI'], $record['extra']['url']);
$this->assertEquals($server['REMOTE_ADDR'], $record['extra']['ip']);
$this->assertEquals($server['REQUEST_METHOD'], $record['extra']['http_method']);
$this->assertEquals($server['HTTP_REFERER'], $record['extra']['referrer']);
$this->assertEquals($server['SERVER_NAME'], $record['extra']['server']);
$this->assertEquals($server['UNIQUE_ID'], $record['extra']['unique_id']);
$this->assertEquals($server['REQUEST_URI'], $record->extra['url']);
$this->assertEquals($server['REMOTE_ADDR'], $record->extra['ip']);
$this->assertEquals($server['REQUEST_METHOD'], $record->extra['http_method']);
$this->assertEquals($server['HTTP_REFERER'], $record->extra['referrer']);
$this->assertEquals($server['SERVER_NAME'], $record->extra['server']);
$this->assertEquals($server['UNIQUE_ID'], $record->extra['unique_id']);
}
public function testProcessorDoNothingIfNoRequestUri()
@@ -44,7 +44,7 @@ class WebProcessorTest extends TestCase
];
$processor = new WebProcessor($server);
$record = $processor($this->getRecord());
$this->assertEmpty($record['extra']);
$this->assertEmpty($record->extra);
}
public function testProcessorReturnNullIfNoHttpReferer()
@@ -57,7 +57,7 @@ class WebProcessorTest extends TestCase
];
$processor = new WebProcessor($server);
$record = $processor($this->getRecord());
$this->assertNull($record['extra']['referrer']);
$this->assertNull($record->extra['referrer']);
}
public function testProcessorDoesNotAddUniqueIdIfNotPresent()
@@ -70,7 +70,7 @@ class WebProcessorTest extends TestCase
];
$processor = new WebProcessor($server);
$record = $processor($this->getRecord());
$this->assertFalse(isset($record['extra']['unique_id']));
$this->assertFalse(isset($record->extra['unique_id']));
}
public function testProcessorAddsOnlyRequestedExtraFields()
@@ -85,7 +85,7 @@ class WebProcessorTest extends TestCase
$processor = new WebProcessor($server, ['url', 'http_method']);
$record = $processor($this->getRecord());
$this->assertSame(['url' => 'A', 'http_method' => 'C'], $record['extra']);
$this->assertSame(['url' => 'A', 'http_method' => 'C'], $record->extra);
}
public function testProcessorAddsOnlyRequestedExtraFieldsIncludingOptionalFields()
@@ -98,7 +98,7 @@ class WebProcessorTest extends TestCase
$processor = new WebProcessor($server, array('url'));
$record = $processor($this->getRecord());
$this->assertSame(array('url' => 'A'), $record['extra']);
$this->assertSame(array('url' => 'A'), $record->extra);
}
public function testProcessorConfiguringOfExtraFields()
@@ -113,7 +113,7 @@ class WebProcessorTest extends TestCase
$processor = new WebProcessor($server, ['url' => 'REMOTE_ADDR']);
$record = $processor($this->getRecord());
$this->assertSame(['url' => 'B'], $record['extra']);
$this->assertSame(['url' => 'B'], $record->extra);
}
public function testInvalidData()

View File

@@ -44,7 +44,7 @@ class PsrLogCompatTest extends TestCase
return strtolower($match[0]);
};
return preg_replace_callback('{^[A-Z]+}', $lower, $record['formatted']);
return preg_replace_callback('{^[A-Z]+}', $lower, $record->formatted);
};
return array_map($convert, $this->handler->getRecords());