Make WordPress Core


Ignore:
Timestamp:
09/22/2021 12:09:05 AM (3 years ago)
Author:
hellofromTonya
Message:

Build/Test Tools: Introduce the PHPUnit Polyfills package for easier cross branch testing.

This backports the PHPUnit Polyfills package and related test infrastructure changes to make it easier for developers to continue testing on multiple versions WordPress while adding tests for newer versions of PHP, which require more modern PHPUnit practices.

One of the changes included is the addition of wrappers for the new snake_case fixture methods in PHPUnit. This allows the native camelCase standard in PHPUnit to be used, but allows for developers to transition to the new naming conventions.

Props hellofromTonya, jrf, SergeyBiryukov, johnbillion, netweb, schlessera, jeherve, lucatume, desrosj.
Merges [51559,51560,51810-51813,51828] to the 5.2 branch.
See #53911.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/5.2/tests/phpunit/includes/testcase.php

    r44701 r51846  
    11<?php
    22
    3 require_once dirname( __FILE__ ) . '/abstract-testcase.php';
     3use Yoast\PHPUnitPolyfills\Helpers\AssertAttributeHelper;
     4use Yoast\PHPUnitPolyfills\Polyfills\AssertClosedResource;
     5use Yoast\PHPUnitPolyfills\Polyfills\AssertEqualsSpecializations;
     6use Yoast\PHPUnitPolyfills\Polyfills\AssertFileDirectory;
     7use Yoast\PHPUnitPolyfills\Polyfills\AssertFileEqualsSpecializations;
     8use Yoast\PHPUnitPolyfills\Polyfills\AssertionRenames;
     9use Yoast\PHPUnitPolyfills\Polyfills\AssertIsType;
     10use Yoast\PHPUnitPolyfills\Polyfills\AssertNumericType;
     11use Yoast\PHPUnitPolyfills\Polyfills\AssertObjectEquals;
     12use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains;
     13use Yoast\PHPUnitPolyfills\Polyfills\EqualToSpecializations;
     14use Yoast\PHPUnitPolyfills\Polyfills\ExpectException;
     15use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionMessageMatches;
     16use Yoast\PHPUnitPolyfills\Polyfills\ExpectExceptionObject;
     17use Yoast\PHPUnitPolyfills\Polyfills\ExpectPHPException;
     18
     19require_once __DIR__ . '/abstract-testcase.php';
    420
    521/**
     
    1430class WP_UnitTestCase extends WP_UnitTestCase_Base {
    1531
     32    use AssertAttributeHelper;
     33    use AssertClosedResource;
     34    use AssertEqualsSpecializations;
     35    use AssertFileDirectory;
     36    use AssertFileEqualsSpecializations;
     37    use AssertionRenames;
     38    use AssertIsType;
     39    use AssertNumericType;
     40    use AssertObjectEquals;
     41    use AssertStringContains;
     42    use EqualToSpecializations;
     43    use ExpectException;
     44    use ExpectExceptionMessageMatches;
     45    use ExpectExceptionObject;
     46    use ExpectPHPException;
     47
    1648    /**
    17      * Asserts that a condition is not false.
    18      *
    19      * This method has been backported from a more recent PHPUnit version, as tests running on PHP 5.2 use
    20      * PHPUnit 3.6.x.
    21      *
    22      * @since 4.7.4
    23      *
    24      * @param bool   $condition Condition to check.
    25      * @param string $message   Optional. Message to display when the assertion fails.
    26      *
    27      * @throws PHPUnit_Framework_AssertionFailedError
     49     * Wrapper method for the `setUpBeforeClass()` method for forward-compatibility with WP 5.9.
    2850     */
    29     public static function assertNotFalse( $condition, $message = '' ) {
    30         self::assertThat( $condition, self::logicalNot( self::isFalse() ), $message );
     51    public static function set_up_before_class() {
     52        static::setUpBeforeClass();
     53    }
     54
     55    /**
     56     * Wrapper method for the `tearDownAfterClass()` method for forward-compatibility with WP 5.9.
     57     */
     58    public static function tear_down_after_class() {
     59        static::tearDownAfterClass();
     60    }
     61
     62    /**
     63     * Wrapper method for the `setUp()` method for forward-compatibility with WP 5.9.
     64     */
     65    public function set_up() {
     66        static::setUp();
     67    }
     68
     69    /**
     70     * Wrapper method for the `tearDown()` method for forward-compatibility with WP 5.9.
     71     */
     72    public function tear_down() {
     73        static::tearDown();
    3174    }
    3275}
Note: See TracChangeset for help on using the changeset viewer.