WordPress.org

Make WordPress Core

Changeset 40536


Ignore:
Timestamp:
04/23/2017 02:05:12 AM (5 years ago)
Author:
johnbillion
Message:

Build/Test Tools: Add support for PHPUnit 6+.

This adds a compatibility shim for the new namespaced structure of PHPUnit and the removed setExpectedException() method. In addition, this updates the Travis config so PHPUnit 6.1 is used where appropriate.

Props miyauchi, gitlost.

Fixes #39822

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/.travis.yml

    r40528 r40536  
    6868  if [[ "$WP_TRAVISCI" == "travis:phpunit" ]]; then
    6969    case "$TRAVIS_PHP_VERSION" in
    70       7.1|7.0|hhvm|nightly)
     70      7.1|7.0|nightly)
     71        echo "Using PHPUnit 6.1"
     72        composer global require "phpunit/phpunit=6.1.*"
     73        ;;
     74      hhvm)
    7175        echo "Using PHPUnit 5.7"
    7276        composer global require "phpunit/phpunit=5.7.*"
  • trunk/tests/phpunit/includes/bootstrap.php

    r40065 r40536  
    44 */
    55
     6/**
     7 * Compatibility with PHPUnit 6+
     8 */
     9if ( class_exists( 'PHPUnit\Runner\Version' ) ) {
     10    require_once dirname( __FILE__ ) . '/phpunit6-compat.php';
     11}
    612
    713$config_file_path = dirname( dirname( __FILE__ ) );
  • trunk/tests/phpunit/includes/testcase.php

    r40535 r40536  
    414414    public function setExpectedIncorrectUsage( $doing_it_wrong ) {
    415415        array_push( $this->expected_doing_it_wrong, $doing_it_wrong );
     416    }
     417
     418    /**
     419     * PHPUnit 6+ compatibility shim.
     420     *
     421     * @param mixed      $exception
     422     * @param string     $message
     423     * @param int|string $code
     424     */
     425    public function setExpectedException( $exception, $message = '', $code = null ) {
     426        if ( is_callable( 'parent::setExpectedException' ) ) {
     427            parent::setExpectedException( $exception, $message, $code );
     428        } else {
     429            $this->expectException( $exception );
     430            if ( '' !== $message ) {
     431                $this->expectExceptionMessage( $message );
     432            }
     433            if ( null !== $code ) {
     434                $this->expectExceptionCode( $code );
     435            }
     436        }
    416437    }
    417438
Note: See TracChangeset for help on using the changeset viewer.