mirror of
https://github.com/Seldaek/monolog.git
synced 2025-07-29 17:30:14 +02:00
Upgrade PHPUnit to v8
This commit is contained in:
@@ -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",
|
||||
|
@@ -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");
|
||||
|
@@ -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,
|
||||
|
@@ -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
|
||||
*/
|
||||
|
@@ -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');
|
||||
|
@@ -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);
|
||||
|
@@ -17,7 +17,7 @@ class ScalarFormatterTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
private $formatter;
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->formatter = new ScalarFormatter();
|
||||
}
|
||||
|
@@ -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,
|
||||
|
@@ -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());
|
||||
|
@@ -19,7 +19,7 @@ use Monolog\Logger;
|
||||
*/
|
||||
class BrowserConsoleHandlerTest extends TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
BrowserConsoleHandler::resetStatic();
|
||||
}
|
||||
|
@@ -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';
|
||||
|
@@ -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');
|
||||
}
|
||||
|
@@ -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');
|
||||
|
@@ -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');
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
@@ -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';
|
||||
|
@@ -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';
|
||||
});
|
||||
|
@@ -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';
|
||||
|
@@ -30,7 +30,7 @@ class FleepHookHandlerTest extends TestCase
|
||||
*/
|
||||
private $handler;
|
||||
|
||||
public function setUp()
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@@ -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');
|
||||
|
@@ -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");
|
||||
|
@@ -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"]);
|
||||
}
|
||||
|
||||
|
@@ -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');
|
||||
|
@@ -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');
|
||||
}
|
||||
|
||||
|
@@ -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");
|
||||
}
|
||||
|
@@ -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));
|
||||
}
|
||||
|
@@ -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]);
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -35,7 +35,7 @@ class RollbarHandlerTest extends TestCase
|
||||
*/
|
||||
private $reportedExceptionArguments = null;
|
||||
|
||||
protected function setUp()
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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');
|
||||
|
@@ -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())
|
||||
|
@@ -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');
|
||||
}
|
||||
|
@@ -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')
|
||||
|
@@ -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");
|
||||
}
|
||||
|
||||
|
@@ -36,7 +36,6 @@ class TelegramBotHandlerTest extends TestCase
|
||||
->getMock();
|
||||
|
||||
$this->handler->expects($this->atLeast(1))
|
||||
->method('send')
|
||||
->willReturn(null);
|
||||
->method('send');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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");
|
||||
|
@@ -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"]);
|
||||
}
|
||||
|
||||
|
@@ -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');
|
||||
|
@@ -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())
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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');
|
||||
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user