Make WordPress Core


Ignore:
Timestamp:
08/06/2021 09:17:20 PM (3 years ago)
Author:
SergeyBiryukov
Message:

Build/Test Tools: Simplify redundant PHPUnit shim for setExpectedException().

PHPUnit 6 deprecated the setExpectedException() method in favor of the expectException(), expectExceptionMessage(), and expectExceptionCode() methods.

WP_UnitTestCase_Base::setExpectedException() backfilled the old method. As the PHPUnit Polyfills have a polyfill for the new method, this backfill can now be simplified.

This backfill should be removed in a future iteration, but is, for now, left in place so as not to break backward compatibility for plugin/theme test suites which extend the WP native test suite for their integration tests.

Follow-up to [48996], [48997], [51559-51561].

Props jrf.
See #46149.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/abstract-testcase.php

    r51561 r51562  
    565565
    566566    /**
    567      * PHPUnit 6+ compatibility shim.
     567     * Redundant PHPUnit 6+ compatibility shim. DO NOT USE!
     568     *
     569     * This method is only left in place for backward compatibility reasons.
     570     *
     571     * @deprecated 5.9.0 Use the PHPUnit native expectException*() methods directly.
    568572     *
    569573     * @param mixed      $exception
     
    572576     */
    573577    public function setExpectedException( $exception, $message = '', $code = null ) {
    574         if ( method_exists( 'PHPUnit_Framework_TestCase', 'setExpectedException' ) ) {
    575             parent::setExpectedException( $exception, $message, $code );
    576         } else {
    577             $this->expectException( $exception );
    578             if ( '' !== $message ) {
    579                 $this->expectExceptionMessage( $message );
    580             }
    581             if ( null !== $code ) {
    582                 $this->expectExceptionCode( $code );
    583             }
     578        $this->expectException( $exception );
     579
     580        if ( '' !== $message ) {
     581            $this->expectExceptionMessage( $message );
     582        }
     583
     584        if ( null !== $code ) {
     585            $this->expectExceptionCode( $code );
    584586        }
    585587    }
Note: See TracChangeset for help on using the changeset viewer.