Make WordPress Core

Changeset 40875


Ignore:
Timestamp:
06/05/2017 10:39:36 AM (8 years ago)
Author:
johnbillion
Message:

Build/Test Tools: Fix PHP 5.2 compatibility for grandchild methods which expect exceptions to be raised.

This is due to is_callable( 'parent::setExpectedException' ) not being supported on PHP 5.2 when the method being checked only exists on the grandparent class.

See #39822

Merges [40872] and [40873] to the 4.8 branch.

Location:
branches/4.8
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/4.8

  • branches/4.8/tests/phpunit/includes/testcase-ajax.php

    r40539 r40875  
    201201            $this->_last_response = $buffer;
    202202    }
    203 
    204     /**
    205      * PHPUnit 6+ compatibility shim.
    206      *
    207      * @param mixed      $exception
    208      * @param string     $message
    209      * @param int|string $code
    210      */
    211     public function setExpectedException( $exception, $message = '', $code = null ) {
    212         if ( is_callable( 'parent::setExpectedException' ) ) {
    213             parent::setExpectedException( $exception, $message, $code );
    214         } else {
    215             $this->expectException( $exception );
    216             if ( '' !== $message ) {
    217                 $this->expectExceptionMessage( $message );
    218             }
    219             if ( null !== $code ) {
    220                 $this->expectExceptionCode( $code );
    221             }
    222         }
    223     }
    224203}
  • branches/4.8/tests/phpunit/includes/testcase.php

    r40605 r40875  
    442442    public function setExpectedIncorrectUsage( $doing_it_wrong ) {
    443443        array_push( $this->expected_doing_it_wrong, $doing_it_wrong );
     444    }
     445
     446    /**
     447     * PHPUnit 6+ compatibility shim.
     448     *
     449     * @param mixed      $exception
     450     * @param string     $message
     451     * @param int|string $code
     452     */
     453    public function setExpectedException( $exception, $message = '', $code = null ) {
     454        if ( method_exists( 'PHPUnit_Framework_TestCase', 'setExpectedException' ) ) {
     455            parent::setExpectedException( $exception, $message, $code );
     456        } else {
     457            $this->expectException( $exception );
     458            if ( '' !== $message ) {
     459                $this->expectExceptionMessage( $message );
     460            }
     461            if ( null !== $code ) {
     462                $this->expectExceptionCode( $code );
     463            }
     464        }
    444465    }
    445466
Note: See TracChangeset for help on using the changeset viewer.