Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement #[WithoutErrorHandler] attribute to disable PHPUnit's error handler for a test method #5430

Conversation

sebastianbergmann
Copy link
Owner

@sebastianbergmann sebastianbergmann commented Jun 27, 2023

@sebastianbergmann sebastianbergmann added type/enhancement A new idea that should be implemented feature/test-runner CLI test runner labels Jun 27, 2023
@sebastianbergmann sebastianbergmann added this to the PHPUnit 10.3 milestone Jun 27, 2023
@codecov
Copy link

codecov bot commented Jun 27, 2023

Codecov Report

Merging #5430 (091fff0) into main (41c9726) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head 091fff0 differs from pull request most recent head e676667. Consider uploading reports for the commit e676667 to get more accurate results

@@             Coverage Diff              @@
##               main    #5430      +/-   ##
============================================
+ Coverage     85.01%   85.02%   +0.01%     
- Complexity     6164     6169       +5     
============================================
  Files           653      654       +1     
  Lines         19634    19650      +16     
============================================
+ Hits          16692    16708      +16     
  Misses         2942     2942              
Impacted Files Coverage Δ
src/Metadata/Metadata.php 100.00% <100.00%> (ø)
src/Metadata/MetadataCollection.php 100.00% <100.00%> (ø)
src/Metadata/Parser/AttributeParser.php 100.00% <100.00%> (ø)
src/Metadata/WithoutErrorHandler.php 100.00% <100.00%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@sebastianbergmann sebastianbergmann self-assigned this Jun 27, 2023
@sebastianbergmann sebastianbergmann changed the title Implement #[WithoutErrorHandler] attribute to disable PHPUnit's error handler for a test method Implement #[WithoutErrorHandler] attribute to disable PHPUnit's error handler for a test method Jun 27, 2023
@sebastianbergmann sebastianbergmann marked this pull request as ready for review June 27, 2023 06:00
@sebastianbergmann sebastianbergmann merged commit 3baace5 into main Jun 27, 2023
@sebastianbergmann sebastianbergmann deleted the 5428-attribute-withouterrorhandler-to-disable-phpunits-error-handler-for-a-test-method branch June 27, 2023 06:11
reviewtypo3org pushed a commit to TYPO3/typo3 that referenced this pull request Dec 28, 2023
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>
reviewtypo3org pushed a commit to TYPO3/typo3 that referenced this pull request Dec 28, 2023
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] 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/+/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>
TYPO3IncTeam pushed a commit to TYPO3-CMS/core that referenced this pull request Dec 28, 2023
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>
TYPO3IncTeam pushed a commit to TYPO3-CMS/core that referenced this pull request Dec 28, 2023
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] 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/+/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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-runner CLI test runner type/enhancement A new idea that should be implemented
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Attribute #[WithoutErrorHandler] to disable PHPUnit's error handler for a test method
1 participant