Bladeren bron

Upgrade to phpunit 10 (#1806)

Co-authored-by: Christopher Georg <christopher.georg@sr-travel.de>
chris 2 jaren geleden
bovenliggende
commit
8561130215

+ 6 - 6
.github/workflows/continuous-integration.yml

@@ -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 - 0
.gitignore

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

+ 1 - 1
composer.json

@@ -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",

+ 20 - 19
phpunit.xml.dist

@@ -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">
+  <testsuites>
+    <testsuite name="Monolog Test Suite">
+      <directory>tests/Monolog/</directory>
+    </testsuite>
+  </testsuites>
 
-<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/>
 
-    <coverage>
-        <include>
-            <directory suffix=".php">src/Monolog/</directory>
-        </include>
-    </coverage>
+  <php>
+    <ini name="date.timezone" value="UTC"/>
+  </php>
+
+  <source>
+    <include>
+      <directory suffix=".php">src/Monolog/</directory>
+    </include>
+  </source>
 
-    <php>
-        <ini name="date.timezone" value="UTC"/>
-    </php>
 </phpunit>

+ 1 - 1
tests/Monolog/ErrorHandlerTest.php

@@ -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],

+ 1 - 1
tests/Monolog/Formatter/JsonFormatterTest.php

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

+ 5 - 5
tests/Monolog/Formatter/LineFormatterTest.php

@@ -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()

+ 1 - 1
tests/Monolog/Formatter/MongoDBFormatterTest.php

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

+ 1 - 1
tests/Monolog/Formatter/SyslogFormatterTest.php

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

+ 1 - 1
tests/Monolog/Handler/ElasticaHandlerTest.php

@@ -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']],

+ 1 - 1
tests/Monolog/Handler/ElasticsearchHandlerTest.php

@@ -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']],

+ 1 - 1
tests/Monolog/Handler/HandlerWrapperTest.php

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

+ 1 - 1
tests/Monolog/Handler/NoopHandlerTest.php

@@ -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],

+ 11 - 4
tests/Monolog/Handler/ProcessHandlerTest.php

@@ -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'],

+ 1 - 1
tests/Monolog/Handler/PsrHandlerTest.php

@@ -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],

+ 6 - 6
tests/Monolog/Handler/RotatingFileHandlerTest.php

@@ -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'

+ 2 - 2
tests/Monolog/Handler/Slack/SlackRecordTest.php

@@ -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'];

+ 1 - 1
tests/Monolog/Handler/SlackHandlerTest.php

@@ -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)],

+ 3 - 3
tests/Monolog/Handler/StreamHandlerTest.php

@@ -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)],

+ 22 - 10
tests/Monolog/Handler/SyslogUdpHandlerTest.php

@@ -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);
 

+ 1 - 1
tests/Monolog/Handler/TestHandlerTest.php

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

+ 3 - 3
tests/Monolog/LoggerTest.php

@@ -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)

+ 1 - 1
tests/Monolog/Processor/ClosureContextProcessorTest.php

@@ -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']];

+ 1 - 1
tests/Monolog/Processor/PsrLogMessageProcessorTest.php

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

+ 1 - 1
tests/Monolog/PsrLogCompatTest.php

@@ -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}'],

+ 2 - 2
tests/Monolog/RegistryTest.php

@@ -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');
 

+ 4 - 4
tests/Monolog/SignalHandlerTest.php

@@ -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],

+ 6 - 6
tests/Monolog/UtilsTest.php

@@ -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],