From 465622956fa567db8e21f7ecfbd20e534eb5cd35 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Stefan=20B=C3=BCrk?= <stefan@buerk.tech>
Date: Thu, 28 Dec 2023 10:40:06 +0100
Subject: [PATCH] [TASK] Align error handler tests with changed PHPUnit
 behavior
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

PHPUnit has changed the behavior of the error handler in
several ways, for example introducing a PHP attribute to
disable the PHPUnit error handler for tests dealing with
`error_get_last()` [1], throwing an exception and stopping
the script execution on `E_*_ERROR` or clearing the error
result [2] - which breaks the ability to use the native
`error_get_last()` method to test custom error handler
implementation.

Something which TYPO3 needs to do for the provided custom
error handler.

An additional change [3] to check and restore error handlers
with levels has been reverted due to issues in the Laravel
world.

This change modifies the related test to use the introduced
PHP attribute `#[WithoutErrorHandler]` and raises PHPUnit.

Note: PHPUnit does not recognize the `@test` doc-block
      annotation if the `#[WithoutErrorHandler]` attribute
      is used. Therefore, the attribute counterparts for
      `@test` and `@dataProvider` has been added on top
      and not exclusively for now, albeit looking weird
      and fishy. This needs to be addressed in a more
      generic way in a dedicated change.

Used command(s):

> composer require --dev \
    "phpunit/phpunit":"^10.5.5" \
    "typo3/testing-framework":"^8.0.8"

[1] https://github.com/sebastianbergmann/phpunit/pull/5430
[2] https://github.com/sebastianbergmann/phpunit/pull/5592
[3] https://github.com/sebastianbergmann/phpunit/pull/5619

Resolves: #102724
Releases: main, 12.4
Change-Id: I77f750ef2eba53b5f8caa51651f36321ae5d1224
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/82283
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Oliver Klee <typo3-coding@oliverklee.de>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com>
---
 composer.json                                 |  4 +--
 composer.lock                                 | 28 +++++++++----------
 .../Tests/Unit/Error/ErrorHandlerTest.php     |  6 ++++
 3 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/composer.json b/composer.json
index 8ca2c325edb3..6e2cd6e6f1e1 100644
--- a/composer.json
+++ b/composer.json
@@ -114,11 +114,11 @@
 		"php-webdriver/webdriver": "^1.14.0",
 		"phpstan/phpstan": "^1.10.48",
 		"phpstan/phpstan-phpunit": "^1.3.15",
-		"phpunit/phpunit": "^10.4.0",
+		"phpunit/phpunit": "^10.5.5",
 		"sokil/php-isocodes-db-i18n": "^4.0.17",
 		"symfony/translation": "^6.4",
 		"typo3/cms-styleguide": "^12.0.2",
-		"typo3/testing-framework": "^8.0.7",
+		"typo3/testing-framework": "^8.0.8",
 		"webmozart/assert": "^1.11.0"
 	},
 	"suggest": {
diff --git a/composer.lock b/composer.lock
index f82e17c4bf92..89a3467dfecf 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "07621639d7883796e9c244884c5dbdc9",
+    "content-hash": "9d14942204ece51df82cc01aba8231d2",
     "packages": [
         {
             "name": "bacon/bacon-qr-code",
@@ -7134,16 +7134,16 @@
         },
         {
             "name": "phpunit/phpunit",
-            "version": "10.4.0",
+            "version": "10.5.5",
             "source": {
                 "type": "git",
                 "url": "https://github.com/sebastianbergmann/phpunit.git",
-                "reference": "9784e877e3700de37475545bdbdce8383ff53d25"
+                "reference": "ed21115d505b4b4f7dc7b5651464e19a2c7f7856"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/9784e877e3700de37475545bdbdce8383ff53d25",
-                "reference": "9784e877e3700de37475545bdbdce8383ff53d25",
+                "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ed21115d505b4b4f7dc7b5651464e19a2c7f7856",
+                "reference": "ed21115d505b4b4f7dc7b5651464e19a2c7f7856",
                 "shasum": ""
             },
             "require": {
@@ -7183,7 +7183,7 @@
             "type": "library",
             "extra": {
                 "branch-alias": {
-                    "dev-main": "10.4-dev"
+                    "dev-main": "10.5-dev"
                 }
             },
             "autoload": {
@@ -7215,7 +7215,7 @@
             "support": {
                 "issues": "https://github.com/sebastianbergmann/phpunit/issues",
                 "security": "https://github.com/sebastianbergmann/phpunit/security/policy",
-                "source": "https://github.com/sebastianbergmann/phpunit/tree/10.4.0"
+                "source": "https://github.com/sebastianbergmann/phpunit/tree/10.5.5"
             },
             "funding": [
                 {
@@ -7231,7 +7231,7 @@
                     "type": "tidelift"
                 }
             ],
-            "time": "2023-10-06T03:41:22+00:00"
+            "time": "2023-12-27T15:13:52+00:00"
         },
         {
             "name": "psy/psysh",
@@ -8997,16 +8997,16 @@
         },
         {
             "name": "typo3/testing-framework",
-            "version": "8.0.7",
+            "version": "8.0.8",
             "source": {
                 "type": "git",
                 "url": "https://github.com/TYPO3/testing-framework.git",
-                "reference": "a0ccebcddbc9ac34024d4edcf4165dc145e15e56"
+                "reference": "a6f63d180637bf78edc4720ff9a733ec34275b4b"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/TYPO3/testing-framework/zipball/a0ccebcddbc9ac34024d4edcf4165dc145e15e56",
-                "reference": "a0ccebcddbc9ac34024d4edcf4165dc145e15e56",
+                "url": "https://api.github.com/repos/TYPO3/testing-framework/zipball/a6f63d180637bf78edc4720ff9a733ec34275b4b",
+                "reference": "a6f63d180637bf78edc4720ff9a733ec34275b4b",
                 "shasum": ""
             },
             "require": {
@@ -9064,9 +9064,9 @@
             "support": {
                 "general": "https://typo3.org/support/",
                 "issues": "https://github.com/TYPO3/testing-framework/issues",
-                "source": "https://github.com/TYPO3/testing-framework/tree/8.0.7"
+                "source": "https://github.com/TYPO3/testing-framework/tree/8.0.8"
             },
-            "time": "2023-11-23T13:51:56+00:00"
+            "time": "2023-12-28T13:04:55+00:00"
         }
     ],
     "aliases": [],
diff --git a/typo3/sysext/core/Tests/Unit/Error/ErrorHandlerTest.php b/typo3/sysext/core/Tests/Unit/Error/ErrorHandlerTest.php
index 63f1deed5cd0..d537921e0a11 100644
--- a/typo3/sysext/core/Tests/Unit/Error/ErrorHandlerTest.php
+++ b/typo3/sysext/core/Tests/Unit/Error/ErrorHandlerTest.php
@@ -17,6 +17,9 @@ declare(strict_types=1);
 
 namespace TYPO3\CMS\Core\Tests\Unit\Error;
 
+use PHPUnit\Framework\Attributes\DataProvider;
+use PHPUnit\Framework\Attributes\Test;
+use PHPUnit\Framework\Attributes\WithoutErrorHandler;
 use Psr\Log\LoggerInterface;
 use Psr\Log\LoggerTrait;
 use Psr\Log\LogLevel;
@@ -64,6 +67,9 @@ final class ErrorHandlerTest extends UnitTestCase
         };
     }
 
+    #[WithoutErrorHandler]
+    #[Test]
+    #[DataProvider('errorTests')]
     /**
      * @test
      * @dataProvider errorTests
-- 
GitLab