1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-11 23:54:04 +02:00

Upgrade phpstan, phpunit (#1923)

* Upgrade phpstan, phpunit

* Fix phpunit deprecation

* Fix hg tests

* Fix php-console tests

* Fix phpunit on 8.1

* Bump phpconsole
This commit is contained in:
Jordi Boggiano
2024-11-11 15:21:55 +01:00
committed by GitHub
parent 7af6f41cff
commit f43e3d5637
43 changed files with 210 additions and 153 deletions

View File

@@ -27,7 +27,6 @@ class BrowserConsoleHandlerTest extends TestCase
protected function generateScript()
{
$reflMethod = new \ReflectionMethod('Monolog\Handler\BrowserConsoleHandler', 'generateScript');
$reflMethod->setAccessible(true);
return $reflMethod->invoke(null);
}

View File

@@ -39,6 +39,13 @@ class FleepHookHandlerTest extends TestCase
$this->handler = new FleepHookHandler(self::TOKEN);
}
public function tearDown(): void
{
parent::tearDown();
unset($this->handler);
}
/**
* @covers ::__construct
*/

View File

@@ -40,6 +40,7 @@ class FlowdockHandlerTest extends TestCase
parent::tearDown();
unset($this->res);
unset($this->handler);
}
public function testWriteHeader()
@@ -73,7 +74,6 @@ class FlowdockHandlerTest extends TestCase
->getMock();
$reflectionProperty = new \ReflectionProperty('Monolog\Handler\SocketHandler', 'connectionString');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->handler, 'localhost:1234');
$this->handler->expects($this->any())

View File

@@ -36,6 +36,7 @@ class HandlerWrapperTest extends TestCase
parent::tearDown();
unset($this->wrapper);
unset($this->handler);
}
public static function trueFalseDataProvider(): array

View File

@@ -33,6 +33,7 @@ class InsightOpsHandlerTest extends TestCase
parent::tearDown();
unset($this->resource);
unset($this->handler);
}
public function testWriteContent()
@@ -68,7 +69,6 @@ class InsightOpsHandlerTest extends TestCase
->getMock();
$reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->handler, 'localhost:1234');
$this->handler->expects($this->any())

View File

@@ -32,6 +32,7 @@ class LogEntriesHandlerTest extends TestCase
parent::tearDown();
unset($this->res);
unset($this->handler);
}
public function testWriteContent()
@@ -72,7 +73,6 @@ class LogEntriesHandlerTest extends TestCase
->getMock();
$reflectionProperty = new \ReflectionProperty('Monolog\Handler\SocketHandler', 'connectionString');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->handler, 'localhost:1234');
$this->handler->expects($this->any())

View File

@@ -32,6 +32,7 @@ class LogmaticHandlerTest extends TestCase
parent::tearDown();
unset($this->res);
unset($this->handler);
}
public function testWriteContent()
@@ -72,7 +73,6 @@ class LogmaticHandlerTest extends TestCase
->getMock();
$reflectionProperty = new \ReflectionProperty('Monolog\Handler\SocketHandler', 'connectionString');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->handler, 'localhost:1234');
$this->handler->expects($this->any())

View File

@@ -21,6 +21,7 @@ use PhpConsole\Dispatcher\Debug as DebugDispatcher;
use PhpConsole\Dispatcher\Errors as ErrorDispatcher;
use PhpConsole\Handler as VendorPhpConsoleHandler;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\WithoutErrorHandler;
use PHPUnit\Framework\MockObject\MockObject;
/**
@@ -169,6 +170,7 @@ class PHPConsoleHandlerTest extends TestCase
}
}
#[WithoutErrorHandler]
public function testError($classesPartialsTraceIgnore = null)
{
$code = E_USER_NOTICE;
@@ -182,10 +184,12 @@ class PHPConsoleHandlerTest extends TestCase
$this->equalTo($line),
$classesPartialsTraceIgnore ?: $this->equalTo($this->getHandlerDefaultOption('classesPartialsTraceIgnore'))
);
$errorHandler = ErrorHandler::register($this->initLogger($classesPartialsTraceIgnore ? ['classesPartialsTraceIgnore' => $classesPartialsTraceIgnore] : []), false);
$errorHandler = ErrorHandler::register($this->initLogger($classesPartialsTraceIgnore ? ['classesPartialsTraceIgnore' => $classesPartialsTraceIgnore] : []), false, false);
$errorHandler->registerErrorHandler([], false, E_USER_WARNING);
$reflMethod = new \ReflectionMethod($errorHandler, 'handleError');
$reflMethod->invoke($errorHandler, $code, $message, $file, $line);
restore_error_handler();
}
public function testException()
@@ -215,11 +219,6 @@ class PHPConsoleHandlerTest extends TestCase
$this->initLogger(['enabled' => false])->debug('test');
}
public function testOptionClassesPartialsTraceIgnore()
{
$this->testError(['Class', 'Namespace\\']);
}
public function testOptionDebugTagsKeysInContext()
{
$this->testDebugTags(['key1', 'key2']);
@@ -232,6 +231,11 @@ class PHPConsoleHandlerTest extends TestCase
}));
$this->assertEquals([VendorPhpConsoleHandler::getInstance(), 'handleException'], set_exception_handler(function () {
}));
restore_exception_handler();
restore_error_handler();
restore_exception_handler();
restore_error_handler();
}
public static function provideConnectorMethodsOptionsSets()

View File

@@ -22,7 +22,7 @@ class ProcessHandlerTest extends TestCase
*
* @var string
*/
const DUMMY_COMMAND = 'echo';
const DUMMY_COMMAND = 'php -r "echo fgets(STDIN);"';
/**
* @covers Monolog\Handler\ProcessHandler::__construct
@@ -42,7 +42,6 @@ class ProcessHandlerTest extends TestCase
$mockBuilder = $this->getMockBuilder('Monolog\Handler\ProcessHandler');
$mockBuilder->onlyMethods(['writeProcessInput']);
// using echo as command, as it is most probably available
$mockBuilder->setConstructorArgs([self::DUMMY_COMMAND]);
$handler = $mockBuilder->getMock();
@@ -163,7 +162,6 @@ class ProcessHandlerTest extends TestCase
{
$mockBuilder = $this->getMockBuilder('Monolog\Handler\ProcessHandler');
$mockBuilder->onlyMethods(['readProcessErrors']);
// using echo as command, as it is most probably available
$mockBuilder->setConstructorArgs([self::DUMMY_COMMAND]);
$handler = $mockBuilder->getMock();
@@ -184,7 +182,6 @@ class ProcessHandlerTest extends TestCase
{
$class = new \ReflectionClass('Monolog\Handler\ProcessHandler');
$property = $class->getProperty('process');
$property->setAccessible(true);
$handler = new ProcessHandler(self::DUMMY_COMMAND);
$handler->handle($this->getRecord(Level::Warning, '21 is only the half truth'));

View File

@@ -32,6 +32,7 @@ class PushoverHandlerTest extends TestCase
parent::tearDown();
unset($this->res);
unset($this->handler);
}
public function testWriteHeader()
@@ -131,7 +132,6 @@ class PushoverHandlerTest extends TestCase
->getMock();
$reflectionProperty = new \ReflectionProperty('Monolog\Handler\SocketHandler', 'connectionString');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->handler, 'localhost:1234');
$this->handler->expects($this->any())

View File

@@ -42,6 +42,7 @@ class SlackHandlerTest extends TestCase
parent::tearDown();
unset($this->res);
unset($this->handler);
}
public function testWriteHeader()
@@ -139,7 +140,6 @@ class SlackHandlerTest extends TestCase
->getMock();
$reflectionProperty = new \ReflectionProperty('Monolog\Handler\SocketHandler', 'connectionString');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->handler, 'localhost:1234');
$this->handler->expects($this->any())

View File

@@ -32,6 +32,7 @@ class SocketHandlerTest extends TestCase
parent::tearDown();
unset($this->res);
unset($this->handler);
}
public function testInvalidHostname()

View File

@@ -263,7 +263,7 @@ STRING;
#[DataProvider('provideMemoryValues')]
public function testPreventOOMError($phpMemory, $expectedChunkSize): void
{
$previousValue = ini_set('memory_limit', $phpMemory);
$previousValue = @ini_set('memory_limit', $phpMemory);
if ($previousValue === false) {
$this->markTestSkipped('We could not set a memory limit that would trigger the error.');

View File

@@ -23,6 +23,13 @@ class TelegramBotHandlerTest extends TestCase
{
private TelegramBotHandler&MockObject $handler;
public function tearDown(): void
{
parent::tearDown();
unset($this->handler);
}
public function testSendTelegramRequest(): void
{
$this->createHandler();