1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-09 14:46:46 +02:00

Upgrade to phpunit 10 (#1806)

Co-authored-by: Christopher Georg <christopher.georg@sr-travel.de>
This commit is contained in:
chris
2023-06-20 15:56:11 +02:00
committed by GitHub
parent 50409b8169
commit 8561130215
28 changed files with 106 additions and 85 deletions

View File

@@ -77,7 +77,7 @@ jobs:
composer-options: "${{ matrix.composer-options }}"
- name: "Run tests"
run: "composer exec phpunit -- --exclude-group Elasticsearch,Elastica --verbose"
run: "composer exec phpunit -- --exclude-group Elasticsearch,Elastica"
- name: "Run tests with psr/log 3"
if: "contains(matrix.dependencies, 'highest') && matrix.php-version >= '8.0'"
@@ -85,7 +85,7 @@ jobs:
composer remove --no-update --dev graylog2/gelf-php ruflin/elastica elasticsearch/elasticsearch rollbar/rollbar
composer require --no-update psr/log:^3
composer update ${{ matrix.composer-options }}
composer exec phpunit -- --exclude-group Elasticsearch,Elastica --verbose
composer exec phpunit -- --exclude-group Elasticsearch,Elastica
tests-es-7:
name: "CI with ES ${{ matrix.es-version }} on PHP ${{ matrix.php-version }}"
@@ -152,7 +152,7 @@ jobs:
dependency-versions: "${{ matrix.dependencies }}"
- name: "Run tests"
run: "composer exec phpunit -- --group Elasticsearch,Elastica --verbose"
run: "composer exec phpunit -- --group Elasticsearch,Elastica"
- name: "Run tests with psr/log 3"
if: "contains(matrix.dependencies, 'highest') && matrix.php-version >= '8.0'"
@@ -161,7 +161,7 @@ jobs:
composer require --no-update --no-interaction --dev ruflin/elastica elasticsearch/elasticsearch:^7
composer require --no-update psr/log:^3
composer update -W
composer exec phpunit -- --group Elasticsearch,Elastica --verbose
composer exec phpunit -- --group Elasticsearch,Elastica
tests-es-8:
name: "CI with ES ${{ matrix.es-version }} on PHP ${{ matrix.php-version }}"
@@ -230,11 +230,11 @@ jobs:
dependency-versions: "${{ matrix.dependencies }}"
- name: "Run tests"
run: "composer exec phpunit -- --group Elasticsearch,Elastica --verbose"
run: "composer exec phpunit -- --group Elasticsearch,Elastica"
- name: "Run tests with psr/log 3"
if: "contains(matrix.dependencies, 'highest') && matrix.php-version >= '8.0'"
run: |
composer require --no-update psr/log:^3
composer update -W
composer exec phpunit -- --group Elasticsearch,Elastica --verbose
composer exec phpunit -- --group Elasticsearch,Elastica

1
.gitignore vendored
View File

@@ -6,3 +6,4 @@ composer.lock
.php-cs-fixer.cache
.hg
.phpunit.result.cache
.phpunit.cache

View File

@@ -29,7 +29,7 @@
"phpstan/phpstan": "^1.9",
"phpstan/phpstan-deprecation-rules": "^1.0",
"phpstan/phpstan-strict-rules": "^1.4",
"phpunit/phpunit": "^9.5.26",
"phpunit/phpunit": "^10.1",
"predis/predis": "^1.1 || ^2",
"ruflin/elastica": "^7",
"symfony/mailer": "^5.4 || ^6",

View File

@@ -1,24 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="tests/bootstrap.php" colors="true"
beStrictAboutTestsThatDoNotTestAnything="false"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="tests/bootstrap.php"
colors="true"
beStrictAboutTestsThatDoNotTestAnything="false">
<testsuites>
<testsuite name="Monolog Test Suite">
<directory>tests/Monolog/</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">src/Monolog/</directory>
</include>
</coverage>
<coverage/>
<php>
<ini name="date.timezone" value="UTC"/>
</php>
<source>
<include>
<directory suffix=".php">src/Monolog/</directory>
</include>
</source>
</phpunit>

View File

@@ -51,7 +51,7 @@ class ErrorHandlerTest extends \PHPUnit\Framework\TestCase
}
}
public function fatalHandlerProvider()
public static function fatalHandlerProvider()
{
return [
[null, 10, str_repeat(' ', 1024 * 10), LogLevel::ALERT],

View File

@@ -327,7 +327,7 @@ class TestJsonNormPrivate
class TestJsonNormWithToStringAndJson implements JsonSerializable
{
public function jsonSerialize()
public function jsonSerialize(): mixed
{
return ['json serialized'];
}

View File

@@ -160,15 +160,15 @@ class LineFormatterTest extends TestCase
$trace = explode('[stacktrace]', $message, 2)[1];
$this->assertStringContainsString('TestCase.php', $trace);
$this->assertStringContainsString('TestResult.php', $trace);
$this->assertStringContainsString('TestSuite.php', $trace);
$this->assertStringContainsString('TestRunner.php', $trace);
}
public function testDefFormatWithExceptionAndStacktraceParserCustom()
{
$formatter = new LineFormatter(null, 'Y-m-d');
$formatter->includeStacktraces(true, function ($line) {
if (strpos($line, 'TestCase.php') === false) {
if (strpos($line, 'TestSuite.php') === false) {
return $line;
}
});
@@ -177,8 +177,8 @@ class LineFormatterTest extends TestCase
$trace = explode('[stacktrace]', $message, 2)[1];
$this->assertStringNotContainsString('TestCase.php', $trace);
$this->assertStringContainsString('TestResult.php', $trace);
$this->assertStringNotContainsString('TestSuite.php', $trace);
$this->assertStringContainsString('TestRunner.php', $trace);
}
public function testDefFormatWithExceptionAndStacktraceParserEmpty()

View File

@@ -29,7 +29,7 @@ class MongoDBFormatterTest extends TestCase
}
}
public function constructArgumentProvider()
public static function constructArgumentProvider()
{
return [
[1, true, 1, true],

View File

@@ -64,7 +64,7 @@ class SyslogFormatterTest extends TestCase
/**
* @return mixed[]
*/
public function formatDataProvider(): array
public static function formatDataProvider(): array
{
return [
'error' => [

View File

@@ -146,7 +146,7 @@ class ElasticaHandlerTest extends TestCase
}
}
public function providerTestConnectionErrors(): array
public static function providerTestConnectionErrors(): array
{
return [
[false, ['RuntimeException', 'Error sending messages to Elasticsearch']],

View File

@@ -128,7 +128,7 @@ class ElasticsearchHandlerTest extends TestCase
}
}
public function providerTestConnectionErrors(): array
public static function providerTestConnectionErrors(): array
{
return [
[false, ['RuntimeException', 'Error sending messages to Elasticsearch']],

View File

@@ -37,7 +37,7 @@ class HandlerWrapperTest extends TestCase
unset($this->wrapper);
}
public function trueFalseDataProvider(): array
public static function trueFalseDataProvider(): array
{
return [
[true],

View File

@@ -37,7 +37,7 @@ class NoopHandlerTest extends TestCase
$this->assertFalse($handler->handle($this->getRecord($level)));
}
public function logLevelsProvider()
public static function logLevelsProvider()
{
return array_map(
fn ($level) => [$level],

View File

@@ -46,9 +46,16 @@ class ProcessHandlerTest extends TestCase
$handler = $mockBuilder->getMock();
$handler->expects($this->exactly(2))
$matcher = $this->exactly(2);
$handler->expects($matcher)
->method('writeProcessInput')
->withConsecutive([$this->stringContains($fixtures[0])], [$this->stringContains($fixtures[1])]);
->willReturnCallback(function () use ($matcher, $fixtures) {
match ($matcher->numberOfInvocations()) {
1 => $this->stringContains($fixtures[0]),
2 => $this->stringContains($fixtures[1]),
};
})
;
/** @var ProcessHandler $handler */
$handler->handle($this->getRecord(Level::Warning, $fixtures[0]));
@@ -58,7 +65,7 @@ class ProcessHandlerTest extends TestCase
/**
* Data provider for invalid commands.
*/
public function invalidCommandProvider(): array
public static function invalidCommandProvider(): array
{
return [
[1337, 'TypeError'],
@@ -82,7 +89,7 @@ class ProcessHandlerTest extends TestCase
/**
* Data provider for invalid CWDs.
*/
public function invalidCwdProvider(): array
public static function invalidCwdProvider(): array
{
return [
[1337, 'TypeError'],

View File

@@ -20,7 +20,7 @@ use Monolog\Formatter\LineFormatter;
*/
class PsrHandlerTest extends TestCase
{
public function logLevelProvider()
public static function logLevelProvider()
{
return array_map(
fn (Level $level) => [$level->toPsrLogLevel(), $level],

View File

@@ -47,7 +47,7 @@ class RotatingFileHandlerTest extends TestCase
unlink($file);
}
if ('testRotationWithFolderByDate' === $this->getName(false)) {
if ('testRotationWithFolderByDate' === $this->name()) {
foreach (glob(__DIR__.'/Fixtures/[0-9]*') as $folder) {
$this->rrmdir($folder);
}
@@ -137,7 +137,7 @@ class RotatingFileHandlerTest extends TestCase
$this->assertEquals('test', file_get_contents($log));
}
public function rotationTests()
public static function rotationTests()
{
$now = time();
$dayCallback = function ($ago) use ($now) {
@@ -207,7 +207,7 @@ class RotatingFileHandlerTest extends TestCase
$this->assertEquals('test', file_get_contents($log));
}
public function rotationWithFolderByDateTests()
public static function rotationWithFolderByDateTests()
{
$now = time();
$dayCallback = function ($ago) use ($now) {
@@ -252,7 +252,7 @@ class RotatingFileHandlerTest extends TestCase
$this->assertTrue(true);
}
public function dateFormatProvider()
public static function dateFormatProvider()
{
return [
[RotatingFileHandler::FILE_PER_DAY, true],
@@ -293,7 +293,7 @@ class RotatingFileHandlerTest extends TestCase
$handler->setFilenameFormat($filenameFormat, RotatingFileHandler::FILE_PER_DAY);
}
public function filenameFormatProvider()
public static function filenameFormatProvider()
{
return [
['{filename}', false],
@@ -326,7 +326,7 @@ class RotatingFileHandlerTest extends TestCase
$this->assertTrue(file_exists($log));
}
public function rotationWhenSimilarFilesExistTests()
public static function rotationWhenSimilarFilesExistTests()
{
return [
'Rotation is triggered when the file of the current day is not present but similar exists'

View File

@@ -19,7 +19,7 @@ use Monolog\Test\TestCase;
*/
class SlackRecordTest extends TestCase
{
public function dataGetAttachmentColor()
public static function dataGetAttachmentColor()
{
return [
[Level::Debug, SlackRecord::COLOR_DEFAULT],
@@ -64,7 +64,7 @@ class SlackRecordTest extends TestCase
$this->assertArrayNotHasKey('username', $data);
}
public function dataStringify(): array
public static function dataStringify(): array
{
$multipleDimensions = [[1, 2]];
$numericKeys = ['library' => 'monolog'];

View File

@@ -116,7 +116,7 @@ class SlackHandlerTest extends TestCase
$this->assertMatchesRegularExpression('/text=test1/', $content);
}
public function provideLevelColors()
public static function provideLevelColors()
{
return [
[Level::Debug, urlencode(SlackRecord::COLOR_DEFAULT)],

View File

@@ -117,7 +117,7 @@ class StreamHandlerTest extends TestCase
$handler->handle($this->getRecord());
}
public function invalidArgumentProvider()
public static function invalidArgumentProvider()
{
return [
[1],
@@ -232,7 +232,7 @@ STRING;
$handler->handle($this->getRecord());
}
public function provideNonExistingAndNotCreatablePath()
public static function provideNonExistingAndNotCreatablePath()
{
return [
'/foo/bar/…' => [
@@ -244,7 +244,7 @@ STRING;
];
}
public function provideMemoryValues()
public static function provideMemoryValues()
{
return [
['1M', (int) (1024*1024/10)],

View File

@@ -39,12 +39,18 @@ class SyslogUdpHandlerTest extends TestCase
->onlyMethods(['write'])
->setConstructorArgs(['lol'])
->getMock();
$socket->expects($this->atLeast(2))
$matcher = $this->atLeast(2);
$socket->expects($matcher)
->method('write')
->withConsecutive(
[$this->equalTo("lol"), $this->equalTo("<".(LOG_AUTHPRIV + LOG_WARNING).">1 $time $host php $pid - - ")],
[$this->equalTo("hej"), $this->equalTo("<".(LOG_AUTHPRIV + LOG_WARNING).">1 $time $host php $pid - - ")],
);
->willReturnCallback(function () use ($matcher, $time, $host, $pid) {
match ($matcher->numberOfInvocations()) {
1 => $this->equalTo("lol") && $this->equalTo("<".(LOG_AUTHPRIV + LOG_WARNING).">1 $time $host php $pid - - "),
2 => $this->equalTo("hej") && $this->equalTo("<".(LOG_AUTHPRIV + LOG_WARNING).">1 $time $host php $pid - - "),
default => $this->assertTrue(true)
};
});
$handler->setSocket($socket);
@@ -85,12 +91,18 @@ class SyslogUdpHandlerTest extends TestCase
->setConstructorArgs(['lol', 999])
->onlyMethods(['write'])
->getMock();
$socket->expects($this->atLeast(2))
$matcher = $this->atLeast(2);
$socket->expects($matcher)
->method('write')
->withConsecutive(
[$this->equalTo("lol"), $this->equalTo("<".(LOG_AUTHPRIV + LOG_WARNING).">$time $host php[$pid]: ")],
[$this->equalTo("hej"), $this->equalTo("<".(LOG_AUTHPRIV + LOG_WARNING).">$time $host php[$pid]: ")],
);
->willReturnCallback(function () use ($matcher, $time, $host, $pid) {
match ($matcher->numberOfInvocations()) {
1 => $this->equalTo("lol") && $this->equalTo("<".(LOG_AUTHPRIV + LOG_WARNING).">$time $host php[$pid]: "),
2 => $this->equalTo("hej") && $this->equalTo("<".(LOG_AUTHPRIV + LOG_WARNING).">$time $host php[$pid]: "),
default => $this->assertTrue(true)
};
});
$handler->setSocket($socket);

View File

@@ -102,7 +102,7 @@ class TestHandlerTest extends TestCase
]));
}
public function methodProvider()
public static function methodProvider()
{
return [
['Emergency', Level::Emergency],

View File

@@ -517,7 +517,7 @@ class LoggerTest extends TestCase
$this->assertEquals($expectedLevel, $record->level);
}
public function logMethodProvider()
public static function logMethodProvider()
{
return [
// PSR-3 methods
@@ -547,7 +547,7 @@ class LoggerTest extends TestCase
$this->assertEquals($tz, $record->datetime->getTimezone());
}
public function setTimezoneProvider()
public static function setTimezoneProvider()
{
return array_map(
function ($tz) {
@@ -628,7 +628,7 @@ class LoggerTest extends TestCase
$this->assertSame($record->datetime->format($assertFormat), (string) $record->datetime);
}
public function useMicrosecondTimestampsProvider()
public static function useMicrosecondTimestampsProvider()
{
return [
// this has a very small chance of a false negative (1/10^6)

View File

@@ -57,7 +57,7 @@ class ClosureContextProcessorTest extends TestCase
$this->assertSame($expected, $record->context);
}
public function getContexts(): iterable
public static function getContexts(): iterable
{
yield [['foo']];
yield [['foo' => 'bar']];

View File

@@ -49,7 +49,7 @@ class PsrLogMessageProcessorTest extends TestCase
$this->assertSame(['foo' => $date], $message['context']);
}
public function getPairs()
public static function getPairs()
{
$date = new \DateTime();

View File

@@ -79,7 +79,7 @@ class PsrLogCompatTest extends TestCase
$this->assertEquals($expected, $this->getLogs());
}
public function provideLevelsAndMessages()
public static function provideLevelsAndMessages()
{
return [
LogLevel::EMERGENCY => [LogLevel::EMERGENCY, 'message of level emergency with context: {user}'],

View File

@@ -32,7 +32,7 @@ class RegistryTest extends \PHPUnit\Framework\TestCase
}
}
public function hasLoggerProvider()
public static function hasLoggerProvider()
{
$logger1 = new Logger('test1');
$logger2 = new Logger('test2');
@@ -86,7 +86,7 @@ class RegistryTest extends \PHPUnit\Framework\TestCase
Registry::getInstance($loggerToAdd->getName());
}
public function removedLoggerProvider()
public static function removedLoggerProvider()
{
$logger1 = new Logger('test1');

View File

@@ -159,7 +159,7 @@ class SignalHandlerTest extends TestCase
$this->assertSame($expected, file_get_contents($path));
}
public function defaultPreviousProvider()
public static function defaultPreviousProvider()
{
if (!defined('SIGCONT') || !defined('SIGINT') || !defined('SIGURG')) {
return [];
@@ -196,7 +196,7 @@ class SignalHandlerTest extends TestCase
$this->assertSame($callPrevious ? 1 : 0, $previousCalled);
}
public function callablePreviousProvider()
public static function callablePreviousProvider()
{
return [
[false],
@@ -248,7 +248,7 @@ class SignalHandlerTest extends TestCase
}
}
public function restartSyscallsProvider()
public static function restartSyscallsProvider()
{
return [
[false],
@@ -277,7 +277,7 @@ class SignalHandlerTest extends TestCase
$this->assertCount($expectedAfter, $handler->getRecords());
}
public function asyncProvider()
public static function asyncProvider()
{
return [
[false, false, 0, 1],

View File

@@ -21,7 +21,7 @@ class UtilsTest extends \PHPUnit_Framework_TestCase
$this->assertSame($expected, Utils::getClass($object));
}
public function provideObjects()
public static function provideObjects()
{
return [
['stdClass', new \stdClass()],
@@ -40,7 +40,7 @@ class UtilsTest extends \PHPUnit_Framework_TestCase
$this->assertSame($expected, Utils::canonicalizePath($input));
}
public function providePathsToCanonicalize()
public static function providePathsToCanonicalize()
{
return [
['/foo/bar', '/foo/bar'],
@@ -62,7 +62,7 @@ class UtilsTest extends \PHPUnit_Framework_TestCase
Utils::handleJsonError($code, 'faked');
}
public function providesHandleJsonErrorFailure()
public static function providesHandleJsonErrorFailure()
{
return [
'depth' => [JSON_ERROR_DEPTH, 'Maximum stack depth exceeded'],
@@ -87,7 +87,7 @@ class UtilsTest extends \PHPUnit_Framework_TestCase
$this->assertSame($expect, $in);
}
public function providesDetectAndCleanUtf8()
public static function providesDetectAndCleanUtf8()
{
$obj = new \stdClass;
@@ -123,7 +123,7 @@ class UtilsTest extends \PHPUnit_Framework_TestCase
/**
* @return array[]
*/
public function providesPcreLastErrorMessage(): array
public static function providesPcreLastErrorMessage(): array
{
return [
[0, 'PREG_NO_ERROR'],
@@ -137,7 +137,7 @@ class UtilsTest extends \PHPUnit_Framework_TestCase
];
}
public function provideIniValuesToConvertToBytes()
public static function provideIniValuesToConvertToBytes()
{
return [
['1', 1],