WordPress.org

Make WordPress Core


Ignore:
Timestamp:
08/06/2021 09:38:45 PM (4 months ago)
Author:
SergeyBiryukov
Message:

Tests: Replace expectException() for PHP native errors with calls to the dedicated PHPUnit 8.4+ methods.

The old manner of testing these is soft deprecated as of PHPUnit 8.4, hard deprecated as of PHPUnit 9.0 and will be removed in PHPUnit 10.0.

These dedicated methods introduced in PHPUnit 8.4 should be used as an alternative:

  • expectDeprecation()
  • expectDeprecationMessage()
  • expectDeprecationMessageMatches()
  • expectNotice()
  • expectNoticeMessage()
  • expectNoticeMessageMatches()
  • expectWarning()
  • expectWarningMessage()
  • expectWarningMessageMatches()
  • expectError()
  • expectErrorMessage()
  • expectErrorMessageMatches()

These new PHPUnit methods are all polyfilled by the PHPUnit Polyfills and switching to these will future-proof the tests some more.

References:

Follow-up to [51559-51562].

Props jrf.
See #46149.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-schema-sanitization.php

    r49246 r51563  
    458458    public function test_format_validation_is_applied_if_missing_type() {
    459459        if ( PHP_VERSION_ID >= 80000 ) {
    460             $this->expectException( 'PHPUnit_Framework_Error_Warning' ); // For the undefined index.
     460            $this->expectWarning(); // For the undefined index.
    461461        } else {
    462             $this->expectException( 'PHPUnit_Framework_Error_Notice' );
     462            $this->expectNotice(); // For the undefined index.
    463463        }
    464464
Note: See TracChangeset for help on using the changeset viewer.