1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-07-29 09:20:12 +02:00

Upgrade PHPUnit to v8

This commit is contained in:
Mario Blažek
2019-08-12 15:20:00 +02:00
parent 2e3c369667
commit 37900f9268
46 changed files with 154 additions and 166 deletions

View File

@@ -25,7 +25,7 @@
"php-amqplib/php-amqplib": "~2.4", "php-amqplib/php-amqplib": "~2.4",
"php-console/php-console": "^3.1.3", "php-console/php-console": "^3.1.3",
"phpspec/prophecy": "^1.6.1", "phpspec/prophecy": "^1.6.1",
"phpunit/phpunit": "^7.5", "phpunit/phpunit": "^8.3",
"predis/predis": "^1.1", "predis/predis": "^1.1",
"rollbar/rollbar": "^1.3", "rollbar/rollbar": "^1.3",
"ruflin/elastica": ">=0.90 <3.0", "ruflin/elastica": ">=0.90 <3.0",

View File

@@ -15,7 +15,7 @@ use Monolog\Logger;
class ElasticaFormatterTest extends \PHPUnit\Framework\TestCase class ElasticaFormatterTest extends \PHPUnit\Framework\TestCase
{ {
public function setUp() public function setUp(): void
{ {
if (!class_exists("Elastica\Document")) { if (!class_exists("Elastica\Document")) {
$this->markTestSkipped("ruflin/elastica not installed"); $this->markTestSkipped("ruflin/elastica not installed");

View File

@@ -12,10 +12,11 @@
namespace Monolog\Formatter; namespace Monolog\Formatter;
use Monolog\Logger; use Monolog\Logger;
use PHPUnit\Framework\TestCase;
class GelfMessageFormatterTest extends \PHPUnit\Framework\TestCase class GelfMessageFormatterTest extends TestCase
{ {
public function setUp() public function setUp(): void
{ {
if (!class_exists('\Gelf\Message')) { if (!class_exists('\Gelf\Message')) {
$this->markTestSkipped("graylog2/gelf-php is not installed"); $this->markTestSkipped("graylog2/gelf-php is not installed");
@@ -82,10 +83,11 @@ class GelfMessageFormatterTest extends \PHPUnit\Framework\TestCase
/** /**
* @covers Monolog\Formatter\GelfMessageFormatter::format * @covers Monolog\Formatter\GelfMessageFormatter::format
* @expectedException InvalidArgumentException
*/ */
public function testFormatInvalidFails() public function testFormatInvalidFails()
{ {
$this->expectException(\InvalidArgumentException::class);
$formatter = new GelfMessageFormatter(); $formatter = new GelfMessageFormatter();
$record = [ $record = [
'level' => Logger::ERROR, 'level' => Logger::ERROR,

View File

@@ -12,16 +12,10 @@
namespace Monolog\Formatter; namespace Monolog\Formatter;
use Monolog\Logger; use Monolog\Logger;
use PHPUnit\Framework\TestCase;
class LogstashFormatterTest extends \PHPUnit\Framework\TestCase class LogstashFormatterTest extends TestCase
{ {
public function tearDown()
{
\PHPUnit\Framework\Error\Warning::$enabled = true;
return parent::tearDown();
}
/** /**
* @covers Monolog\Formatter\LogstashFormatter::format * @covers Monolog\Formatter\LogstashFormatter::format
*/ */

View File

@@ -18,7 +18,7 @@ use Monolog\Logger;
*/ */
class MongoDBFormatterTest extends \PHPUnit\Framework\TestCase class MongoDBFormatterTest extends \PHPUnit\Framework\TestCase
{ {
public function setUp() public function setUp(): void
{ {
if (!class_exists('MongoDB\BSON\UTCDateTime')) { if (!class_exists('MongoDB\BSON\UTCDateTime')) {
$this->markTestSkipped('ext-mongodb not installed'); $this->markTestSkipped('ext-mongodb not installed');

View File

@@ -11,18 +11,13 @@
namespace Monolog\Formatter; namespace Monolog\Formatter;
use PHPUnit\Framework\TestCase;
/** /**
* @covers Monolog\Formatter\NormalizerFormatter * @covers Monolog\Formatter\NormalizerFormatter
*/ */
class NormalizerFormatterTest extends \PHPUnit\Framework\TestCase class NormalizerFormatterTest extends TestCase
{ {
public function tearDown()
{
\PHPUnit\Framework\Error\Warning::$enabled = true;
return parent::tearDown();
}
public function testFormat() public function testFormat()
{ {
$formatter = new NormalizerFormatter('Y-m-d'); $formatter = new NormalizerFormatter('Y-m-d');
@@ -263,11 +258,10 @@ class NormalizerFormatterTest extends \PHPUnit\Framework\TestCase
$this->assertEquals('Over 1000 items (2000 total), aborting normalization', $res['context'][0]['...']); $this->assertEquals('Over 1000 items (2000 total), aborting normalization', $res['context'][0]['...']);
} }
/**
* @expectedException RuntimeException
*/
public function testThrowsOnInvalidEncoding() public function testThrowsOnInvalidEncoding()
{ {
$this->expectException(\RuntimeException::class);
$formatter = new NormalizerFormatter(); $formatter = new NormalizerFormatter();
$reflMethod = new \ReflectionMethod($formatter, 'toJson'); $reflMethod = new \ReflectionMethod($formatter, 'toJson');
$reflMethod->setAccessible(true); $reflMethod->setAccessible(true);

View File

@@ -17,7 +17,7 @@ class ScalarFormatterTest extends \PHPUnit\Framework\TestCase
{ {
private $formatter; private $formatter;
public function setUp() public function setUp(): void
{ {
$this->formatter = new ScalarFormatter(); $this->formatter = new ScalarFormatter();
} }

View File

@@ -91,10 +91,11 @@ class WildfireFormatterTest extends \PHPUnit\Framework\TestCase
/** /**
* @covers Monolog\Formatter\WildfireFormatter::formatBatch * @covers Monolog\Formatter\WildfireFormatter::formatBatch
* @expectedException BadMethodCallException
*/ */
public function testBatchFormatThrowException() public function testBatchFormatThrowException()
{ {
$this->expectException(\BadMethodCallException::class);
$wildfire = new WildfireFormatter(); $wildfire = new WildfireFormatter();
$record = [ $record = [
'level' => Logger::ERROR, 'level' => Logger::ERROR,

View File

@@ -93,10 +93,11 @@ class AbstractProcessingHandlerTest extends TestCase
/** /**
* @covers Monolog\Handler\ProcessableHandlerTrait::pushProcessor * @covers Monolog\Handler\ProcessableHandlerTrait::pushProcessor
* @covers Monolog\Handler\ProcessableHandlerTrait::popProcessor * @covers Monolog\Handler\ProcessableHandlerTrait::popProcessor
* @expectedException LogicException
*/ */
public function testPushPopProcessor() public function testPushPopProcessor()
{ {
$this->expectException(\LogicException::class);
$logger = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler'); $logger = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler');
$processor1 = new WebProcessor; $processor1 = new WebProcessor;
$processor2 = new WebProcessor; $processor2 = new WebProcessor;
@@ -111,10 +112,11 @@ class AbstractProcessingHandlerTest extends TestCase
/** /**
* @covers Monolog\Handler\ProcessableHandlerTrait::pushProcessor * @covers Monolog\Handler\ProcessableHandlerTrait::pushProcessor
* @expectedException TypeError
*/ */
public function testPushProcessorWithNonCallable() public function testPushProcessorWithNonCallable()
{ {
$this->expectException(\TypeError::class);
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler'); $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler');
$handler->pushProcessor(new \stdClass()); $handler->pushProcessor(new \stdClass());

View File

@@ -19,7 +19,7 @@ use Monolog\Logger;
*/ */
class BrowserConsoleHandlerTest extends TestCase class BrowserConsoleHandlerTest extends TestCase
{ {
protected function setUp() protected function setUp(): void
{ {
BrowserConsoleHandler::resetStatic(); BrowserConsoleHandler::resetStatic();
} }

View File

@@ -19,7 +19,7 @@ use Monolog\Logger;
*/ */
class ChromePHPHandlerTest extends TestCase class ChromePHPHandlerTest extends TestCase
{ {
protected function setUp() protected function setUp(): void
{ {
TestChromePHPHandler::resetStatic(); TestChromePHPHandler::resetStatic();
$_SERVER['HTTP_USER_AGENT'] = 'Monolog Test; Chrome/1.0'; $_SERVER['HTTP_USER_AGENT'] = 'Monolog Test; Chrome/1.0';

View File

@@ -158,7 +158,7 @@ class DeduplicationHandlerTest extends TestCase
$this->assertFalse($test->hasWarningRecords()); $this->assertFalse($test->hasWarningRecords());
} }
public static function tearDownAfterClass() public static function tearDownAfterClass(): void
{ {
@unlink(sys_get_temp_dir().'/monolog_dedup.log'); @unlink(sys_get_temp_dir().'/monolog_dedup.log');
} }

View File

@@ -16,7 +16,7 @@ use Monolog\Logger;
class DoctrineCouchDBHandlerTest extends TestCase class DoctrineCouchDBHandlerTest extends TestCase
{ {
protected function setup() protected function setUp(): void
{ {
if (!class_exists('Doctrine\CouchDB\CouchDBClient')) { if (!class_exists('Doctrine\CouchDB\CouchDBClient')) {
$this->markTestSkipped('The "doctrine/couchdb" package is not installed'); $this->markTestSkipped('The "doctrine/couchdb" package is not installed');

View File

@@ -17,7 +17,7 @@ class DynamoDbHandlerTest extends TestCase
{ {
private $client; private $client;
public function setUp() public function setUp(): void
{ {
if (!class_exists('Aws\DynamoDb\DynamoDbClient')) { if (!class_exists('Aws\DynamoDb\DynamoDbClient')) {
$this->markTestSkipped('aws/aws-sdk-php not installed'); $this->markTestSkipped('aws/aws-sdk-php not installed');

View File

@@ -34,7 +34,7 @@ class ElasticaHandlerTest extends TestCase
'type' => 'doc_type', 'type' => 'doc_type',
]; ];
public function setUp() public function setUp(): void
{ {
// Elastica lib required // Elastica lib required
if (!class_exists("Elastica\Client")) { if (!class_exists("Elastica\Client")) {
@@ -97,11 +97,12 @@ class ElasticaHandlerTest extends TestCase
/** /**
* @covers Monolog\Handler\ElasticaHandler::setFormatter * @covers Monolog\Handler\ElasticaHandler::setFormatter
* @expectedException InvalidArgumentException
* @expectedExceptionMessage ElasticaHandler is only compatible with ElasticaFormatter
*/ */
public function testSetFormatterInvalid() public function testSetFormatterInvalid()
{ {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('ElasticaHandler is only compatible with ElasticaFormatter');
$handler = new ElasticaHandler($this->client); $handler = new ElasticaHandler($this->client);
$formatter = new NormalizerFormatter(); $formatter = new NormalizerFormatter();
$handler->setFormatter($formatter); $handler->setFormatter($formatter);

View File

@@ -33,7 +33,7 @@ class ElasticsearchHandlerTest extends TestCase
'type' => 'doc_type', 'type' => 'doc_type',
]; ];
public function setUp() public function setUp(): void
{ {
// Elasticsearch lib required // Elasticsearch lib required
if (!class_exists('Elasticsearch\Client')) { if (!class_exists('Elasticsearch\Client')) {
@@ -109,11 +109,12 @@ class ElasticsearchHandlerTest extends TestCase
/** /**
* @covers Monolog\Handler\ElasticsearchHandler::setFormatter * @covers Monolog\Handler\ElasticsearchHandler::setFormatter
* @expectedException InvalidArgumentException
* @expectedExceptionMessage ElasticsearchHandler is only compatible with ElasticsearchFormatter
*/ */
public function testSetFormatterInvalid() public function testSetFormatterInvalid()
{ {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('ElasticsearchHandler is only compatible with ElasticsearchFormatter');
$handler = new ElasticsearchHandler($this->client); $handler = new ElasticsearchHandler($this->client);
$formatter = new NormalizerFormatter(); $formatter = new NormalizerFormatter();
$handler->setFormatter($formatter); $handler->setFormatter($formatter);

View File

@@ -22,18 +22,19 @@ function error_log()
class ErrorLogHandlerTest extends TestCase class ErrorLogHandlerTest extends TestCase
{ {
protected function setUp() protected function setUp(): void
{ {
$GLOBALS['error_log'] = []; $GLOBALS['error_log'] = [];
} }
/** /**
* @covers Monolog\Handler\ErrorLogHandler::__construct * @covers Monolog\Handler\ErrorLogHandler::__construct
* @expectedException InvalidArgumentException
* @expectedExceptionMessage The given message type "42" is not supported
*/ */
public function testShouldNotAcceptAnInvalidTypeOnConstructor() public function testShouldNotAcceptAnInvalidTypeOnConstructor()
{ {
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('The given message type "42" is not supported');
new ErrorLogHandler(42); new ErrorLogHandler(42);
} }

View File

@@ -159,10 +159,11 @@ class FilterHandlerTest extends TestCase
/** /**
* @covers Monolog\Handler\FilterHandler::handle * @covers Monolog\Handler\FilterHandler::handle
* @expectedException \RuntimeException
*/ */
public function testHandleWithBadCallbackThrowsException() public function testHandleWithBadCallbackThrowsException()
{ {
$this->expectException(\RuntimeException::class);
$handler = new FilterHandler( $handler = new FilterHandler(
function ($record, $handler) { function ($record, $handler) {
return 'foo'; return 'foo';

View File

@@ -129,10 +129,11 @@ class FingersCrossedHandlerTest extends TestCase
/** /**
* @covers Monolog\Handler\FingersCrossedHandler::handle * @covers Monolog\Handler\FingersCrossedHandler::handle
* @covers Monolog\Handler\FingersCrossedHandler::activate * @covers Monolog\Handler\FingersCrossedHandler::activate
* @expectedException RuntimeException
*/ */
public function testHandleWithBadCallbackThrowsException() public function testHandleWithBadCallbackThrowsException()
{ {
$this->expectException(\RuntimeException::class);
$handler = new FingersCrossedHandler(function ($record, $handler) { $handler = new FingersCrossedHandler(function ($record, $handler) {
return 'foo'; return 'foo';
}); });

View File

@@ -19,7 +19,7 @@ use Monolog\Logger;
*/ */
class FirePHPHandlerTest extends TestCase class FirePHPHandlerTest extends TestCase
{ {
public function setUp() public function setUp(): void
{ {
TestFirePHPHandler::resetStatic(); TestFirePHPHandler::resetStatic();
$_SERVER['HTTP_USER_AGENT'] = 'Monolog Test; FirePHP/1.0'; $_SERVER['HTTP_USER_AGENT'] = 'Monolog Test; FirePHP/1.0';

View File

@@ -30,7 +30,7 @@ class FleepHookHandlerTest extends TestCase
*/ */
private $handler; private $handler;
public function setUp() public function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@@ -31,7 +31,7 @@ class FlowdockHandlerTest extends TestCase
*/ */
private $handler; private $handler;
public function setUp() public function setUp(): void
{ {
if (!extension_loaded('openssl')) { if (!extension_loaded('openssl')) {
$this->markTestSkipped('This test requires openssl to run'); $this->markTestSkipped('This test requires openssl to run');

View File

@@ -18,7 +18,7 @@ use Monolog\Formatter\GelfMessageFormatter;
class GelfHandlerTest extends TestCase class GelfHandlerTest extends TestCase
{ {
public function setUp() public function setUp(): void
{ {
if (!class_exists('Gelf\Publisher') || !class_exists('Gelf\Message')) { if (!class_exists('Gelf\Publisher') || !class_exists('Gelf\Message')) {
$this->markTestSkipped("graylog2/gelf-php not installed"); $this->markTestSkipped("graylog2/gelf-php not installed");

View File

@@ -18,10 +18,11 @@ class GroupHandlerTest extends TestCase
{ {
/** /**
* @covers Monolog\Handler\GroupHandler::__construct * @covers Monolog\Handler\GroupHandler::__construct
* @expectedException InvalidArgumentException
*/ */
public function testConstructorOnlyTakesHandler() public function testConstructorOnlyTakesHandler()
{ {
$this->expectException(\InvalidArgumentException::class);
new GroupHandler([new TestHandler(), "foo"]); new GroupHandler([new TestHandler(), "foo"]);
} }

View File

@@ -25,7 +25,7 @@ class HandlerWrapperTest extends TestCase
private $handler; private $handler;
public function setUp() public function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->handler = $this->createMock('Monolog\\Handler\\HandlerInterface'); $this->handler = $this->createMock('Monolog\\Handler\\HandlerInterface');

View File

@@ -17,11 +17,10 @@ use Monolog\Formatter\NormalizerFormatter;
class MongoDBHandlerTest extends TestCase class MongoDBHandlerTest extends TestCase
{ {
/**
* @expectedException InvalidArgumentException
*/
public function testConstructorShouldThrowExceptionForInvalidMongo() public function testConstructorShouldThrowExceptionForInvalidMongo()
{ {
$this->expectException(\InvalidArgumentException::class);
new MongoDBHandler(new \stdClass, 'db', 'collection'); new MongoDBHandler(new \stdClass, 'db', 'collection');
} }

View File

@@ -22,51 +22,46 @@ function mail($to, $subject, $message, $additional_headers = null, $additional_p
class NativeMailerHandlerTest extends TestCase class NativeMailerHandlerTest extends TestCase
{ {
protected function setUp() protected function setUp(): void
{ {
$GLOBALS['mail'] = []; $GLOBALS['mail'] = [];
} }
/**
* @expectedException InvalidArgumentException
*/
public function testConstructorHeaderInjection() public function testConstructorHeaderInjection()
{ {
$this->expectException(\InvalidArgumentException::class);
$mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', "receiver@example.org\r\nFrom: faked@attacker.org"); $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', "receiver@example.org\r\nFrom: faked@attacker.org");
} }
/**
* @expectedException InvalidArgumentException
*/
public function testSetterHeaderInjection() public function testSetterHeaderInjection()
{ {
$this->expectException(\InvalidArgumentException::class);
$mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org'); $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org');
$mailer->addHeader("Content-Type: text/html\r\nFrom: faked@attacker.org"); $mailer->addHeader("Content-Type: text/html\r\nFrom: faked@attacker.org");
} }
/**
* @expectedException InvalidArgumentException
*/
public function testSetterArrayHeaderInjection() public function testSetterArrayHeaderInjection()
{ {
$this->expectException(\InvalidArgumentException::class);
$mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org'); $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org');
$mailer->addHeader(["Content-Type: text/html\r\nFrom: faked@attacker.org"]); $mailer->addHeader(["Content-Type: text/html\r\nFrom: faked@attacker.org"]);
} }
/**
* @expectedException InvalidArgumentException
*/
public function testSetterContentTypeInjection() public function testSetterContentTypeInjection()
{ {
$this->expectException(\InvalidArgumentException::class);
$mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org'); $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org');
$mailer->setContentType("text/html\r\nFrom: faked@attacker.org"); $mailer->setContentType("text/html\r\nFrom: faked@attacker.org");
} }
/**
* @expectedException InvalidArgumentException
*/
public function testSetterEncodingInjection() public function testSetterEncodingInjection()
{ {
$this->expectException(\InvalidArgumentException::class);
$mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org'); $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org');
$mailer->setEncoding("utf-8\r\nFrom: faked@attacker.org"); $mailer->setEncoding("utf-8\r\nFrom: faked@attacker.org");
} }

View File

@@ -21,18 +21,17 @@ class NewRelicHandlerTest extends TestCase
public static $customParameters; public static $customParameters;
public static $transactionName; public static $transactionName;
public function setUp() public function setUp(): void
{ {
self::$appname = null; self::$appname = null;
self::$customParameters = []; self::$customParameters = [];
self::$transactionName = null; self::$transactionName = null;
} }
/**
* @expectedException Monolog\Handler\MissingExtensionException
*/
public function testThehandlerThrowsAnExceptionIfTheNRExtensionIsNotLoaded() public function testThehandlerThrowsAnExceptionIfTheNRExtensionIsNotLoaded()
{ {
$this->expectException(MissingExtensionException::class);
$handler = new StubNewRelicHandlerWithoutExtension(); $handler = new StubNewRelicHandlerWithoutExtension();
$handler->handle($this->getRecord(Logger::ERROR)); $handler->handle($this->getRecord(Logger::ERROR));
} }

View File

@@ -34,7 +34,7 @@ class PHPConsoleHandlerTest extends TestCase
/** @var ErrorDispatcher|MockObject */ /** @var ErrorDispatcher|MockObject */
protected $errorDispatcher; protected $errorDispatcher;
protected function setUp() protected function setUp(): void
{ {
if (!class_exists('PhpConsole\Connector')) { if (!class_exists('PhpConsole\Connector')) {
$this->markTestSkipped('PHP Console library not found. See https://github.com/barbushin/php-console#installation'); $this->markTestSkipped('PHP Console library not found. See https://github.com/barbushin/php-console#installation');
@@ -187,11 +187,10 @@ class PHPConsoleHandlerTest extends TestCase
); );
} }
/**
* @expectedException Exception
*/
public function testWrongOptionsThrowsException() public function testWrongOptionsThrowsException()
{ {
$this->expectException(\Exception::class);
new PHPConsoleHandler(['xxx' => 1]); new PHPConsoleHandler(['xxx' => 1]);
} }

View File

@@ -17,11 +17,10 @@ use Monolog\Formatter\LineFormatter;
class RedisHandlerTest extends TestCase class RedisHandlerTest extends TestCase
{ {
/**
* @expectedException InvalidArgumentException
*/
public function testConstructorShouldThrowExceptionForInvalidRedis() public function testConstructorShouldThrowExceptionForInvalidRedis()
{ {
$this->expectException(\InvalidArgumentException::class);
new RedisHandler(new \stdClass(), 'key'); new RedisHandler(new \stdClass(), 'key');
} }
@@ -43,11 +42,11 @@ class RedisHandlerTest extends TestCase
public function testPredisHandle() public function testPredisHandle()
{ {
$redis = $this->createPartialMock('Predis\Client', ['rpush']); $redis = $this->createPartialMock('Predis\Client', ['rPush']);
// Predis\Client uses rpush // Predis\Client uses rPush
$redis->expects($this->once()) $redis->expects($this->once())
->method('rpush') ->method('rPush')
->with('key', 'test'); ->with('key', 'test');
$record = $this->getRecord(Logger::WARNING, 'test', ['data' => new \stdClass, 'foo' => 34]); $record = $this->getRecord(Logger::WARNING, 'test', ['data' => new \stdClass, 'foo' => 34]);
@@ -63,11 +62,11 @@ class RedisHandlerTest extends TestCase
$this->markTestSkipped('The redis ext is required to run this test'); $this->markTestSkipped('The redis ext is required to run this test');
} }
$redis = $this->createPartialMock('Redis', ['rpush']); $redis = $this->createPartialMock('Redis', ['rPush']);
// Redis uses rPush // Redis uses rPush
$redis->expects($this->once()) $redis->expects($this->once())
->method('rpush') ->method('rPush')
->with('key', 'test'); ->with('key', 'test');
$record = $this->getRecord(Logger::WARNING, 'test', ['data' => new \stdClass, 'foo' => 34]); $record = $this->getRecord(Logger::WARNING, 'test', ['data' => new \stdClass, 'foo' => 34]);
@@ -83,7 +82,7 @@ class RedisHandlerTest extends TestCase
$this->markTestSkipped('The redis ext is required to run this test'); $this->markTestSkipped('The redis ext is required to run this test');
} }
$redis = $this->createPartialMock('Redis', ['multi', 'rpush', 'ltrim', 'exec']); $redis = $this->createPartialMock('Redis', ['multi', 'rPush', 'lTrim', 'exec']);
// Redis uses multi // Redis uses multi
$redis->expects($this->once()) $redis->expects($this->once())
@@ -91,11 +90,11 @@ class RedisHandlerTest extends TestCase
->will($this->returnSelf()); ->will($this->returnSelf());
$redis->expects($this->once()) $redis->expects($this->once())
->method('rpush') ->method('rPush')
->will($this->returnSelf()); ->will($this->returnSelf());
$redis->expects($this->once()) $redis->expects($this->once())
->method('ltrim') ->method('lTrim')
->will($this->returnSelf()); ->will($this->returnSelf());
$redis->expects($this->once()) $redis->expects($this->once())
@@ -113,14 +112,14 @@ class RedisHandlerTest extends TestCase
{ {
$redis = $this->createPartialMock('Predis\Client', ['transaction']); $redis = $this->createPartialMock('Predis\Client', ['transaction']);
$redisTransaction = $this->createPartialMock('Predis\Client', ['rpush', 'ltrim']); $redisTransaction = $this->createPartialMock('Predis\Client', ['rPush', 'lTrim']);
$redisTransaction->expects($this->once()) $redisTransaction->expects($this->once())
->method('rpush') ->method('rPush')
->will($this->returnSelf()); ->will($this->returnSelf());
$redisTransaction->expects($this->once()) $redisTransaction->expects($this->once())
->method('ltrim') ->method('lTrim')
->will($this->returnSelf()); ->will($this->returnSelf());
// Redis uses multi // Redis uses multi

View File

@@ -35,7 +35,7 @@ class RollbarHandlerTest extends TestCase
*/ */
private $reportedExceptionArguments = null; private $reportedExceptionArguments = null;
protected function setUp() protected function setUp(): void
{ {
parent::setUp(); parent::setUp();

View File

@@ -21,7 +21,7 @@ class RotatingFileHandlerTest extends TestCase
{ {
private $lastError; private $lastError;
public function setUp() public function setUp(): void
{ {
$dir = __DIR__.'/Fixtures'; $dir = __DIR__.'/Fixtures';
chmod($dir, 0777); chmod($dir, 0777);
@@ -238,7 +238,7 @@ class RotatingFileHandlerTest extends TestCase
$this->assertEquals('footest', file_get_contents($log)); $this->assertEquals('footest', file_get_contents($log));
} }
public function tearDown() public function tearDown(): void
{ {
foreach (glob(__DIR__.'/Fixtures/*.rot') as $file) { foreach (glob(__DIR__.'/Fixtures/*.rot') as $file) {
unlink($file); unlink($file);

View File

@@ -21,7 +21,7 @@ class SlackRecordTest extends TestCase
{ {
private $jsonPrettyPrintFlag; private $jsonPrettyPrintFlag;
protected function setUp() protected function setUp(): void
{ {
$this->jsonPrettyPrintFlag = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 128; $this->jsonPrettyPrintFlag = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 128;
} }

View File

@@ -32,7 +32,7 @@ class SlackHandlerTest extends TestCase
*/ */
private $handler; private $handler;
public function setUp() public function setUp(): void
{ {
if (!extension_loaded('openssl')) { if (!extension_loaded('openssl')) {
$this->markTestSkipped('This test requires openssl to run'); $this->markTestSkipped('This test requires openssl to run');

View File

@@ -30,20 +30,18 @@ class SocketHandlerTest extends TestCase
*/ */
private $res; private $res;
/**
* @expectedException UnexpectedValueException
*/
public function testInvalidHostname() public function testInvalidHostname()
{ {
$this->expectException(\UnexpectedValueException::class);
$this->createHandler('garbage://here'); $this->createHandler('garbage://here');
$this->writeRecord('data'); $this->writeRecord('data');
} }
/**
* @expectedException \InvalidArgumentException
*/
public function testBadConnectionTimeout() public function testBadConnectionTimeout()
{ {
$this->expectException(\InvalidArgumentException::class);
$this->createHandler('localhost:1234'); $this->createHandler('localhost:1234');
$this->handler->setConnectionTimeout(-1); $this->handler->setConnectionTimeout(-1);
} }
@@ -55,11 +53,10 @@ class SocketHandlerTest extends TestCase
$this->assertEquals(10.1, $this->handler->getConnectionTimeout()); $this->assertEquals(10.1, $this->handler->getConnectionTimeout());
} }
/**
* @expectedException \InvalidArgumentException
*/
public function testBadTimeout() public function testBadTimeout()
{ {
$this->expectException(\InvalidArgumentException::class);
$this->createHandler('localhost:1234'); $this->createHandler('localhost:1234');
$this->handler->setTimeout(-1); $this->handler->setTimeout(-1);
} }
@@ -91,11 +88,10 @@ class SocketHandlerTest extends TestCase
$this->assertEquals('tcp://localhost:9090', $this->handler->getConnectionString()); $this->assertEquals('tcp://localhost:9090', $this->handler->getConnectionString());
} }
/**
* @expectedException UnexpectedValueException
*/
public function testExceptionIsThrownOnFsockopenError() public function testExceptionIsThrownOnFsockopenError()
{ {
$this->expectException(\UnexpectedValueException::class);
$this->setMockHandler(['fsockopen']); $this->setMockHandler(['fsockopen']);
$this->handler->expects($this->once()) $this->handler->expects($this->once())
->method('fsockopen') ->method('fsockopen')
@@ -103,11 +99,10 @@ class SocketHandlerTest extends TestCase
$this->writeRecord('Hello world'); $this->writeRecord('Hello world');
} }
/**
* @expectedException UnexpectedValueException
*/
public function testExceptionIsThrownOnPfsockopenError() public function testExceptionIsThrownOnPfsockopenError()
{ {
$this->expectException(\UnexpectedValueException::class);
$this->setMockHandler(['pfsockopen']); $this->setMockHandler(['pfsockopen']);
$this->handler->expects($this->once()) $this->handler->expects($this->once())
->method('pfsockopen') ->method('pfsockopen')
@@ -116,11 +111,10 @@ class SocketHandlerTest extends TestCase
$this->writeRecord('Hello world'); $this->writeRecord('Hello world');
} }
/**
* @expectedException UnexpectedValueException
*/
public function testExceptionIsThrownIfCannotSetTimeout() public function testExceptionIsThrownIfCannotSetTimeout()
{ {
$this->expectException(\UnexpectedValueException::class);
$this->setMockHandler(['streamSetTimeout']); $this->setMockHandler(['streamSetTimeout']);
$this->handler->expects($this->once()) $this->handler->expects($this->once())
->method('streamSetTimeout') ->method('streamSetTimeout')
@@ -128,11 +122,10 @@ class SocketHandlerTest extends TestCase
$this->writeRecord('Hello world'); $this->writeRecord('Hello world');
} }
/**
* @expectedException UnexpectedValueException
*/
public function testExceptionIsThrownIfCannotSetChunkSize() public function testExceptionIsThrownIfCannotSetChunkSize()
{ {
$this->expectException(\UnexpectedValueException::class);
$this->setMockHandler(array('streamSetChunkSize')); $this->setMockHandler(array('streamSetChunkSize'));
$this->handler->setChunkSize(8192); $this->handler->setChunkSize(8192);
$this->handler->expects($this->once()) $this->handler->expects($this->once())
@@ -141,11 +134,10 @@ class SocketHandlerTest extends TestCase
$this->writeRecord('Hello world'); $this->writeRecord('Hello world');
} }
/**
* @expectedException RuntimeException
*/
public function testWriteFailsOnIfFwriteReturnsFalse() public function testWriteFailsOnIfFwriteReturnsFalse()
{ {
$this->expectException(\RuntimeException::class);
$this->setMockHandler(['fwrite']); $this->setMockHandler(['fwrite']);
$callback = function ($arg) { $callback = function ($arg) {
@@ -164,11 +156,10 @@ class SocketHandlerTest extends TestCase
$this->writeRecord('Hello world'); $this->writeRecord('Hello world');
} }
/**
* @expectedException RuntimeException
*/
public function testWriteFailsIfStreamTimesOut() public function testWriteFailsIfStreamTimesOut()
{ {
$this->expectException(\RuntimeException::class);
$this->setMockHandler(['fwrite', 'streamGetMetadata']); $this->setMockHandler(['fwrite', 'streamGetMetadata']);
$callback = function ($arg) { $callback = function ($arg) {
@@ -190,11 +181,10 @@ class SocketHandlerTest extends TestCase
$this->writeRecord('Hello world'); $this->writeRecord('Hello world');
} }
/**
* @expectedException RuntimeException
*/
public function testWriteFailsOnIncompleteWrite() public function testWriteFailsOnIncompleteWrite()
{ {
$this->expectException(\RuntimeException::class);
$this->setMockHandler(['fwrite', 'streamGetMetadata']); $this->setMockHandler(['fwrite', 'streamGetMetadata']);
$res = $this->res; $res = $this->res;
@@ -263,11 +253,10 @@ class SocketHandlerTest extends TestCase
$this->assertTrue(is_resource($this->res)); $this->assertTrue(is_resource($this->res));
} }
/**
* @expectedException \RuntimeException
*/
public function testAvoidInfiniteLoopWhenNoDataIsWrittenForAWritingTimeoutSeconds() public function testAvoidInfiniteLoopWhenNoDataIsWrittenForAWritingTimeoutSeconds()
{ {
$this->expectException(\RuntimeException::class);
$this->setMockHandler(['fwrite', 'streamGetMetadata']); $this->setMockHandler(['fwrite', 'streamGetMetadata']);
$this->handler->expects($this->any()) $this->handler->expects($this->any())

View File

@@ -70,7 +70,7 @@ class StreamHandlerTest extends TestCase
$this->assertTrue(is_resource($stream)); $this->assertTrue(is_resource($stream));
fseek($stream, 0); fseek($stream, 0);
$this->assertContains('testfoo', stream_get_contents($stream)); $this->assertStringContainsString('testfoo', stream_get_contents($stream));
$serialized = serialize($handler); $serialized = serialize($handler);
$this->assertFalse(is_resource($stream)); $this->assertFalse(is_resource($stream));
@@ -81,8 +81,8 @@ class StreamHandlerTest extends TestCase
$this->assertTrue(is_resource($stream)); $this->assertTrue(is_resource($stream));
fseek($stream, 0); fseek($stream, 0);
$contents = stream_get_contents($stream); $contents = stream_get_contents($stream);
$this->assertNotContains('testfoo', $contents); $this->assertStringNotContainsString('testfoo', $contents);
$this->assertContains('testbar', $contents); $this->assertStringContainsString('testbar', $contents);
} }
/** /**
@@ -106,12 +106,13 @@ class StreamHandlerTest extends TestCase
} }
/** /**
* @expectedException LogicException
* @covers Monolog\Handler\StreamHandler::__construct * @covers Monolog\Handler\StreamHandler::__construct
* @covers Monolog\Handler\StreamHandler::write * @covers Monolog\Handler\StreamHandler::write
*/ */
public function testWriteMissingResource() public function testWriteMissingResource()
{ {
$this->expectException(\LogicException::class);
$handler = new StreamHandler(null); $handler = new StreamHandler(null);
$handler->handle($this->getRecord()); $handler->handle($this->getRecord());
} }
@@ -127,32 +128,35 @@ class StreamHandlerTest extends TestCase
/** /**
* @dataProvider invalidArgumentProvider * @dataProvider invalidArgumentProvider
* @expectedException InvalidArgumentException
* @covers Monolog\Handler\StreamHandler::__construct * @covers Monolog\Handler\StreamHandler::__construct
*/ */
public function testWriteInvalidArgument($invalidArgument) public function testWriteInvalidArgument($invalidArgument)
{ {
$this->expectException(\InvalidArgumentException::class);
$handler = new StreamHandler($invalidArgument); $handler = new StreamHandler($invalidArgument);
} }
/** /**
* @expectedException UnexpectedValueException
* @covers Monolog\Handler\StreamHandler::__construct * @covers Monolog\Handler\StreamHandler::__construct
* @covers Monolog\Handler\StreamHandler::write * @covers Monolog\Handler\StreamHandler::write
*/ */
public function testWriteInvalidResource() public function testWriteInvalidResource()
{ {
$this->expectException(\UnexpectedValueException::class);
$handler = new StreamHandler('bogus://url'); $handler = new StreamHandler('bogus://url');
$handler->handle($this->getRecord()); $handler->handle($this->getRecord());
} }
/** /**
* @expectedException UnexpectedValueException
* @covers Monolog\Handler\StreamHandler::__construct * @covers Monolog\Handler\StreamHandler::__construct
* @covers Monolog\Handler\StreamHandler::write * @covers Monolog\Handler\StreamHandler::write
*/ */
public function testWriteNonExistingResource() public function testWriteNonExistingResource()
{ {
$this->expectException(\UnexpectedValueException::class);
$handler = new StreamHandler('ftp://foo/bar/baz/'.rand(0, 10000)); $handler = new StreamHandler('ftp://foo/bar/baz/'.rand(0, 10000));
$handler->handle($this->getRecord()); $handler->handle($this->getRecord());
} }
@@ -178,13 +182,15 @@ class StreamHandlerTest extends TestCase
} }
/** /**
* @expectedException Exception
* @expectedExceptionMessageRegExp /There is no existing directory at/
* @covers Monolog\Handler\StreamHandler::__construct * @covers Monolog\Handler\StreamHandler::__construct
* @covers Monolog\Handler\StreamHandler::write * @covers Monolog\Handler\StreamHandler::write
*/ */
public function testWriteNonExistingAndNotCreatablePath() public function testWriteNonExistingAndNotCreatablePath()
{ {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('There is no existing directory at');
if (defined('PHP_WINDOWS_VERSION_BUILD')) { if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('Permissions checks can not run on windows'); $this->markTestSkipped('Permissions checks can not run on windows');
} }
@@ -193,13 +199,14 @@ class StreamHandlerTest extends TestCase
} }
/** /**
* @expectedException Exception
* @expectedExceptionMessageRegExp /There is no existing directory at/
* @covers Monolog\Handler\StreamHandler::__construct * @covers Monolog\Handler\StreamHandler::__construct
* @covers Monolog\Handler\StreamHandler::write * @covers Monolog\Handler\StreamHandler::write
*/ */
public function testWriteNonExistingAndNotCreatableFileResource() public function testWriteNonExistingAndNotCreatableFileResource()
{ {
$this->expectException(\Exception::class);
$this->expectExceptionMessage('There is no existing directory at');
if (defined('PHP_WINDOWS_VERSION_BUILD')) { if (defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('Permissions checks can not run on windows'); $this->markTestSkipped('Permissions checks can not run on windows');
} }

View File

@@ -20,7 +20,7 @@ class SwiftMailerHandlerTest extends TestCase
/** @var \Swift_Mailer|MockObject */ /** @var \Swift_Mailer|MockObject */
private $mailer; private $mailer;
public function setUp() public function setUp(): void
{ {
$this->mailer = $this $this->mailer = $this
->getMockBuilder('Swift_Mailer') ->getMockBuilder('Swift_Mailer')

View File

@@ -18,11 +18,10 @@ use Monolog\Test\TestCase;
*/ */
class SyslogUdpHandlerTest extends TestCase class SyslogUdpHandlerTest extends TestCase
{ {
/**
* @expectedException UnexpectedValueException
*/
public function testWeValidateFacilities() public function testWeValidateFacilities()
{ {
$this->expectException(\UnexpectedValueException::class);
$handler = new SyslogUdpHandler("ip", 514, "invalidFacility"); $handler = new SyslogUdpHandler("ip", 514, "invalidFacility");
} }

View File

@@ -36,7 +36,6 @@ class TelegramBotHandlerTest extends TestCase
->getMock(); ->getMock();
$this->handler->expects($this->atLeast(1)) $this->handler->expects($this->atLeast(1))
->method('send') ->method('send');
->willReturn(null);
} }
} }

View File

@@ -58,11 +58,10 @@ class UdpSocketTest extends TestCase
$socket->close(); $socket->close();
} }
/**
* @expectedException RuntimeException
*/
public function testWriteAfterCloseErrors() public function testWriteAfterCloseErrors()
{ {
$this->expectException(\RuntimeException::class);
$socket = new UdpSocket('127.0.0.1', 514); $socket = new UdpSocket('127.0.0.1', 514);
$socket->close(); $socket->close();
$socket->write('foo', "HEADER"); $socket->write('foo', "HEADER");

View File

@@ -18,10 +18,11 @@ class WhatFailureGroupHandlerTest extends TestCase
{ {
/** /**
* @covers Monolog\Handler\WhatFailureGroupHandler::__construct * @covers Monolog\Handler\WhatFailureGroupHandler::__construct
* @expectedException InvalidArgumentException
*/ */
public function testConstructorOnlyTakesHandler() public function testConstructorOnlyTakesHandler()
{ {
$this->expectException(\InvalidArgumentException::class);
new WhatFailureGroupHandler([new TestHandler(), "foo"]); new WhatFailureGroupHandler([new TestHandler(), "foo"]);
} }

View File

@@ -17,7 +17,7 @@ class ZendMonitorHandlerTest extends TestCase
{ {
protected $zendMonitorHandler; protected $zendMonitorHandler;
public function setUp() public function setUp(): void
{ {
if (!function_exists('zend_monitor_custom_event')) { if (!function_exists('zend_monitor_custom_event')) {
$this->markTestSkipped('ZendServer is not installed'); $this->markTestSkipped('ZendServer is not installed');

View File

@@ -63,10 +63,11 @@ class LoggerTest extends \PHPUnit\Framework\TestCase
/** /**
* @covers Monolog\Logger::getLevelName * @covers Monolog\Logger::getLevelName
* @expectedException InvalidArgumentException
*/ */
public function testGetLevelNameThrows() public function testGetLevelNameThrows()
{ {
$this->expectException(\InvalidArgumentException::class);
Logger::getLevelName(5); Logger::getLevelName(5);
} }
@@ -138,10 +139,11 @@ class LoggerTest extends \PHPUnit\Framework\TestCase
/** /**
* @covers Monolog\Logger::pushHandler * @covers Monolog\Logger::pushHandler
* @covers Monolog\Logger::popHandler * @covers Monolog\Logger::popHandler
* @expectedException LogicException
*/ */
public function testPushPopHandler() public function testPushPopHandler()
{ {
$this->expectException(\LogicException::class);
$logger = new Logger(__METHOD__); $logger = new Logger(__METHOD__);
$handler1 = new TestHandler; $handler1 = new TestHandler;
$handler2 = new TestHandler; $handler2 = new TestHandler;
@@ -181,10 +183,11 @@ class LoggerTest extends \PHPUnit\Framework\TestCase
/** /**
* @covers Monolog\Logger::pushProcessor * @covers Monolog\Logger::pushProcessor
* @covers Monolog\Logger::popProcessor * @covers Monolog\Logger::popProcessor
* @expectedException LogicException
*/ */
public function testPushPopProcessor() public function testPushPopProcessor()
{ {
$this->expectException(\LogicException::class);
$logger = new Logger(__METHOD__); $logger = new Logger(__METHOD__);
$processor1 = new WebProcessor; $processor1 = new WebProcessor;
$processor2 = new WebProcessor; $processor2 = new WebProcessor;
@@ -541,7 +544,7 @@ class LoggerTest extends \PHPUnit\Framework\TestCase
} }
} }
public function tearDown() public function tearDown(): void
{ {
date_default_timezone_set('UTC'); date_default_timezone_set('UTC');
} }
@@ -592,10 +595,11 @@ class LoggerTest extends \PHPUnit\Framework\TestCase
/** /**
* @covers Monolog\Logger::handleException * @covers Monolog\Logger::handleException
* @expectedException Exception
*/ */
public function testDefaultHandleException() public function testDefaultHandleException()
{ {
$this->expectException(\Exception::class);
$logger = new Logger(__METHOD__); $logger = new Logger(__METHOD__);
$handler = $this->getMockBuilder('Monolog\Handler\HandlerInterface')->getMock(); $handler = $this->getMockBuilder('Monolog\Handler\HandlerInterface')->getMock();
$handler->expects($this->any()) $handler->expects($this->any())

View File

@@ -103,11 +103,10 @@ class WebProcessorTest extends TestCase
$this->assertSame(['url' => 'B'], $record['extra']); $this->assertSame(['url' => 'B'], $record['extra']);
} }
/**
* @expectedException UnexpectedValueException
*/
public function testInvalidData() public function testInvalidData()
{ {
$this->expectException(\UnexpectedValueException::class);
new WebProcessor(new \stdClass); new WebProcessor(new \stdClass);
} }
} }

View File

@@ -13,7 +13,7 @@ namespace Monolog;
class RegistryTest extends \PHPUnit\Framework\TestCase class RegistryTest extends \PHPUnit\Framework\TestCase
{ {
protected function setUp() protected function setUp(): void
{ {
Registry::clear(); Registry::clear();
} }
@@ -114,11 +114,11 @@ class RegistryTest extends \PHPUnit\Framework\TestCase
} }
/** /**
* @expectedException \InvalidArgumentException
* @covers Monolog\Registry::getInstance * @covers Monolog\Registry::getInstance
*/ */
public function testFailsOnNonExistantLogger() public function testFailsOnNonExistantLogger()
{ {
$this->expectException(\InvalidArgumentException::class);
Registry::getInstance('test1'); Registry::getInstance('test1');
} }
@@ -138,11 +138,12 @@ class RegistryTest extends \PHPUnit\Framework\TestCase
} }
/** /**
* @expectedException \InvalidArgumentException
* @covers Monolog\Registry::addLogger * @covers Monolog\Registry::addLogger
*/ */
public function testFailsOnUnspecifiedReplacement() public function testFailsOnUnspecifiedReplacement()
{ {
$this->expectException(\InvalidArgumentException::class);
$log1 = new Logger('test1'); $log1 = new Logger('test1');
$log2 = new Logger('test2'); $log2 = new Logger('test2');

View File

@@ -26,7 +26,7 @@ class SignalHandlerTest extends TestCase
private $blockedSignals; private $blockedSignals;
private $signalHandlers; private $signalHandlers;
protected function setUp() protected function setUp(): void
{ {
$this->signalHandlers = array(); $this->signalHandlers = array();
if (extension_loaded('pcntl')) { if (extension_loaded('pcntl')) {
@@ -39,7 +39,7 @@ class SignalHandlerTest extends TestCase
} }
} }
protected function tearDown() protected function tearDown(): void
{ {
if ($this->asyncSignalHandling !== null) { if ($this->asyncSignalHandling !== null) {
pcntl_async_signals($this->asyncSignalHandling); pcntl_async_signals($this->asyncSignalHandling);