From d39ffff2f6b752b7f18c85e74e6f2592b2dd5ad5 Mon Sep 17 00:00:00 2001
From: Sergei Predvoditelev <sergei@predvoditelev.ru>
Date: Sun, 7 Jan 2024 14:52:35 +0300
Subject: [PATCH] Raise PhpUnit to `^10.5` + Improve CI + Remove
 asset-packagist.org usage (#238)

---
 .github/PULL_REQUEST_TEMPLATE.md              |  1 -
 .github/dependabot.yml                        | 26 ++++++------
 .github/workflows/bc.yml_                     | 40 ++++++++++++++-----
 .github/workflows/build.yml                   |  1 +
 .../workflows/composer-require-checker.yml    |  3 +-
 .github/workflows/mutation.yml                |  3 +-
 .github/workflows/rector.yml                  |  4 +-
 .github/workflows/static.yml                  |  1 +
 .gitignore                                    |  8 ++--
 composer.json                                 |  8 +---
 phpunit.xml.dist                              | 30 ++++++++------
 .../FilesystemStreamCollectorTest.php         |  7 ++--
 .../Collector/HttpStreamCollectorTest.php     | 34 ++++++++--------
 tests/Unit/DebugServiceProviderTest.php       |  7 ----
 tests/Unit/ProxyServiceProviderTest.php       |  7 ----
 ...geTest.php => AbstractStorageTestCase.php} |  2 +-
 tests/Unit/Storage/FileStorageTest.php        |  2 +-
 tests/Unit/Storage/MemoryStorageTest.php      |  2 +-
 18 files changed, 96 insertions(+), 90 deletions(-)
 rename tests/Unit/Storage/{AbstractStorageTest.php => AbstractStorageTestCase.php} (98%)

diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
index 4a3e8ace9..6be5d5871 100644
--- a/.github/PULL_REQUEST_TEMPLATE.md
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -3,4 +3,3 @@
 | Is bugfix?    | ✔️/❌
 | New feature?  | ✔️/❌
 | Breaks BC?    | ✔️/❌
-| Fixed issues  | comma-separated list of tickets # fixed by the PR, if any
diff --git a/.github/dependabot.yml b/.github/dependabot.yml
index d7ebdbfdb..db86156d1 100644
--- a/.github/dependabot.yml
+++ b/.github/dependabot.yml
@@ -1,16 +1,16 @@
 version: 2
 updates:
-    # Maintain dependencies for GitHub Actions.
-    - package-ecosystem: "github-actions"
-      directory: "/"
-      schedule:
-          interval: "daily"
-      # Too noisy. See https://github.community/t/increase-if-necessary-for-github-actions-in-dependabot/179581
-      open-pull-requests-limit: 0
+  # Maintain dependencies for GitHub Actions.
+  - package-ecosystem: "github-actions"
+    directory: "/"
+    schedule:
+      interval: "daily"
+    # Too noisy. See https://github.community/t/increase-if-necessary-for-github-actions-in-dependabot/179581
+    open-pull-requests-limit: 0
 
-    # Maintain dependencies for Composer
-    - package-ecosystem: "composer"
-      directory: "/"
-      schedule:
-          interval: "daily"
-      versioning-strategy: increase-if-necessary
+  # Maintain dependencies for Composer
+  - package-ecosystem: "composer"
+    directory: "/"
+    schedule:
+      interval: "daily"
+    versioning-strategy: increase-if-necessary
diff --git a/.github/workflows/bc.yml_ b/.github/workflows/bc.yml_
index 35b3a8624..00041a9f4 100644
--- a/.github/workflows/bc.yml_
+++ b/.github/workflows/bc.yml_
@@ -1,15 +1,33 @@
 on:
-    - pull_request
-    - push
+  pull_request:
+    paths-ignore:
+      - 'docs/**'
+      - 'README.md'
+      - 'CHANGELOG.md'
+      - '.gitignore'
+      - '.gitattributes'
+      - 'infection.json.dist'
+      - 'phpunit.xml.dist'
+      - 'psalm.xml'
+  push:
+    branches: ['master']
+    paths-ignore:
+      - 'docs/**'
+      - 'README.md'
+      - 'CHANGELOG.md'
+      - '.gitignore'
+      - '.gitattributes'
+      - 'infection.json.dist'
+      - 'phpunit.xml.dist'
+      - 'psalm.xml'
 
 name: backwards compatibility
+
 jobs:
-    roave_bc_check:
-        name: Roave BC Check
-        runs-on: ubuntu-latest
-        steps:
-            - uses: actions/checkout@master
-            - name: fetch tags
-              run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
-            - name: Roave BC Check
-              uses: docker://nyholm/roave-bc-check-ga
+  roave_bc_check:
+    uses: yiisoft/actions/.github/workflows/bc.yml@master
+    with:
+      os: >-
+        ['ubuntu-latest']
+      php: >-
+        ['8.1']
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index b662d755e..15b34500d 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -10,6 +10,7 @@ on:
       - 'psalm.xml'
 
   push:
+    branches: ['master']
     paths-ignore:
       - 'docs/**'
       - 'README.md'
diff --git a/.github/workflows/composer-require-checker.yml b/.github/workflows/composer-require-checker.yml
index b115ab1d3..a857bce6c 100644
--- a/.github/workflows/composer-require-checker.yml
+++ b/.github/workflows/composer-require-checker.yml
@@ -11,6 +11,7 @@ on:
       - 'psalm.xml'
 
   push:
+    branches: ['master']
     paths-ignore:
       - 'docs/**'
       - 'README.md'
@@ -30,4 +31,4 @@ jobs:
       os: >-
         ['ubuntu-latest']
       php: >-
-        ['8.1']
+        ['8.1', '8.2', '8.3']
diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml
index c1aca98cf..815049951 100644
--- a/.github/workflows/mutation.yml
+++ b/.github/workflows/mutation.yml
@@ -9,6 +9,7 @@ on:
       - 'psalm.xml'
 
   push:
+    branches: ['master']
     paths-ignore:
       - 'docs/**'
       - 'README.md'
@@ -26,6 +27,6 @@ jobs:
       os: >-
         ['ubuntu-latest']
       php: >-
-        ['8.1']
+        ['8.2']
     secrets:
       STRYKER_DASHBOARD_API_KEY: ${{ secrets.STRYKER_DASHBOARD_API_KEY }}
diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml
index c9030d7e1..35411d0ae 100644
--- a/.github/workflows/rector.yml
+++ b/.github/workflows/rector.yml
@@ -14,8 +14,10 @@ name: rector
 jobs:
   rector:
     uses: yiisoft/actions/.github/workflows/rector.yml@master
+    secrets:
+      token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
     with:
       os: >-
         ['ubuntu-latest']
       php: >-
-        ['8.1']
+        ['8.3']
diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml
index abebcd189..e33eca865 100644
--- a/.github/workflows/static.yml
+++ b/.github/workflows/static.yml
@@ -10,6 +10,7 @@ on:
       - 'phpunit.xml.dist'
 
   push:
+    branches: ['master']
     paths-ignore:
       - 'docs/**'
       - 'README.md'
diff --git a/.gitignore b/.gitignore
index 4a95cdb50..c16a327c0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -20,13 +20,13 @@ composer.phar
 # Mac DS_Store Files
 .DS_Store
 
-# phpunit itself is not needed
+# PhpUnit itself is not needed
 phpunit.phar
-# local phpunit config
+# local PhpUnit config
 /phpunit.xml
+# PhpUnit cache
+/.phpunit.cache
 
 # local tests configuration
 /tests/data/config.local.php
 /tests/Storage/runtime
-
-.phpunit.result.cache
diff --git a/composer.json b/composer.json
index cc142cbd9..776c84b96 100644
--- a/composer.json
+++ b/composer.json
@@ -46,7 +46,7 @@
         "ext-sockets": "*",
         "maglnet/composer-require-checker": "^4.2",
         "nyholm/psr7": "^1.3",
-        "phpunit/phpunit": "^9.4",
+        "phpunit/phpunit": "^10.5",
         "rector/rector": "^0.15.18",
         "roave/infection-static-analysis-plugin": "^1.16",
         "spatie/phpunit-watcher": "^1.23",
@@ -87,12 +87,6 @@
             "events-console": "events-console.php"
         }
     },
-    "repositories": [
-        {
-            "type": "composer",
-            "url": "https://asset-packagist.org"
-        }
-    ],
     "config": {
         "sort-packages": true,
         "allow-plugins": {
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 20d7fed79..e95e73833 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -1,13 +1,16 @@
-<?xml version="1.0" encoding="utf-8"?>
-<phpunit
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-    xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
-    bootstrap="vendor/autoload.php"
-    colors="true"
-    verbose="true"
-    failOnRisky="true"
-    failOnWarning="true"
-    executionOrder="random"
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
+         bootstrap="vendor/autoload.php"
+         cacheDirectory=".phpunit.cache"
+         requireCoverageMetadata="false"
+         beStrictAboutCoverageMetadata="true"
+         beStrictAboutOutputDuringTests="true"
+         executionOrder="random"
+         failOnRisky="true"
+         failOnWarning="true"
+         stopOnFailure="false"
+         colors="true"
 >
     <php>
         <ini name="error_reporting" value="-1"/>
@@ -19,9 +22,10 @@
         </testsuite>
     </testsuites>
 
-    <coverage>
+    <source>
         <include>
-            <directory>src</directory>
+            <directory suffix=".php">./src</directory>
+            <directory suffix=".php">./config</directory>
         </include>
-    </coverage>
+    </source>
 </phpunit>
diff --git a/tests/Unit/Collector/FilesystemStreamCollectorTest.php b/tests/Unit/Collector/FilesystemStreamCollectorTest.php
index 310797724..844f6a835 100644
--- a/tests/Unit/Collector/FilesystemStreamCollectorTest.php
+++ b/tests/Unit/Collector/FilesystemStreamCollectorTest.php
@@ -4,6 +4,7 @@
 
 namespace Yiisoft\Yii\Debug\Tests\Unit\Collector;
 
+use PHPUnit\Framework\Attributes\DataProvider;
 use Yiisoft\Files\FileHelper;
 use Yiisoft\Yii\Debug\Collector\CollectorInterface;
 use Yiisoft\Yii\Debug\Collector\Stream\FilesystemStreamCollector;
@@ -33,9 +34,7 @@ protected function collectTestData(CollectorInterface $collector): void
         );
     }
 
-    /**
-     * @dataProvider dataSkipCollectOnMatchIgnoreReferences
-     */
+    #[DataProvider('dataSkipCollectOnMatchIgnoreReferences')]
     public function testSkipCollectOnMatchIgnoreReferences(
         string $path,
         callable $before,
@@ -64,7 +63,7 @@ public function testSkipCollectOnMatchIgnoreReferences(
         $this->assertEquals($result, $collected);
     }
 
-    public function dataSkipCollectOnMatchIgnoreReferences(): iterable
+    public static function dataSkipCollectOnMatchIgnoreReferences(): iterable
     {
         $mkdirBefore = function (string $path) {
             if (is_dir($path)) {
diff --git a/tests/Unit/Collector/HttpStreamCollectorTest.php b/tests/Unit/Collector/HttpStreamCollectorTest.php
index e29323a8a..922deb083 100644
--- a/tests/Unit/Collector/HttpStreamCollectorTest.php
+++ b/tests/Unit/Collector/HttpStreamCollectorTest.php
@@ -4,6 +4,8 @@
 
 namespace Yiisoft\Yii\Debug\Tests\Unit\Collector;
 
+use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\TestCase;
 use Yiisoft\Yii\Debug\Collector\CollectorInterface;
 use Yiisoft\Yii\Debug\Collector\Stream\HttpStreamCollector;
 use Yiisoft\Yii\Debug\Tests\Shared\AbstractCollectorTestCase;
@@ -27,9 +29,7 @@ protected function collectTestData(CollectorInterface $collector): void
         );
     }
 
-    /**
-     * @dataProvider dataSkipCollectOnMatchIgnoreReferences
-     */
+    #[DataProvider('dataSkipCollectOnMatchIgnoreReferences')]
     public function testSkipCollectOnMatchIgnoreReferences(
         string $url,
         callable $before,
@@ -60,11 +60,11 @@ public function testSkipCollectOnMatchIgnoreReferences(
         if (is_array($assertResult)) {
             $this->assertSame($assertResult, $collected);
         } else {
-            $assertResult($url, $collected);
+            $assertResult($this, $url, $collected);
         }
     }
 
-    public function dataSkipCollectOnMatchIgnoreReferences(): iterable
+    public static function dataSkipCollectOnMatchIgnoreReferences(): iterable
     {
         $httpStreamBefore = function (string $url) {
         };
@@ -86,23 +86,23 @@ public function dataSkipCollectOnMatchIgnoreReferences(): iterable
             [],
             $httpStreamOperation,
             $httpStreamAfter,
-            function (string $url, array $collected) {
-                $this->assertArrayHasKey('read', $collected);
-                $this->assertIsArray($collected['read']);
-                $this->assertCount(1, $collected['read']);
+            function (TestCase $testCase, string $url, array $collected) {
+                $testCase->assertArrayHasKey('read', $collected);
+                $testCase->assertIsArray($collected['read']);
+                $testCase->assertCount(1, $collected['read']);
 
                 $readItem = $collected['read'][0];
-                $this->assertSame($url, $readItem['uri']);
-                $this->assertArrayHasKey('args', $readItem);
+                $testCase->assertSame($url, $readItem['uri']);
+                $testCase->assertArrayHasKey('args', $readItem);
 
                 $readItemArgs = $readItem['args'];
-                $this->assertCount(3, $readItemArgs);
+                $testCase->assertCount(3, $readItemArgs);
 
-                $this->assertSame('GET', $readItemArgs['method']);
-                $this->assertIsArray($readItemArgs['response_headers']);
-                $this->assertNotEmpty($readItemArgs['response_headers']);
-                $this->assertIsArray($readItemArgs['request_headers']);
-                $this->assertEmpty($readItemArgs['request_headers']);
+                $testCase->assertSame('GET', $readItemArgs['method']);
+                $testCase->assertIsArray($readItemArgs['response_headers']);
+                $testCase->assertNotEmpty($readItemArgs['response_headers']);
+                $testCase->assertIsArray($readItemArgs['request_headers']);
+                $testCase->assertEmpty($readItemArgs['request_headers']);
             },
         ];
         yield 'file stream ignored by path' => [
diff --git a/tests/Unit/DebugServiceProviderTest.php b/tests/Unit/DebugServiceProviderTest.php
index 339d51ebb..ef10f8728 100644
--- a/tests/Unit/DebugServiceProviderTest.php
+++ b/tests/Unit/DebugServiceProviderTest.php
@@ -9,7 +9,6 @@
 use Psr\EventDispatcher\ListenerProviderInterface;
 use Psr\Log\LoggerInterface;
 use Psr\Log\NullLogger;
-use Yiisoft\Definitions\Exception\InvalidConfigException;
 use Yiisoft\Di\Container;
 use Yiisoft\Di\ContainerConfig;
 use Yiisoft\EventDispatcher\Dispatcher\Dispatcher;
@@ -20,12 +19,6 @@
 
 final class DebugServiceProviderTest extends TestCase
 {
-    /**
-     * @throws InvalidConfigException
-     *
-     * @covers \Yiisoft\Yii\Debug\DebugServiceProvider::getDefinitions()
-     * @covers \Yiisoft\Yii\Debug\DebugServiceProvider::getExtensions()
-     */
     public function testRegister(): void
     {
         $config = ContainerConfig::create()
diff --git a/tests/Unit/ProxyServiceProviderTest.php b/tests/Unit/ProxyServiceProviderTest.php
index a9d9c4b1d..d9dd64829 100644
--- a/tests/Unit/ProxyServiceProviderTest.php
+++ b/tests/Unit/ProxyServiceProviderTest.php
@@ -10,7 +10,6 @@
 use Psr\EventDispatcher\ListenerProviderInterface;
 use Psr\Log\LoggerInterface;
 use Psr\Log\NullLogger;
-use Yiisoft\Definitions\Exception\InvalidConfigException;
 use Yiisoft\Di\Container;
 use Yiisoft\Di\ContainerConfig;
 use Yiisoft\EventDispatcher\Dispatcher\Dispatcher;
@@ -20,12 +19,6 @@
 
 final class ProxyServiceProviderTest extends TestCase
 {
-    /**
-     * @throws InvalidConfigException
-     *
-     * @covers \Yiisoft\Yii\Debug\ProxyServiceProvider::getDefinitions()
-     * @covers \Yiisoft\Yii\Debug\ProxyServiceProvider::getExtensions()
-     */
     public function testRegister(): void
     {
         $config = ContainerConfig::create()
diff --git a/tests/Unit/Storage/AbstractStorageTest.php b/tests/Unit/Storage/AbstractStorageTestCase.php
similarity index 98%
rename from tests/Unit/Storage/AbstractStorageTest.php
rename to tests/Unit/Storage/AbstractStorageTestCase.php
index fa7ff4a72..004bd2e90 100644
--- a/tests/Unit/Storage/AbstractStorageTest.php
+++ b/tests/Unit/Storage/AbstractStorageTestCase.php
@@ -13,7 +13,7 @@
 use Yiisoft\Yii\Debug\Storage\MemoryStorage;
 use Yiisoft\Yii\Debug\Storage\StorageInterface;
 
-abstract class AbstractStorageTest extends TestCase
+abstract class AbstractStorageTestCase extends TestCase
 {
     /**
      * @dataProvider dataProvider()
diff --git a/tests/Unit/Storage/FileStorageTest.php b/tests/Unit/Storage/FileStorageTest.php
index 679df42a6..537a9bce2 100644
--- a/tests/Unit/Storage/FileStorageTest.php
+++ b/tests/Unit/Storage/FileStorageTest.php
@@ -10,7 +10,7 @@
 use Yiisoft\Yii\Debug\Storage\FileStorage;
 use Yiisoft\Yii\Debug\Storage\StorageInterface;
 
-final class FileStorageTest extends AbstractStorageTest
+final class FileStorageTest extends AbstractStorageTestCase
 {
     private string $path = __DIR__ . '/runtime';
 
diff --git a/tests/Unit/Storage/MemoryStorageTest.php b/tests/Unit/Storage/MemoryStorageTest.php
index 98f71de4d..a74e37eb3 100644
--- a/tests/Unit/Storage/MemoryStorageTest.php
+++ b/tests/Unit/Storage/MemoryStorageTest.php
@@ -8,7 +8,7 @@
 use Yiisoft\Yii\Debug\Storage\MemoryStorage;
 use Yiisoft\Yii\Debug\Storage\StorageInterface;
 
-final class MemoryStorageTest extends AbstractStorageTest
+final class MemoryStorageTest extends AbstractStorageTestCase
 {
     public function getStorage(DebuggerIdGenerator $idGenerator): StorageInterface
     {