diff --git a/composer.json b/composer.json index f3451742..85637ddd 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "php-amqplib/php-amqplib": "~2.4", "php-console/php-console": "^3.1.3", "phpspec/prophecy": "^1.6.1", - "phpunit/phpunit": "^7.5", + "phpunit/phpunit": "^8.3", "predis/predis": "^1.1", "rollbar/rollbar": "^1.3", "ruflin/elastica": ">=0.90 <3.0", diff --git a/tests/Monolog/Formatter/ElasticaFormatterTest.php b/tests/Monolog/Formatter/ElasticaFormatterTest.php index 5e4eeb9c..e2c97778 100644 --- a/tests/Monolog/Formatter/ElasticaFormatterTest.php +++ b/tests/Monolog/Formatter/ElasticaFormatterTest.php @@ -15,7 +15,7 @@ use Monolog\Logger; class ElasticaFormatterTest extends \PHPUnit\Framework\TestCase { - public function setUp() + public function setUp(): void { if (!class_exists("Elastica\Document")) { $this->markTestSkipped("ruflin/elastica not installed"); diff --git a/tests/Monolog/Formatter/GelfMessageFormatterTest.php b/tests/Monolog/Formatter/GelfMessageFormatterTest.php index 012de3cd..9be4b3e6 100644 --- a/tests/Monolog/Formatter/GelfMessageFormatterTest.php +++ b/tests/Monolog/Formatter/GelfMessageFormatterTest.php @@ -12,10 +12,11 @@ namespace Monolog\Formatter; 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')) { $this->markTestSkipped("graylog2/gelf-php is not installed"); @@ -82,10 +83,11 @@ class GelfMessageFormatterTest extends \PHPUnit\Framework\TestCase /** * @covers Monolog\Formatter\GelfMessageFormatter::format - * @expectedException InvalidArgumentException */ public function testFormatInvalidFails() { + $this->expectException(\InvalidArgumentException::class); + $formatter = new GelfMessageFormatter(); $record = [ 'level' => Logger::ERROR, diff --git a/tests/Monolog/Formatter/LogstashFormatterTest.php b/tests/Monolog/Formatter/LogstashFormatterTest.php index 5d0374bc..b242d680 100644 --- a/tests/Monolog/Formatter/LogstashFormatterTest.php +++ b/tests/Monolog/Formatter/LogstashFormatterTest.php @@ -12,16 +12,10 @@ namespace Monolog\Formatter; 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 */ diff --git a/tests/Monolog/Formatter/MongoDBFormatterTest.php b/tests/Monolog/Formatter/MongoDBFormatterTest.php index f9494f3d..140341b4 100644 --- a/tests/Monolog/Formatter/MongoDBFormatterTest.php +++ b/tests/Monolog/Formatter/MongoDBFormatterTest.php @@ -18,7 +18,7 @@ use Monolog\Logger; */ class MongoDBFormatterTest extends \PHPUnit\Framework\TestCase { - public function setUp() + public function setUp(): void { if (!class_exists('MongoDB\BSON\UTCDateTime')) { $this->markTestSkipped('ext-mongodb not installed'); diff --git a/tests/Monolog/Formatter/NormalizerFormatterTest.php b/tests/Monolog/Formatter/NormalizerFormatterTest.php index 8f3499a5..bc918543 100644 --- a/tests/Monolog/Formatter/NormalizerFormatterTest.php +++ b/tests/Monolog/Formatter/NormalizerFormatterTest.php @@ -11,18 +11,13 @@ namespace Monolog\Formatter; +use PHPUnit\Framework\TestCase; + /** * @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() { $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]['...']); } - /** - * @expectedException RuntimeException - */ public function testThrowsOnInvalidEncoding() { + $this->expectException(\RuntimeException::class); + $formatter = new NormalizerFormatter(); $reflMethod = new \ReflectionMethod($formatter, 'toJson'); $reflMethod->setAccessible(true); diff --git a/tests/Monolog/Formatter/ScalarFormatterTest.php b/tests/Monolog/Formatter/ScalarFormatterTest.php index 9af4937c..6c519628 100644 --- a/tests/Monolog/Formatter/ScalarFormatterTest.php +++ b/tests/Monolog/Formatter/ScalarFormatterTest.php @@ -17,7 +17,7 @@ class ScalarFormatterTest extends \PHPUnit\Framework\TestCase { private $formatter; - public function setUp() + public function setUp(): void { $this->formatter = new ScalarFormatter(); } diff --git a/tests/Monolog/Formatter/WildfireFormatterTest.php b/tests/Monolog/Formatter/WildfireFormatterTest.php index d0662020..06c75169 100644 --- a/tests/Monolog/Formatter/WildfireFormatterTest.php +++ b/tests/Monolog/Formatter/WildfireFormatterTest.php @@ -91,10 +91,11 @@ class WildfireFormatterTest extends \PHPUnit\Framework\TestCase /** * @covers Monolog\Formatter\WildfireFormatter::formatBatch - * @expectedException BadMethodCallException */ public function testBatchFormatThrowException() { + $this->expectException(\BadMethodCallException::class); + $wildfire = new WildfireFormatter(); $record = [ 'level' => Logger::ERROR, diff --git a/tests/Monolog/Handler/AbstractProcessingHandlerTest.php b/tests/Monolog/Handler/AbstractProcessingHandlerTest.php index 58d09202..0d3736d0 100644 --- a/tests/Monolog/Handler/AbstractProcessingHandlerTest.php +++ b/tests/Monolog/Handler/AbstractProcessingHandlerTest.php @@ -93,10 +93,11 @@ class AbstractProcessingHandlerTest extends TestCase /** * @covers Monolog\Handler\ProcessableHandlerTrait::pushProcessor * @covers Monolog\Handler\ProcessableHandlerTrait::popProcessor - * @expectedException LogicException */ public function testPushPopProcessor() { + $this->expectException(\LogicException::class); + $logger = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler'); $processor1 = new WebProcessor; $processor2 = new WebProcessor; @@ -111,10 +112,11 @@ class AbstractProcessingHandlerTest extends TestCase /** * @covers Monolog\Handler\ProcessableHandlerTrait::pushProcessor - * @expectedException TypeError */ public function testPushProcessorWithNonCallable() { + $this->expectException(\TypeError::class); + $handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler'); $handler->pushProcessor(new \stdClass()); diff --git a/tests/Monolog/Handler/BrowserConsoleHandlerTest.php b/tests/Monolog/Handler/BrowserConsoleHandlerTest.php index cbb216a1..57b4cc77 100644 --- a/tests/Monolog/Handler/BrowserConsoleHandlerTest.php +++ b/tests/Monolog/Handler/BrowserConsoleHandlerTest.php @@ -19,7 +19,7 @@ use Monolog\Logger; */ class BrowserConsoleHandlerTest extends TestCase { - protected function setUp() + protected function setUp(): void { BrowserConsoleHandler::resetStatic(); } diff --git a/tests/Monolog/Handler/ChromePHPHandlerTest.php b/tests/Monolog/Handler/ChromePHPHandlerTest.php index aff51847..42c0c559 100644 --- a/tests/Monolog/Handler/ChromePHPHandlerTest.php +++ b/tests/Monolog/Handler/ChromePHPHandlerTest.php @@ -19,7 +19,7 @@ use Monolog\Logger; */ class ChromePHPHandlerTest extends TestCase { - protected function setUp() + protected function setUp(): void { TestChromePHPHandler::resetStatic(); $_SERVER['HTTP_USER_AGENT'] = 'Monolog Test; Chrome/1.0'; diff --git a/tests/Monolog/Handler/DeduplicationHandlerTest.php b/tests/Monolog/Handler/DeduplicationHandlerTest.php index 491fd85c..ef4fb0a6 100644 --- a/tests/Monolog/Handler/DeduplicationHandlerTest.php +++ b/tests/Monolog/Handler/DeduplicationHandlerTest.php @@ -158,7 +158,7 @@ class DeduplicationHandlerTest extends TestCase $this->assertFalse($test->hasWarningRecords()); } - public static function tearDownAfterClass() + public static function tearDownAfterClass(): void { @unlink(sys_get_temp_dir().'/monolog_dedup.log'); } diff --git a/tests/Monolog/Handler/DoctrineCouchDBHandlerTest.php b/tests/Monolog/Handler/DoctrineCouchDBHandlerTest.php index f72f3237..80546aaf 100644 --- a/tests/Monolog/Handler/DoctrineCouchDBHandlerTest.php +++ b/tests/Monolog/Handler/DoctrineCouchDBHandlerTest.php @@ -16,7 +16,7 @@ use Monolog\Logger; class DoctrineCouchDBHandlerTest extends TestCase { - protected function setup() + protected function setUp(): void { if (!class_exists('Doctrine\CouchDB\CouchDBClient')) { $this->markTestSkipped('The "doctrine/couchdb" package is not installed'); diff --git a/tests/Monolog/Handler/DynamoDbHandlerTest.php b/tests/Monolog/Handler/DynamoDbHandlerTest.php index 9d61356f..0a291253 100644 --- a/tests/Monolog/Handler/DynamoDbHandlerTest.php +++ b/tests/Monolog/Handler/DynamoDbHandlerTest.php @@ -17,7 +17,7 @@ class DynamoDbHandlerTest extends TestCase { private $client; - public function setUp() + public function setUp(): void { if (!class_exists('Aws\DynamoDb\DynamoDbClient')) { $this->markTestSkipped('aws/aws-sdk-php not installed'); diff --git a/tests/Monolog/Handler/ElasticaHandlerTest.php b/tests/Monolog/Handler/ElasticaHandlerTest.php index 423adbe6..c456ec13 100644 --- a/tests/Monolog/Handler/ElasticaHandlerTest.php +++ b/tests/Monolog/Handler/ElasticaHandlerTest.php @@ -34,7 +34,7 @@ class ElasticaHandlerTest extends TestCase 'type' => 'doc_type', ]; - public function setUp() + public function setUp(): void { // Elastica lib required if (!class_exists("Elastica\Client")) { @@ -97,11 +97,12 @@ class ElasticaHandlerTest extends TestCase /** * @covers Monolog\Handler\ElasticaHandler::setFormatter - * @expectedException InvalidArgumentException - * @expectedExceptionMessage ElasticaHandler is only compatible with ElasticaFormatter */ public function testSetFormatterInvalid() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('ElasticaHandler is only compatible with ElasticaFormatter'); + $handler = new ElasticaHandler($this->client); $formatter = new NormalizerFormatter(); $handler->setFormatter($formatter); diff --git a/tests/Monolog/Handler/ElasticsearchHandlerTest.php b/tests/Monolog/Handler/ElasticsearchHandlerTest.php index 7895332b..06599e45 100644 --- a/tests/Monolog/Handler/ElasticsearchHandlerTest.php +++ b/tests/Monolog/Handler/ElasticsearchHandlerTest.php @@ -33,7 +33,7 @@ class ElasticsearchHandlerTest extends TestCase 'type' => 'doc_type', ]; - public function setUp() + public function setUp(): void { // Elasticsearch lib required if (!class_exists('Elasticsearch\Client')) { @@ -109,11 +109,12 @@ class ElasticsearchHandlerTest extends TestCase /** * @covers Monolog\Handler\ElasticsearchHandler::setFormatter - * @expectedException InvalidArgumentException - * @expectedExceptionMessage ElasticsearchHandler is only compatible with ElasticsearchFormatter */ public function testSetFormatterInvalid() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('ElasticsearchHandler is only compatible with ElasticsearchFormatter'); + $handler = new ElasticsearchHandler($this->client); $formatter = new NormalizerFormatter(); $handler->setFormatter($formatter); diff --git a/tests/Monolog/Handler/ErrorLogHandlerTest.php b/tests/Monolog/Handler/ErrorLogHandlerTest.php index 16d8e47d..d48a058b 100644 --- a/tests/Monolog/Handler/ErrorLogHandlerTest.php +++ b/tests/Monolog/Handler/ErrorLogHandlerTest.php @@ -22,18 +22,19 @@ function error_log() class ErrorLogHandlerTest extends TestCase { - protected function setUp() + protected function setUp(): void { $GLOBALS['error_log'] = []; } /** * @covers Monolog\Handler\ErrorLogHandler::__construct - * @expectedException InvalidArgumentException - * @expectedExceptionMessage The given message type "42" is not supported */ public function testShouldNotAcceptAnInvalidTypeOnConstructor() { + $this->expectException(\InvalidArgumentException::class); + $this->expectExceptionMessage('The given message type "42" is not supported'); + new ErrorLogHandler(42); } diff --git a/tests/Monolog/Handler/FilterHandlerTest.php b/tests/Monolog/Handler/FilterHandlerTest.php index b0072de0..db715719 100644 --- a/tests/Monolog/Handler/FilterHandlerTest.php +++ b/tests/Monolog/Handler/FilterHandlerTest.php @@ -159,10 +159,11 @@ class FilterHandlerTest extends TestCase /** * @covers Monolog\Handler\FilterHandler::handle - * @expectedException \RuntimeException */ public function testHandleWithBadCallbackThrowsException() { + $this->expectException(\RuntimeException::class); + $handler = new FilterHandler( function ($record, $handler) { return 'foo'; diff --git a/tests/Monolog/Handler/FingersCrossedHandlerTest.php b/tests/Monolog/Handler/FingersCrossedHandlerTest.php index b545489c..75dc49af 100644 --- a/tests/Monolog/Handler/FingersCrossedHandlerTest.php +++ b/tests/Monolog/Handler/FingersCrossedHandlerTest.php @@ -129,10 +129,11 @@ class FingersCrossedHandlerTest extends TestCase /** * @covers Monolog\Handler\FingersCrossedHandler::handle * @covers Monolog\Handler\FingersCrossedHandler::activate - * @expectedException RuntimeException */ public function testHandleWithBadCallbackThrowsException() { + $this->expectException(\RuntimeException::class); + $handler = new FingersCrossedHandler(function ($record, $handler) { return 'foo'; }); diff --git a/tests/Monolog/Handler/FirePHPHandlerTest.php b/tests/Monolog/Handler/FirePHPHandlerTest.php index 3ada7ced..cd8fa1be 100644 --- a/tests/Monolog/Handler/FirePHPHandlerTest.php +++ b/tests/Monolog/Handler/FirePHPHandlerTest.php @@ -19,7 +19,7 @@ use Monolog\Logger; */ class FirePHPHandlerTest extends TestCase { - public function setUp() + public function setUp(): void { TestFirePHPHandler::resetStatic(); $_SERVER['HTTP_USER_AGENT'] = 'Monolog Test; FirePHP/1.0'; diff --git a/tests/Monolog/Handler/FleepHookHandlerTest.php b/tests/Monolog/Handler/FleepHookHandlerTest.php index fe44e360..de01c44b 100644 --- a/tests/Monolog/Handler/FleepHookHandlerTest.php +++ b/tests/Monolog/Handler/FleepHookHandlerTest.php @@ -30,7 +30,7 @@ class FleepHookHandlerTest extends TestCase */ private $handler; - public function setUp() + public function setUp(): void { parent::setUp(); diff --git a/tests/Monolog/Handler/FlowdockHandlerTest.php b/tests/Monolog/Handler/FlowdockHandlerTest.php index 23f8b06c..ec8ad087 100644 --- a/tests/Monolog/Handler/FlowdockHandlerTest.php +++ b/tests/Monolog/Handler/FlowdockHandlerTest.php @@ -31,7 +31,7 @@ class FlowdockHandlerTest extends TestCase */ private $handler; - public function setUp() + public function setUp(): void { if (!extension_loaded('openssl')) { $this->markTestSkipped('This test requires openssl to run'); diff --git a/tests/Monolog/Handler/GelfHandlerTest.php b/tests/Monolog/Handler/GelfHandlerTest.php index 12e5f8b1..41de094d 100644 --- a/tests/Monolog/Handler/GelfHandlerTest.php +++ b/tests/Monolog/Handler/GelfHandlerTest.php @@ -18,7 +18,7 @@ use Monolog\Formatter\GelfMessageFormatter; class GelfHandlerTest extends TestCase { - public function setUp() + public function setUp(): void { if (!class_exists('Gelf\Publisher') || !class_exists('Gelf\Message')) { $this->markTestSkipped("graylog2/gelf-php not installed"); diff --git a/tests/Monolog/Handler/GroupHandlerTest.php b/tests/Monolog/Handler/GroupHandlerTest.php index 003c7014..536518c0 100644 --- a/tests/Monolog/Handler/GroupHandlerTest.php +++ b/tests/Monolog/Handler/GroupHandlerTest.php @@ -18,10 +18,11 @@ class GroupHandlerTest extends TestCase { /** * @covers Monolog\Handler\GroupHandler::__construct - * @expectedException InvalidArgumentException */ public function testConstructorOnlyTakesHandler() { + $this->expectException(\InvalidArgumentException::class); + new GroupHandler([new TestHandler(), "foo"]); } diff --git a/tests/Monolog/Handler/HandlerWrapperTest.php b/tests/Monolog/Handler/HandlerWrapperTest.php index 42fff1c6..87a117b1 100644 --- a/tests/Monolog/Handler/HandlerWrapperTest.php +++ b/tests/Monolog/Handler/HandlerWrapperTest.php @@ -25,7 +25,7 @@ class HandlerWrapperTest extends TestCase private $handler; - public function setUp() + public function setUp(): void { parent::setUp(); $this->handler = $this->createMock('Monolog\\Handler\\HandlerInterface'); diff --git a/tests/Monolog/Handler/MongoDBHandlerTest.php b/tests/Monolog/Handler/MongoDBHandlerTest.php index 7333ef62..a21f207b 100644 --- a/tests/Monolog/Handler/MongoDBHandlerTest.php +++ b/tests/Monolog/Handler/MongoDBHandlerTest.php @@ -17,11 +17,10 @@ use Monolog\Formatter\NormalizerFormatter; class MongoDBHandlerTest extends TestCase { - /** - * @expectedException InvalidArgumentException - */ public function testConstructorShouldThrowExceptionForInvalidMongo() { + $this->expectException(\InvalidArgumentException::class); + new MongoDBHandler(new \stdClass, 'db', 'collection'); } diff --git a/tests/Monolog/Handler/NativeMailerHandlerTest.php b/tests/Monolog/Handler/NativeMailerHandlerTest.php index 9e17cd3f..0803f5b4 100644 --- a/tests/Monolog/Handler/NativeMailerHandlerTest.php +++ b/tests/Monolog/Handler/NativeMailerHandlerTest.php @@ -22,51 +22,46 @@ function mail($to, $subject, $message, $additional_headers = null, $additional_p class NativeMailerHandlerTest extends TestCase { - protected function setUp() + protected function setUp(): void { $GLOBALS['mail'] = []; } - /** - * @expectedException InvalidArgumentException - */ public function testConstructorHeaderInjection() { + $this->expectException(\InvalidArgumentException::class); + $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', "receiver@example.org\r\nFrom: faked@attacker.org"); } - /** - * @expectedException InvalidArgumentException - */ public function testSetterHeaderInjection() { + $this->expectException(\InvalidArgumentException::class); + $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org'); $mailer->addHeader("Content-Type: text/html\r\nFrom: faked@attacker.org"); } - /** - * @expectedException InvalidArgumentException - */ public function testSetterArrayHeaderInjection() { + $this->expectException(\InvalidArgumentException::class); + $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org'); $mailer->addHeader(["Content-Type: text/html\r\nFrom: faked@attacker.org"]); } - /** - * @expectedException InvalidArgumentException - */ public function testSetterContentTypeInjection() { + $this->expectException(\InvalidArgumentException::class); + $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org'); $mailer->setContentType("text/html\r\nFrom: faked@attacker.org"); } - /** - * @expectedException InvalidArgumentException - */ public function testSetterEncodingInjection() { + $this->expectException(\InvalidArgumentException::class); + $mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org'); $mailer->setEncoding("utf-8\r\nFrom: faked@attacker.org"); } diff --git a/tests/Monolog/Handler/NewRelicHandlerTest.php b/tests/Monolog/Handler/NewRelicHandlerTest.php index 26160094..e4e4d70b 100644 --- a/tests/Monolog/Handler/NewRelicHandlerTest.php +++ b/tests/Monolog/Handler/NewRelicHandlerTest.php @@ -21,18 +21,17 @@ class NewRelicHandlerTest extends TestCase public static $customParameters; public static $transactionName; - public function setUp() + public function setUp(): void { self::$appname = null; self::$customParameters = []; self::$transactionName = null; } - /** - * @expectedException Monolog\Handler\MissingExtensionException - */ public function testThehandlerThrowsAnExceptionIfTheNRExtensionIsNotLoaded() { + $this->expectException(MissingExtensionException::class); + $handler = new StubNewRelicHandlerWithoutExtension(); $handler->handle($this->getRecord(Logger::ERROR)); } diff --git a/tests/Monolog/Handler/PHPConsoleHandlerTest.php b/tests/Monolog/Handler/PHPConsoleHandlerTest.php index 9c479da6..7b899550 100644 --- a/tests/Monolog/Handler/PHPConsoleHandlerTest.php +++ b/tests/Monolog/Handler/PHPConsoleHandlerTest.php @@ -34,7 +34,7 @@ class PHPConsoleHandlerTest extends TestCase /** @var ErrorDispatcher|MockObject */ protected $errorDispatcher; - protected function setUp() + protected function setUp(): void { if (!class_exists('PhpConsole\Connector')) { $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() { + $this->expectException(\Exception::class); + new PHPConsoleHandler(['xxx' => 1]); } diff --git a/tests/Monolog/Handler/RedisHandlerTest.php b/tests/Monolog/Handler/RedisHandlerTest.php index a0260e1d..19f2bbc7 100644 --- a/tests/Monolog/Handler/RedisHandlerTest.php +++ b/tests/Monolog/Handler/RedisHandlerTest.php @@ -17,11 +17,10 @@ use Monolog\Formatter\LineFormatter; class RedisHandlerTest extends TestCase { - /** - * @expectedException InvalidArgumentException - */ public function testConstructorShouldThrowExceptionForInvalidRedis() { + $this->expectException(\InvalidArgumentException::class); + new RedisHandler(new \stdClass(), 'key'); } @@ -43,11 +42,11 @@ class RedisHandlerTest extends TestCase 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()) - ->method('rpush') + ->method('rPush') ->with('key', 'test'); $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'); } - $redis = $this->createPartialMock('Redis', ['rpush']); + $redis = $this->createPartialMock('Redis', ['rPush']); // Redis uses rPush $redis->expects($this->once()) - ->method('rpush') + ->method('rPush') ->with('key', 'test'); $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'); } - $redis = $this->createPartialMock('Redis', ['multi', 'rpush', 'ltrim', 'exec']); + $redis = $this->createPartialMock('Redis', ['multi', 'rPush', 'lTrim', 'exec']); // Redis uses multi $redis->expects($this->once()) @@ -91,11 +90,11 @@ class RedisHandlerTest extends TestCase ->will($this->returnSelf()); $redis->expects($this->once()) - ->method('rpush') + ->method('rPush') ->will($this->returnSelf()); $redis->expects($this->once()) - ->method('ltrim') + ->method('lTrim') ->will($this->returnSelf()); $redis->expects($this->once()) @@ -113,14 +112,14 @@ class RedisHandlerTest extends TestCase { $redis = $this->createPartialMock('Predis\Client', ['transaction']); - $redisTransaction = $this->createPartialMock('Predis\Client', ['rpush', 'ltrim']); + $redisTransaction = $this->createPartialMock('Predis\Client', ['rPush', 'lTrim']); $redisTransaction->expects($this->once()) - ->method('rpush') + ->method('rPush') ->will($this->returnSelf()); $redisTransaction->expects($this->once()) - ->method('ltrim') + ->method('lTrim') ->will($this->returnSelf()); // Redis uses multi diff --git a/tests/Monolog/Handler/RollbarHandlerTest.php b/tests/Monolog/Handler/RollbarHandlerTest.php index 5d8c1fc2..7419ef82 100644 --- a/tests/Monolog/Handler/RollbarHandlerTest.php +++ b/tests/Monolog/Handler/RollbarHandlerTest.php @@ -35,7 +35,7 @@ class RollbarHandlerTest extends TestCase */ private $reportedExceptionArguments = null; - protected function setUp() + protected function setUp(): void { parent::setUp(); diff --git a/tests/Monolog/Handler/RotatingFileHandlerTest.php b/tests/Monolog/Handler/RotatingFileHandlerTest.php index 7d3e8c4f..6b695154 100644 --- a/tests/Monolog/Handler/RotatingFileHandlerTest.php +++ b/tests/Monolog/Handler/RotatingFileHandlerTest.php @@ -21,7 +21,7 @@ class RotatingFileHandlerTest extends TestCase { private $lastError; - public function setUp() + public function setUp(): void { $dir = __DIR__.'/Fixtures'; chmod($dir, 0777); @@ -238,7 +238,7 @@ class RotatingFileHandlerTest extends TestCase $this->assertEquals('footest', file_get_contents($log)); } - public function tearDown() + public function tearDown(): void { foreach (glob(__DIR__.'/Fixtures/*.rot') as $file) { unlink($file); diff --git a/tests/Monolog/Handler/Slack/SlackRecordTest.php b/tests/Monolog/Handler/Slack/SlackRecordTest.php index 9f23c7ce..f1572b27 100644 --- a/tests/Monolog/Handler/Slack/SlackRecordTest.php +++ b/tests/Monolog/Handler/Slack/SlackRecordTest.php @@ -21,7 +21,7 @@ class SlackRecordTest extends TestCase { private $jsonPrettyPrintFlag; - protected function setUp() + protected function setUp(): void { $this->jsonPrettyPrintFlag = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 128; } diff --git a/tests/Monolog/Handler/SlackHandlerTest.php b/tests/Monolog/Handler/SlackHandlerTest.php index e8abd15d..4a783349 100644 --- a/tests/Monolog/Handler/SlackHandlerTest.php +++ b/tests/Monolog/Handler/SlackHandlerTest.php @@ -32,7 +32,7 @@ class SlackHandlerTest extends TestCase */ private $handler; - public function setUp() + public function setUp(): void { if (!extension_loaded('openssl')) { $this->markTestSkipped('This test requires openssl to run'); diff --git a/tests/Monolog/Handler/SocketHandlerTest.php b/tests/Monolog/Handler/SocketHandlerTest.php index a003cb7f..48a2642a 100644 --- a/tests/Monolog/Handler/SocketHandlerTest.php +++ b/tests/Monolog/Handler/SocketHandlerTest.php @@ -30,20 +30,18 @@ class SocketHandlerTest extends TestCase */ private $res; - /** - * @expectedException UnexpectedValueException - */ public function testInvalidHostname() { + $this->expectException(\UnexpectedValueException::class); + $this->createHandler('garbage://here'); $this->writeRecord('data'); } - /** - * @expectedException \InvalidArgumentException - */ public function testBadConnectionTimeout() { + $this->expectException(\InvalidArgumentException::class); + $this->createHandler('localhost:1234'); $this->handler->setConnectionTimeout(-1); } @@ -55,11 +53,10 @@ class SocketHandlerTest extends TestCase $this->assertEquals(10.1, $this->handler->getConnectionTimeout()); } - /** - * @expectedException \InvalidArgumentException - */ public function testBadTimeout() { + $this->expectException(\InvalidArgumentException::class); + $this->createHandler('localhost:1234'); $this->handler->setTimeout(-1); } @@ -91,11 +88,10 @@ class SocketHandlerTest extends TestCase $this->assertEquals('tcp://localhost:9090', $this->handler->getConnectionString()); } - /** - * @expectedException UnexpectedValueException - */ public function testExceptionIsThrownOnFsockopenError() { + $this->expectException(\UnexpectedValueException::class); + $this->setMockHandler(['fsockopen']); $this->handler->expects($this->once()) ->method('fsockopen') @@ -103,11 +99,10 @@ class SocketHandlerTest extends TestCase $this->writeRecord('Hello world'); } - /** - * @expectedException UnexpectedValueException - */ public function testExceptionIsThrownOnPfsockopenError() { + $this->expectException(\UnexpectedValueException::class); + $this->setMockHandler(['pfsockopen']); $this->handler->expects($this->once()) ->method('pfsockopen') @@ -116,11 +111,10 @@ class SocketHandlerTest extends TestCase $this->writeRecord('Hello world'); } - /** - * @expectedException UnexpectedValueException - */ public function testExceptionIsThrownIfCannotSetTimeout() { + $this->expectException(\UnexpectedValueException::class); + $this->setMockHandler(['streamSetTimeout']); $this->handler->expects($this->once()) ->method('streamSetTimeout') @@ -128,11 +122,10 @@ class SocketHandlerTest extends TestCase $this->writeRecord('Hello world'); } - /** - * @expectedException UnexpectedValueException - */ public function testExceptionIsThrownIfCannotSetChunkSize() { + $this->expectException(\UnexpectedValueException::class); + $this->setMockHandler(array('streamSetChunkSize')); $this->handler->setChunkSize(8192); $this->handler->expects($this->once()) @@ -141,11 +134,10 @@ class SocketHandlerTest extends TestCase $this->writeRecord('Hello world'); } - /** - * @expectedException RuntimeException - */ public function testWriteFailsOnIfFwriteReturnsFalse() { + $this->expectException(\RuntimeException::class); + $this->setMockHandler(['fwrite']); $callback = function ($arg) { @@ -164,11 +156,10 @@ class SocketHandlerTest extends TestCase $this->writeRecord('Hello world'); } - /** - * @expectedException RuntimeException - */ public function testWriteFailsIfStreamTimesOut() { + $this->expectException(\RuntimeException::class); + $this->setMockHandler(['fwrite', 'streamGetMetadata']); $callback = function ($arg) { @@ -190,11 +181,10 @@ class SocketHandlerTest extends TestCase $this->writeRecord('Hello world'); } - /** - * @expectedException RuntimeException - */ public function testWriteFailsOnIncompleteWrite() { + $this->expectException(\RuntimeException::class); + $this->setMockHandler(['fwrite', 'streamGetMetadata']); $res = $this->res; @@ -263,11 +253,10 @@ class SocketHandlerTest extends TestCase $this->assertTrue(is_resource($this->res)); } - /** - * @expectedException \RuntimeException - */ public function testAvoidInfiniteLoopWhenNoDataIsWrittenForAWritingTimeoutSeconds() { + $this->expectException(\RuntimeException::class); + $this->setMockHandler(['fwrite', 'streamGetMetadata']); $this->handler->expects($this->any()) diff --git a/tests/Monolog/Handler/StreamHandlerTest.php b/tests/Monolog/Handler/StreamHandlerTest.php index 377e2964..f8101dba 100644 --- a/tests/Monolog/Handler/StreamHandlerTest.php +++ b/tests/Monolog/Handler/StreamHandlerTest.php @@ -70,7 +70,7 @@ class StreamHandlerTest extends TestCase $this->assertTrue(is_resource($stream)); fseek($stream, 0); - $this->assertContains('testfoo', stream_get_contents($stream)); + $this->assertStringContainsString('testfoo', stream_get_contents($stream)); $serialized = serialize($handler); $this->assertFalse(is_resource($stream)); @@ -81,8 +81,8 @@ class StreamHandlerTest extends TestCase $this->assertTrue(is_resource($stream)); fseek($stream, 0); $contents = stream_get_contents($stream); - $this->assertNotContains('testfoo', $contents); - $this->assertContains('testbar', $contents); + $this->assertStringNotContainsString('testfoo', $contents); + $this->assertStringContainsString('testbar', $contents); } /** @@ -106,12 +106,13 @@ class StreamHandlerTest extends TestCase } /** - * @expectedException LogicException * @covers Monolog\Handler\StreamHandler::__construct * @covers Monolog\Handler\StreamHandler::write */ public function testWriteMissingResource() { + $this->expectException(\LogicException::class); + $handler = new StreamHandler(null); $handler->handle($this->getRecord()); } @@ -127,32 +128,35 @@ class StreamHandlerTest extends TestCase /** * @dataProvider invalidArgumentProvider - * @expectedException InvalidArgumentException * @covers Monolog\Handler\StreamHandler::__construct */ public function testWriteInvalidArgument($invalidArgument) { + $this->expectException(\InvalidArgumentException::class); + $handler = new StreamHandler($invalidArgument); } /** - * @expectedException UnexpectedValueException * @covers Monolog\Handler\StreamHandler::__construct * @covers Monolog\Handler\StreamHandler::write */ public function testWriteInvalidResource() { + $this->expectException(\UnexpectedValueException::class); + $handler = new StreamHandler('bogus://url'); $handler->handle($this->getRecord()); } /** - * @expectedException UnexpectedValueException * @covers Monolog\Handler\StreamHandler::__construct * @covers Monolog\Handler\StreamHandler::write */ public function testWriteNonExistingResource() { + $this->expectException(\UnexpectedValueException::class); + $handler = new StreamHandler('ftp://foo/bar/baz/'.rand(0, 10000)); $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::write */ public function testWriteNonExistingAndNotCreatablePath() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('There is no existing directory at'); + + if (defined('PHP_WINDOWS_VERSION_BUILD')) { $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::write */ public function testWriteNonExistingAndNotCreatableFileResource() { + $this->expectException(\Exception::class); + $this->expectExceptionMessage('There is no existing directory at'); + if (defined('PHP_WINDOWS_VERSION_BUILD')) { $this->markTestSkipped('Permissions checks can not run on windows'); } diff --git a/tests/Monolog/Handler/SwiftMailerHandlerTest.php b/tests/Monolog/Handler/SwiftMailerHandlerTest.php index d8ff39bc..51596c39 100644 --- a/tests/Monolog/Handler/SwiftMailerHandlerTest.php +++ b/tests/Monolog/Handler/SwiftMailerHandlerTest.php @@ -20,7 +20,7 @@ class SwiftMailerHandlerTest extends TestCase /** @var \Swift_Mailer|MockObject */ private $mailer; - public function setUp() + public function setUp(): void { $this->mailer = $this ->getMockBuilder('Swift_Mailer') diff --git a/tests/Monolog/Handler/SyslogUdpHandlerTest.php b/tests/Monolog/Handler/SyslogUdpHandlerTest.php index 4ef2390c..4d0e114c 100644 --- a/tests/Monolog/Handler/SyslogUdpHandlerTest.php +++ b/tests/Monolog/Handler/SyslogUdpHandlerTest.php @@ -18,11 +18,10 @@ use Monolog\Test\TestCase; */ class SyslogUdpHandlerTest extends TestCase { - /** - * @expectedException UnexpectedValueException - */ public function testWeValidateFacilities() { + $this->expectException(\UnexpectedValueException::class); + $handler = new SyslogUdpHandler("ip", 514, "invalidFacility"); } diff --git a/tests/Monolog/Handler/TelegramBotHandlerTest.php b/tests/Monolog/Handler/TelegramBotHandlerTest.php index c9f22f0b..6e09aadd 100644 --- a/tests/Monolog/Handler/TelegramBotHandlerTest.php +++ b/tests/Monolog/Handler/TelegramBotHandlerTest.php @@ -36,7 +36,6 @@ class TelegramBotHandlerTest extends TestCase ->getMock(); $this->handler->expects($this->atLeast(1)) - ->method('send') - ->willReturn(null); + ->method('send'); } -} \ No newline at end of file +} diff --git a/tests/Monolog/Handler/UdpSocketTest.php b/tests/Monolog/Handler/UdpSocketTest.php index bc01a25b..530091cd 100644 --- a/tests/Monolog/Handler/UdpSocketTest.php +++ b/tests/Monolog/Handler/UdpSocketTest.php @@ -58,11 +58,10 @@ class UdpSocketTest extends TestCase $socket->close(); } - /** - * @expectedException RuntimeException - */ public function testWriteAfterCloseErrors() { + $this->expectException(\RuntimeException::class); + $socket = new UdpSocket('127.0.0.1', 514); $socket->close(); $socket->write('foo', "HEADER"); diff --git a/tests/Monolog/Handler/WhatFailureGroupHandlerTest.php b/tests/Monolog/Handler/WhatFailureGroupHandlerTest.php index 6aacdde5..c7ac4561 100644 --- a/tests/Monolog/Handler/WhatFailureGroupHandlerTest.php +++ b/tests/Monolog/Handler/WhatFailureGroupHandlerTest.php @@ -18,10 +18,11 @@ class WhatFailureGroupHandlerTest extends TestCase { /** * @covers Monolog\Handler\WhatFailureGroupHandler::__construct - * @expectedException InvalidArgumentException */ public function testConstructorOnlyTakesHandler() { + $this->expectException(\InvalidArgumentException::class); + new WhatFailureGroupHandler([new TestHandler(), "foo"]); } diff --git a/tests/Monolog/Handler/ZendMonitorHandlerTest.php b/tests/Monolog/Handler/ZendMonitorHandlerTest.php index 4879ebef..02169f17 100644 --- a/tests/Monolog/Handler/ZendMonitorHandlerTest.php +++ b/tests/Monolog/Handler/ZendMonitorHandlerTest.php @@ -17,7 +17,7 @@ class ZendMonitorHandlerTest extends TestCase { protected $zendMonitorHandler; - public function setUp() + public function setUp(): void { if (!function_exists('zend_monitor_custom_event')) { $this->markTestSkipped('ZendServer is not installed'); diff --git a/tests/Monolog/LoggerTest.php b/tests/Monolog/LoggerTest.php index c3c5e94a..deaa2c33 100644 --- a/tests/Monolog/LoggerTest.php +++ b/tests/Monolog/LoggerTest.php @@ -63,10 +63,11 @@ class LoggerTest extends \PHPUnit\Framework\TestCase /** * @covers Monolog\Logger::getLevelName - * @expectedException InvalidArgumentException */ public function testGetLevelNameThrows() { + $this->expectException(\InvalidArgumentException::class); + Logger::getLevelName(5); } @@ -138,10 +139,11 @@ class LoggerTest extends \PHPUnit\Framework\TestCase /** * @covers Monolog\Logger::pushHandler * @covers Monolog\Logger::popHandler - * @expectedException LogicException */ public function testPushPopHandler() { + $this->expectException(\LogicException::class); + $logger = new Logger(__METHOD__); $handler1 = new TestHandler; $handler2 = new TestHandler; @@ -181,10 +183,11 @@ class LoggerTest extends \PHPUnit\Framework\TestCase /** * @covers Monolog\Logger::pushProcessor * @covers Monolog\Logger::popProcessor - * @expectedException LogicException */ public function testPushPopProcessor() { + $this->expectException(\LogicException::class); + $logger = new Logger(__METHOD__); $processor1 = 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'); } @@ -592,10 +595,11 @@ class LoggerTest extends \PHPUnit\Framework\TestCase /** * @covers Monolog\Logger::handleException - * @expectedException Exception */ public function testDefaultHandleException() { + $this->expectException(\Exception::class); + $logger = new Logger(__METHOD__); $handler = $this->getMockBuilder('Monolog\Handler\HandlerInterface')->getMock(); $handler->expects($this->any()) diff --git a/tests/Monolog/Processor/WebProcessorTest.php b/tests/Monolog/Processor/WebProcessorTest.php index 6da6ab89..463dfd98 100644 --- a/tests/Monolog/Processor/WebProcessorTest.php +++ b/tests/Monolog/Processor/WebProcessorTest.php @@ -103,11 +103,10 @@ class WebProcessorTest extends TestCase $this->assertSame(['url' => 'B'], $record['extra']); } - /** - * @expectedException UnexpectedValueException - */ public function testInvalidData() { + $this->expectException(\UnexpectedValueException::class); + new WebProcessor(new \stdClass); } } diff --git a/tests/Monolog/RegistryTest.php b/tests/Monolog/RegistryTest.php index 7ee2cbdf..b917de86 100644 --- a/tests/Monolog/RegistryTest.php +++ b/tests/Monolog/RegistryTest.php @@ -13,7 +13,7 @@ namespace Monolog; class RegistryTest extends \PHPUnit\Framework\TestCase { - protected function setUp() + protected function setUp(): void { Registry::clear(); } @@ -114,11 +114,11 @@ class RegistryTest extends \PHPUnit\Framework\TestCase } /** - * @expectedException \InvalidArgumentException * @covers Monolog\Registry::getInstance */ public function testFailsOnNonExistantLogger() { + $this->expectException(\InvalidArgumentException::class); Registry::getInstance('test1'); } @@ -138,11 +138,12 @@ class RegistryTest extends \PHPUnit\Framework\TestCase } /** - * @expectedException \InvalidArgumentException * @covers Monolog\Registry::addLogger */ public function testFailsOnUnspecifiedReplacement() { + $this->expectException(\InvalidArgumentException::class); + $log1 = new Logger('test1'); $log2 = new Logger('test2'); diff --git a/tests/Monolog/SignalHandlerTest.php b/tests/Monolog/SignalHandlerTest.php index 5169705a..e73ad8fd 100644 --- a/tests/Monolog/SignalHandlerTest.php +++ b/tests/Monolog/SignalHandlerTest.php @@ -26,7 +26,7 @@ class SignalHandlerTest extends TestCase private $blockedSignals; private $signalHandlers; - protected function setUp() + protected function setUp(): void { $this->signalHandlers = array(); if (extension_loaded('pcntl')) { @@ -39,7 +39,7 @@ class SignalHandlerTest extends TestCase } } - protected function tearDown() + protected function tearDown(): void { if ($this->asyncSignalHandling !== null) { pcntl_async_signals($this->asyncSignalHandling);