mirror of
https://github.com/Seldaek/monolog.git
synced 2025-07-31 18:30:15 +02:00
Move expectException before the line where exception is thrown
This commit is contained in:
@@ -86,14 +86,14 @@ class GelfMessageFormatterTest extends TestCase
|
||||
*/
|
||||
public function testFormatInvalidFails()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
$formatter = new GelfMessageFormatter();
|
||||
$record = [
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
];
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
$formatter->format($record);
|
||||
}
|
||||
|
||||
|
@@ -260,8 +260,6 @@ class NormalizerFormatterTest extends TestCase
|
||||
|
||||
public function testThrowsOnInvalidEncoding()
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$formatter = new NormalizerFormatter();
|
||||
$reflMethod = new \ReflectionMethod($formatter, 'toJson');
|
||||
$reflMethod->setAccessible(true);
|
||||
@@ -269,6 +267,9 @@ class NormalizerFormatterTest extends TestCase
|
||||
// send an invalid unicode sequence as a object that can't be cleaned
|
||||
$record = new \stdClass;
|
||||
$record->message = "\xB1\x31";
|
||||
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$reflMethod->invoke($formatter, $record);
|
||||
}
|
||||
|
||||
|
@@ -96,8 +96,6 @@ class AbstractProcessingHandlerTest extends TestCase
|
||||
*/
|
||||
public function testPushPopProcessor()
|
||||
{
|
||||
$this->expectException(\LogicException::class);
|
||||
|
||||
$logger = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler');
|
||||
$processor1 = new WebProcessor;
|
||||
$processor2 = new WebProcessor;
|
||||
@@ -107,6 +105,9 @@ class AbstractProcessingHandlerTest extends TestCase
|
||||
|
||||
$this->assertEquals($processor2, $logger->popProcessor());
|
||||
$this->assertEquals($processor1, $logger->popProcessor());
|
||||
|
||||
$this->expectException(\LogicException::class);
|
||||
|
||||
$logger->popProcessor();
|
||||
}
|
||||
|
||||
@@ -115,10 +116,10 @@ class AbstractProcessingHandlerTest extends TestCase
|
||||
*/
|
||||
public function testPushProcessorWithNonCallable()
|
||||
{
|
||||
$this->expectException(\TypeError::class);
|
||||
|
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler');
|
||||
|
||||
$this->expectException(\TypeError::class);
|
||||
|
||||
$handler->pushProcessor(new \stdClass());
|
||||
}
|
||||
|
||||
|
@@ -100,11 +100,12 @@ class ElasticaHandlerTest extends TestCase
|
||||
*/
|
||||
public function testSetFormatterInvalid()
|
||||
{
|
||||
$handler = new ElasticaHandler($this->client);
|
||||
$formatter = new NormalizerFormatter();
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('ElasticaHandler is only compatible with ElasticaFormatter');
|
||||
|
||||
$handler = new ElasticaHandler($this->client);
|
||||
$formatter = new NormalizerFormatter();
|
||||
$handler->setFormatter($formatter);
|
||||
}
|
||||
|
||||
|
@@ -112,11 +112,12 @@ class ElasticsearchHandlerTest extends TestCase
|
||||
*/
|
||||
public function testSetFormatterInvalid()
|
||||
{
|
||||
$handler = new ElasticsearchHandler($this->client);
|
||||
$formatter = new NormalizerFormatter();
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->expectExceptionMessage('ElasticsearchHandler is only compatible with ElasticsearchFormatter');
|
||||
|
||||
$handler = new ElasticsearchHandler($this->client);
|
||||
$formatter = new NormalizerFormatter();
|
||||
$handler->setFormatter($formatter);
|
||||
}
|
||||
|
||||
|
@@ -162,13 +162,14 @@ class FilterHandlerTest extends TestCase
|
||||
*/
|
||||
public function testHandleWithBadCallbackThrowsException()
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$handler = new FilterHandler(
|
||||
function ($record, $handler) {
|
||||
return 'foo';
|
||||
}
|
||||
);
|
||||
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$handler->handle($this->getRecord(Logger::WARNING));
|
||||
}
|
||||
}
|
||||
|
@@ -132,11 +132,12 @@ class FingersCrossedHandlerTest extends TestCase
|
||||
*/
|
||||
public function testHandleWithBadCallbackThrowsException()
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$handler = new FingersCrossedHandler(function ($record, $handler) {
|
||||
return 'foo';
|
||||
});
|
||||
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$handler->handle($this->getRecord(Logger::WARNING));
|
||||
}
|
||||
|
||||
|
@@ -30,9 +30,10 @@ class NewRelicHandlerTest extends TestCase
|
||||
|
||||
public function testThehandlerThrowsAnExceptionIfTheNRExtensionIsNotLoaded()
|
||||
{
|
||||
$handler = new StubNewRelicHandlerWithoutExtension();
|
||||
|
||||
$this->expectException(MissingExtensionException::class);
|
||||
|
||||
$handler = new StubNewRelicHandlerWithoutExtension();
|
||||
$handler->handle($this->getRecord(Logger::ERROR));
|
||||
}
|
||||
|
||||
|
@@ -135,7 +135,7 @@ class ProcessHandlerTest extends TestCase
|
||||
->method('selectErrorStream')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->expectException('\UnexpectedValueException');
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
/** @var ProcessHandler $handler */
|
||||
$handler->handle($this->getRecord(Logger::WARNING, 'stream failing, whoops'));
|
||||
}
|
||||
@@ -147,7 +147,9 @@ class ProcessHandlerTest extends TestCase
|
||||
public function testStartupWithErrorsThrowsUnexpectedValueException()
|
||||
{
|
||||
$handler = new ProcessHandler('>&2 echo "some fake error message"');
|
||||
$this->expectException('\UnexpectedValueException');
|
||||
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
|
||||
$handler->handle($this->getRecord(Logger::WARNING, 'some warning in the house'));
|
||||
}
|
||||
|
||||
@@ -167,7 +169,7 @@ class ProcessHandlerTest extends TestCase
|
||||
->method('readProcessErrors')
|
||||
->willReturnOnConsecutiveCalls('', $this->returnValue('some fake error message here'));
|
||||
|
||||
$this->expectException('\UnexpectedValueException');
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
/** @var ProcessHandler $handler */
|
||||
$handler->handle($this->getRecord(Logger::WARNING, 'some test stuff'));
|
||||
}
|
||||
|
@@ -90,54 +90,57 @@ class SocketHandlerTest extends TestCase
|
||||
|
||||
public function testExceptionIsThrownOnFsockopenError()
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
|
||||
$this->setMockHandler(['fsockopen']);
|
||||
$this->handler->expects($this->once())
|
||||
->method('fsockopen')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
|
||||
$this->writeRecord('Hello world');
|
||||
}
|
||||
|
||||
public function testExceptionIsThrownOnPfsockopenError()
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
|
||||
$this->setMockHandler(['pfsockopen']);
|
||||
$this->handler->expects($this->once())
|
||||
->method('pfsockopen')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->handler->setPersistent(true);
|
||||
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
|
||||
$this->writeRecord('Hello world');
|
||||
}
|
||||
|
||||
public function testExceptionIsThrownIfCannotSetTimeout()
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
|
||||
$this->setMockHandler(['streamSetTimeout']);
|
||||
$this->handler->expects($this->once())
|
||||
->method('streamSetTimeout')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
|
||||
$this->writeRecord('Hello world');
|
||||
}
|
||||
|
||||
public function testExceptionIsThrownIfCannotSetChunkSize()
|
||||
{
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
|
||||
$this->setMockHandler(array('streamSetChunkSize'));
|
||||
$this->handler->setChunkSize(8192);
|
||||
$this->handler->expects($this->once())
|
||||
->method('streamSetChunkSize')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
|
||||
$this->writeRecord('Hello world');
|
||||
}
|
||||
|
||||
public function testWriteFailsOnIfFwriteReturnsFalse()
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$this->setMockHandler(['fwrite']);
|
||||
|
||||
$callback = function ($arg) {
|
||||
@@ -153,13 +156,13 @@ class SocketHandlerTest extends TestCase
|
||||
->method('fwrite')
|
||||
->will($this->returnCallback($callback));
|
||||
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$this->writeRecord('Hello world');
|
||||
}
|
||||
|
||||
public function testWriteFailsIfStreamTimesOut()
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$this->setMockHandler(['fwrite', 'streamGetMetadata']);
|
||||
|
||||
$callback = function ($arg) {
|
||||
@@ -178,13 +181,13 @@ class SocketHandlerTest extends TestCase
|
||||
->method('streamGetMetadata')
|
||||
->will($this->returnValue(['timed_out' => true]));
|
||||
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$this->writeRecord('Hello world');
|
||||
}
|
||||
|
||||
public function testWriteFailsOnIncompleteWrite()
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$this->setMockHandler(['fwrite', 'streamGetMetadata']);
|
||||
|
||||
$res = $this->res;
|
||||
@@ -201,6 +204,8 @@ class SocketHandlerTest extends TestCase
|
||||
->method('streamGetMetadata')
|
||||
->will($this->returnValue(['timed_out' => false]));
|
||||
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$this->writeRecord('Hello world');
|
||||
}
|
||||
|
||||
@@ -255,8 +260,6 @@ class SocketHandlerTest extends TestCase
|
||||
|
||||
public function testAvoidInfiniteLoopWhenNoDataIsWrittenForAWritingTimeoutSeconds()
|
||||
{
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$this->setMockHandler(['fwrite', 'streamGetMetadata']);
|
||||
|
||||
$this->handler->expects($this->any())
|
||||
@@ -269,6 +272,8 @@ class SocketHandlerTest extends TestCase
|
||||
|
||||
$this->handler->setWritingTimeout(1);
|
||||
|
||||
$this->expectException(\RuntimeException::class);
|
||||
|
||||
$this->writeRecord('Hello world');
|
||||
}
|
||||
|
||||
|
@@ -38,7 +38,7 @@ class SyslogHandlerTest extends \PHPUnit\Framework\TestCase
|
||||
*/
|
||||
public function testConstructInvalidFacility()
|
||||
{
|
||||
$this->expectException('UnexpectedValueException');
|
||||
$this->expectException(\UnexpectedValueException::class);
|
||||
$handler = new SyslogHandler('test', 'unknown');
|
||||
}
|
||||
}
|
||||
|
@@ -142,8 +142,6 @@ class LoggerTest extends \PHPUnit\Framework\TestCase
|
||||
*/
|
||||
public function testPushPopHandler()
|
||||
{
|
||||
$this->expectException(\LogicException::class);
|
||||
|
||||
$logger = new Logger(__METHOD__);
|
||||
$handler1 = new TestHandler;
|
||||
$handler2 = new TestHandler;
|
||||
@@ -153,6 +151,9 @@ class LoggerTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$this->assertEquals($handler2, $logger->popHandler());
|
||||
$this->assertEquals($handler1, $logger->popHandler());
|
||||
|
||||
$this->expectException(\LogicException::class);
|
||||
|
||||
$logger->popHandler();
|
||||
}
|
||||
|
||||
@@ -186,8 +187,6 @@ class LoggerTest extends \PHPUnit\Framework\TestCase
|
||||
*/
|
||||
public function testPushPopProcessor()
|
||||
{
|
||||
$this->expectException(\LogicException::class);
|
||||
|
||||
$logger = new Logger(__METHOD__);
|
||||
$processor1 = new WebProcessor;
|
||||
$processor2 = new WebProcessor;
|
||||
@@ -197,6 +196,9 @@ class LoggerTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$this->assertEquals($processor2, $logger->popProcessor());
|
||||
$this->assertEquals($processor1, $logger->popProcessor());
|
||||
|
||||
$this->expectException(\LogicException::class);
|
||||
|
||||
$logger->popProcessor();
|
||||
}
|
||||
|
||||
@@ -598,8 +600,6 @@ class LoggerTest extends \PHPUnit\Framework\TestCase
|
||||
*/
|
||||
public function testDefaultHandleException()
|
||||
{
|
||||
$this->expectException(\Exception::class);
|
||||
|
||||
$logger = new Logger(__METHOD__);
|
||||
$handler = $this->getMockBuilder('Monolog\Handler\HandlerInterface')->getMock();
|
||||
$handler->expects($this->any())
|
||||
@@ -610,6 +610,9 @@ class LoggerTest extends \PHPUnit\Framework\TestCase
|
||||
->method('handle')
|
||||
->will($this->throwException(new \Exception('Some handler exception')))
|
||||
;
|
||||
|
||||
$this->expectException(\Exception::class);
|
||||
|
||||
$logger->pushHandler($handler);
|
||||
$logger->info('test');
|
||||
}
|
||||
|
@@ -142,13 +142,13 @@ class RegistryTest extends \PHPUnit\Framework\TestCase
|
||||
*/
|
||||
public function testFailsOnUnspecifiedReplacement()
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
$log1 = new Logger('test1');
|
||||
$log2 = new Logger('test2');
|
||||
|
||||
Registry::addLogger($log1, 'log');
|
||||
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
Registry::addLogger($log2, 'log');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user