1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-19 11:21:27 +02:00

Use fully-qualified name for native functions (#1887)

This commit is contained in:
Christoph Dreis
2024-06-28 10:45:25 +02:00
committed by GitHub
parent 4e03d25f6d
commit 3ba77d1d39
90 changed files with 246 additions and 245 deletions

View File

@@ -37,7 +37,7 @@ class ErrorHandlerTest extends \PHPUnit\Framework\TestCase
try {
$errHandler->registerErrorHandler([], true);
$prop = $this->getPrivatePropertyValue($errHandler, 'previousErrorHandler');
$this->assertTrue(is_callable($prop));
$this->assertTrue(\is_callable($prop));
$this->assertSame($prevHandler, $prop);
$resHandler = $errHandler->registerErrorHandler([E_USER_NOTICE => LogLevel::EMERGENCY], false);
@@ -66,7 +66,7 @@ class ErrorHandlerTest extends \PHPUnit\Framework\TestCase
protected function getPrivatePropertyValue($instance, $property)
{
$ref = new \ReflectionClass(get_class($instance));
$ref = new \ReflectionClass(\get_class($instance));
$prop = $ref->getProperty($property);
$prop->setAccessible(true);
@@ -105,7 +105,7 @@ class ErrorHandlerTest extends \PHPUnit\Framework\TestCase
$errHandler->registerExceptionHandler([], true);
$prop = $this->getPrivatePropertyValue($errHandler, 'previousExceptionHandler');
$this->assertTrue(is_callable($prop));
$this->assertTrue(\is_callable($prop));
}
public function testCodeToString()

View File

@@ -193,8 +193,8 @@ class GelfMessageFormatterTest extends TestCase
$length = 200;
foreach ($messageArray as $key => $value) {
if (!in_array($key, ['level', 'timestamp']) && is_string($value)) {
$length += strlen($value);
if (!\in_array($key, ['level', 'timestamp']) && \is_string($value)) {
$length += \strlen($value);
}
}
@@ -219,8 +219,8 @@ class GelfMessageFormatterTest extends TestCase
$length = 200;
foreach ($messageArray as $key => $value) {
if (!in_array($key, ['level', 'timestamp'])) {
$length += strlen($value);
if (!\in_array($key, ['level', 'timestamp'])) {
$length += \strlen($value);
}
}

View File

@@ -244,7 +244,7 @@ class JsonFormatterTest extends TestCase
private function formatException($exception, ?string $previous = null): string
{
$formattedException =
'{"class":"' . get_class($exception) .
'{"class":"' . \get_class($exception) .
'","message":"' . $exception->getMessage() .
'","code":' . $exception->getCode() .
',"file":"' . $this->formatExceptionFilePathWithLine($exception) .

View File

@@ -296,7 +296,7 @@ class LineFormatterTest extends TestCase
{
$formatter = new LineFormatter();
$formatter->includeStacktraces();
$formatter->setBasePath(dirname(dirname(dirname(__DIR__))));
$formatter->setBasePath(\dirname(\dirname(\dirname(__DIR__))));
$formatter->indentStackTraces(' ');
$message = $formatter->format($this->getRecord(message: "foo", context: ['exception' => new RuntimeException('lala')]));

View File

@@ -67,13 +67,13 @@ class NormalizerFormatterTest extends TestCase
'exception' => $e2,
]);
$this->assertGreaterThan(5, count($formatted['exception']['trace']));
$this->assertGreaterThan(5, \count($formatted['exception']['trace']));
$this->assertTrue(isset($formatted['exception']['previous']));
unset($formatted['exception']['trace'], $formatted['exception']['previous']);
$this->assertEquals([
'exception' => [
'class' => get_class($e2),
'class' => \get_class($e2),
'message' => $e2->getMessage(),
'code' => $e2->getCode(),
'file' => $e2->getFile().':'.$e2->getLine(),
@@ -416,7 +416,7 @@ class NormalizerFormatterTest extends TestCase
{
try {
$arg = new TestInfoLeak;
call_user_func([$this, 'throwHelper'], $arg, $dt = new \DateTime());
\call_user_func([$this, 'throwHelper'], $arg, $dt = new \DateTime());
} catch (\Exception $e) {
}

View File

@@ -69,7 +69,7 @@ class ScalarFormatterTest extends TestCase
'bat' => ['foo' => 'bar'],
'bap' => (string) $dt,
'ban' => [
'class' => get_class($exception),
'class' => \get_class($exception),
'message' => $exception->getMessage(),
'code' => $exception->getCode(),
'file' => $exception->getFile() . ':' . $exception->getLine(),
@@ -97,7 +97,7 @@ class ScalarFormatterTest extends TestCase
$this->assertSame($this->encodeJson([
'exception' => [
'class' => get_class($exception),
'class' => \get_class($exception),
'message' => $exception->getMessage(),
'code' => $exception->getCode(),
'file' => $exception->getFile() . ':' . $exception->getLine(),

View File

@@ -87,7 +87,7 @@ class AbstractProcessingHandlerTest extends TestCase
})
;
$handler->handle($this->getRecord());
$this->assertEquals(6, count($handledRecord['extra']));
$this->assertEquals(6, \count($handledRecord['extra']));
}
/**

View File

@@ -27,7 +27,7 @@ class DynamoDbHandlerTest extends TestCase
$this->markTestSkipped('aws/aws-sdk-php not installed');
}
$this->isV3 = defined('Aws\Sdk::VERSION') && version_compare(\Aws\Sdk::VERSION, '3.0', '>=');
$this->isV3 = \defined('Aws\Sdk::VERSION') && version_compare(\Aws\Sdk::VERSION, '3.0', '>=');
$implementedMethods = ['__call'];

View File

@@ -17,7 +17,7 @@ use Monolog\Formatter\LineFormatter;
function error_log()
{
$GLOBALS['error_log'][] = func_get_args();
$GLOBALS['error_log'][] = \func_get_args();
}
class ErrorLogHandlerTest extends TestCase

View File

@@ -31,7 +31,7 @@ class FleepHookHandlerTest extends TestCase
{
parent::setUp();
if (!extension_loaded('openssl')) {
if (!\extension_loaded('openssl')) {
$this->markTestSkipped('This test requires openssl extension to run');
}

View File

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

View File

@@ -59,7 +59,7 @@ class InsightOpsHandlerTest extends TestCase
private function createHandler()
{
$useSSL = extension_loaded('openssl');
$useSSL = \extension_loaded('openssl');
$args = ['testToken', 'us', $useSSL, Level::Debug, true];
$this->resource = fopen('php://memory', 'a');
$this->handler = $this->getMockBuilder(InsightOpsHandler::class)

View File

@@ -63,7 +63,7 @@ class LogEntriesHandlerTest extends TestCase
private function createHandler()
{
$useSSL = extension_loaded('openssl');
$useSSL = \extension_loaded('openssl');
$args = ['testToken', $useSSL, Level::Debug, true];
$this->res = fopen('php://memory', 'a');
$this->handler = $this->getMockBuilder('Monolog\Handler\LogEntriesHandler')

View File

@@ -63,7 +63,7 @@ class LogmaticHandlerTest extends TestCase
private function createHandler()
{
$useSSL = extension_loaded('openssl');
$useSSL = \extension_loaded('openssl');
$args = ['testToken', 'testHostname', 'testAppname', $useSSL, Level::Debug, true];
$this->res = fopen('php://memory', 'a');
$this->handler = $this->getMockBuilder('Monolog\Handler\LogmaticHandler')

View File

@@ -16,7 +16,7 @@ use Monolog\Test\TestCase;
function mail($to, $subject, $message, $additional_headers = null, $additional_parameters = null)
{
$GLOBALS['mail'][] = func_get_args();
$GLOBALS['mail'][] = \func_get_args();
}
class NativeMailerHandlerTest extends TestCase

View File

@@ -143,7 +143,7 @@ class PHPConsoleHandlerTest extends TestCase
$message = 'test';
$tag = 'tag';
$context = [$tag, 'custom' => mt_rand()];
$expectedMessage = $message . ' ' . json_encode(array_slice($context, 1));
$expectedMessage = $message . ' ' . json_encode(\array_slice($context, 1));
$this->debugDispatcher->expects($this->once())->method('dispatchDebug')->with(
$this->equalTo($expectedMessage),
$this->equalTo($tag)
@@ -197,7 +197,7 @@ class PHPConsoleHandlerTest extends TestCase
$handler = $this->initLogger();
$handler->log(
\Psr\Log\LogLevel::ERROR,
sprintf('Uncaught Exception %s: "%s" at %s line %s', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()),
sprintf('Uncaught Exception %s: "%s" at %s line %s', \get_class($e), $e->getMessage(), $e->getFile(), $e->getLine()),
['exception' => $e]
);
}

View File

@@ -190,11 +190,11 @@ class ProcessHandlerTest extends TestCase
$handler->handle($this->getRecord(Level::Warning, '21 is only the half truth'));
$process = $property->getValue($handler);
$this->assertTrue(is_resource($process), 'Process is not running although it should.');
$this->assertTrue(\is_resource($process), 'Process is not running although it should.');
$handler->close();
$process = $property->getValue($handler);
$this->assertFalse(is_resource($process), 'Process is still running although it should not.');
$this->assertFalse(\is_resource($process), 'Process is still running although it should not.');
}
}

View File

@@ -64,7 +64,7 @@ class RotatingFileHandlerTest extends TestCase
throw new InvalidArgumentException("$directory must be a directory");
}
if (substr($directory, strlen($directory) - 1, 1) !== '/') {
if (substr($directory, \strlen($directory) - 1, 1) !== '/') {
$directory .= '/';
}
@@ -169,7 +169,7 @@ class RotatingFileHandlerTest extends TestCase
private function createDeep($file)
{
mkdir(dirname($file), 0777, true);
mkdir(\dirname($file), 0777, true);
touch($file);
return $file;

View File

@@ -25,7 +25,7 @@ class SamplingHandlerTest extends TestCase
for ($i = 0; $i < 10000; $i++) {
$handler->handle($this->getRecord());
}
$count = count($testHandler->getRecords());
$count = \count($testHandler->getRecords());
// $count should be half of 10k, so between 4k and 6k
$this->assertLessThan(6000, $count);
$this->assertGreaterThan(4000, $count);

View File

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

View File

@@ -198,7 +198,7 @@ class SocketHandlerTest extends TestCase
$callback = function ($string) use ($res) {
fclose($res);
return strlen('Hello');
return \strlen('Hello');
};
$this->handler->expects($this->exactly(1))
@@ -249,7 +249,7 @@ class SocketHandlerTest extends TestCase
$this->writeRecord('Hello world');
$this->assertIsResource($this->res);
$this->handler->close();
$this->assertFalse(is_resource($this->res), "Expected resource to be closed after closing handler");
$this->assertFalse(\is_resource($this->res), "Expected resource to be closed after closing handler");
}
public function testCloseDoesNotClosePersistentSocket()
@@ -257,9 +257,9 @@ class SocketHandlerTest extends TestCase
$this->setMockHandler();
$this->handler->setPersistent(true);
$this->writeRecord('Hello world');
$this->assertTrue(is_resource($this->res));
$this->assertTrue(\is_resource($this->res));
$this->handler->close();
$this->assertTrue(is_resource($this->res));
$this->assertTrue(\is_resource($this->res));
}
public function testAvoidInfiniteLoopWhenNoDataIsWrittenForAWritingTimeoutSeconds()
@@ -308,25 +308,25 @@ class SocketHandlerTest extends TestCase
->setConstructorArgs(['localhost:1234'])
->getMock();
if (!in_array('fsockopen', $methods)) {
if (!\in_array('fsockopen', $methods)) {
$this->handler->expects($this->any())
->method('fsockopen')
->willReturn($this->res);
}
if (!in_array('pfsockopen', $methods)) {
if (!\in_array('pfsockopen', $methods)) {
$this->handler->expects($this->any())
->method('pfsockopen')
->willReturn($this->res);
}
if (!in_array('streamSetTimeout', $methods)) {
if (!\in_array('streamSetTimeout', $methods)) {
$this->handler->expects($this->any())
->method('streamSetTimeout')
->willReturn(true);
}
if (!in_array('streamSetChunkSize', $methods)) {
if (!\in_array('streamSetChunkSize', $methods)) {
$this->handler->expects($this->any())
->method('streamSetChunkSize')
->willReturn(8192);

View File

@@ -40,9 +40,9 @@ class StreamHandlerTest extends TestCase
{
$handle = fopen('php://memory', 'a+');
$handler = new StreamHandler($handle);
$this->assertTrue(is_resource($handle));
$this->assertTrue(\is_resource($handle));
$handler->close();
$this->assertTrue(is_resource($handle));
$this->assertTrue(\is_resource($handle));
}
/**
@@ -54,9 +54,9 @@ class StreamHandlerTest extends TestCase
$handler->handle($this->getRecord(Level::Warning, 'test'));
$stream = $handler->getStream();
$this->assertTrue(is_resource($stream));
$this->assertTrue(\is_resource($stream));
$handler->close();
$this->assertFalse(is_resource($stream));
$this->assertFalse(\is_resource($stream));
}
/**
@@ -69,17 +69,17 @@ class StreamHandlerTest extends TestCase
$handler->handle($this->getRecord(Level::Warning, 'testfoo'));
$stream = $handler->getStream();
$this->assertTrue(is_resource($stream));
$this->assertTrue(\is_resource($stream));
fseek($stream, 0);
$this->assertStringContainsString('testfoo', stream_get_contents($stream));
$serialized = serialize($handler);
$this->assertFalse(is_resource($stream));
$this->assertFalse(\is_resource($stream));
$handler = unserialize($serialized);
$handler->handle($this->getRecord(Level::Warning, 'testbar'));
$stream = $handler->getStream();
$this->assertTrue(is_resource($stream));
$this->assertTrue(\is_resource($stream));
fseek($stream, 0);
$contents = stream_get_contents($stream);
$this->assertStringNotContainsString('testfoo', $contents);
@@ -212,7 +212,7 @@ STRING;
#[DataProvider('provideNonExistingAndNotCreatablePath')]
public function testWriteNonExistingAndNotCreatablePath($nonExistingAndNotCreatablePath)
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
if (\defined('PHP_WINDOWS_VERSION_BUILD')) {
$this->markTestSkipped('Permissions checks can not run on windows');
}

View File

@@ -68,7 +68,7 @@ class SymfonyMailerHandlerTest extends TestCase
// Callback dynamically changes subject based on number of logged records
$callback = function ($content, array $records) use ($expectedMessage) {
$subject = count($records) > 0 ? 'Emergency' : 'Normal';
$subject = \count($records) > 0 ? 'Emergency' : 'Normal';
return $expectedMessage->subject($subject);
};
$handler = new SymfonyMailerHandler($this->mailer, $callback);

View File

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

View File

@@ -746,7 +746,7 @@ class LoggerTest extends TestCase
$logger->pushProcessor($processorUid2);
$getProperty = function ($object, $property) {
$reflectionProperty = new \ReflectionProperty(get_class($object), $property);
$reflectionProperty = new \ReflectionProperty(\get_class($object), $property);
$reflectionProperty->setAccessible(true);
return $reflectionProperty->getValue($object);

View File

@@ -25,7 +25,7 @@ class GitProcessorTest extends TestCase
$record = $processor($this->getRecord());
$this->assertArrayHasKey('git', $record->extra);
$this->assertTrue(!is_array($record->extra['git']['branch']));
$this->assertTrue(!\is_array($record->extra['git']['branch']));
}
/**

View File

@@ -20,7 +20,7 @@ class MercurialProcessorTest extends TestCase
*/
public function testProcessor()
{
if (defined('PHP_WINDOWS_VERSION_BUILD')) {
if (\defined('PHP_WINDOWS_VERSION_BUILD')) {
exec("where hg 2>NUL", $output, $result);
} else {
exec("which hg 2>/dev/null >/dev/null", $output, $result);
@@ -36,7 +36,7 @@ class MercurialProcessorTest extends TestCase
$record = $processor($this->getRecord());
$this->assertArrayHasKey('hg', $record->extra);
$this->assertTrue(!is_array($record->extra['hg']['branch']));
$this->assertTrue(!is_array($record->extra['hg']['revision']));
$this->assertTrue(!\is_array($record->extra['hg']['branch']));
$this->assertTrue(!\is_array($record->extra['hg']['revision']));
}
}

View File

@@ -28,6 +28,6 @@ class UidProcessorTest extends TestCase
public function testGetUid()
{
$processor = new UidProcessor(10);
$this->assertEquals(10, strlen($processor->getUid()));
$this->assertEquals(10, \strlen($processor->getUid()));
}
}

View File

@@ -30,11 +30,11 @@ class SignalHandlerTest extends TestCase
protected function setUp(): void
{
$this->signalHandlers = [];
if (extension_loaded('pcntl')) {
if (function_exists('pcntl_async_signals')) {
if (\extension_loaded('pcntl')) {
if (\function_exists('pcntl_async_signals')) {
$this->asyncSignalHandling = pcntl_async_signals();
}
if (function_exists('pcntl_sigprocmask')) {
if (\function_exists('pcntl_sigprocmask')) {
pcntl_sigprocmask(SIG_SETMASK, [], $this->blockedSignals);
}
}
@@ -62,7 +62,7 @@ class SignalHandlerTest extends TestCase
private function setSignalHandler($signo, $handler = SIG_DFL)
{
if (function_exists('pcntl_signal_get_handler')) {
if (\function_exists('pcntl_signal_get_handler')) {
$this->signalHandlers[$signo] = pcntl_signal_get_handler($signo);
} else {
$this->signalHandlers[$signo] = SIG_DFL;
@@ -95,7 +95,7 @@ class SignalHandlerTest extends TestCase
public function testRegisterSignalHandler()
{
// SIGCONT and SIGURG should be ignored by default.
if (!defined('SIGCONT') || !defined('SIGURG')) {
if (!\defined('SIGCONT') || !\defined('SIGURG')) {
$this->markTestSkipped('This test requires the SIGCONT and SIGURG pcntl constants.');
}
@@ -162,7 +162,7 @@ class SignalHandlerTest extends TestCase
public static function defaultPreviousProvider()
{
if (!defined('SIGCONT') || !defined('SIGINT') || !defined('SIGURG')) {
if (!\defined('SIGCONT') || !\defined('SIGINT') || !\defined('SIGURG')) {
return [];
}