Make WordPress Core


Ignore:
Timestamp:
09/21/2021 07:29:38 PM (3 years ago)
Author:
desrosj
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.6 branch.
See #53911.

Location:
branches/5.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/5.6

  • branches/5.6/tests/phpunit/includes/testcase.php

    r48953 r51840  
    11<?php
     2
     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;
    218
    319require_once __DIR__ . '/abstract-testcase.php';
     
    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 two variables are equal (with delta).
    18      *
    19      * This method has been backported from a more recent PHPUnit version,
    20      * as tests running on PHP 5.6 use PHPUnit 5.7.x.
    21      *
    22      * @since 5.6.0
    23      *
    24      * @param mixed  $expected First value to compare.
    25      * @param mixed  $actual   Second value to compare.
    26      * @param float  $delta    Allowed numerical distance between two values to consider them equal.
    27      * @param string $message  Optional. Message to display when the assertion fails.
    28      *
    29      * @throws ExpectationFailedException
    30      * @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
     49     * Wrapper method for the `setUpBeforeClass()` method for forward-compatibility with WP 5.9.
    3150     */
    32     public static function assertEqualsWithDelta( $expected, $actual, $delta, $message = '' ) {
    33         $constraint = new PHPUnit_Framework_Constraint_IsEqual(
    34             $expected,
    35             $delta
    36         );
     51    public static function set_up_before_class() {
     52        static::setUpBeforeClass();
     53    }
    3754
    38         static::assertThat( $actual, $constraint, $message );
     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();
    3974    }
    4075}
Note: See TracChangeset for help on using the changeset viewer.