Skip to content

Commit

Permalink
[TASK] Align error handler tests with changed PHPUnit behavior
Browse files Browse the repository at this point in the history
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 update typo3/testing-framework
> composer require --dev "phpunit/phpunit":"^10.5.5"

[1] sebastianbergmann/phpunit#5430
[2] sebastianbergmann/phpunit#5592
[3] sebastianbergmann/phpunit#5619

Resolves: #102724
Releases: main, 12.4
Change-Id: I77f750ef2eba53b5f8caa51651f36321ae5d1224
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/82282
Tested-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com>
Tested-by: core-ci <typo3@b13.com>
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Simon Schaufelberger <simonschaufi+typo3@gmail.com>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
  • Loading branch information
sbuerk committed Dec 28, 2023
1 parent 7a238b3 commit 5d1d9d7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"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/testing-framework": "dev-main",
Expand Down
26 changes: 13 additions & 13 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions typo3/sysext/core/Tests/Unit/Error/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

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;
Expand Down Expand Up @@ -64,6 +67,9 @@ public function log($level, string|\Stringable $message, array $context = []): v
};
}

#[WithoutErrorHandler]
#[Test]
#[DataProvider('errorTests')]
/**
* @test
* @dataProvider errorTests
Expand Down

0 comments on commit 5d1d9d7

Please sign in to comment.