1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-22 21:03:37 +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

@@ -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()