Make WordPress Core


Ignore:
Timestamp:
07/19/2021 02:00:11 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Tests: Replace assertContains() with assertStringContainsString() when used with strings.

Using the assertContains() and assertNotContains() methods with string haystacks was deprecated in PHPUnit 8 and removed in PHPUnit 9.

While WordPress test suite currently only supports PHPUnit up to 7.5.x, this allows us to switch to newer assertions ahead of adding full support for PHPUnit 8+.

These methods introduced in PHPUnit 7.5 should be used as an alternative:

  • assertStringContainsString()
  • assertStringContainsStringIgnoringCase
  • assertStringNotContainsString()
  • assertStringNotContainsStringIgnoringCase

As WordPress currently uses PHPUnit 5.7.x to run tests on PHP 5.6, polyfills for these methods were added to the WP_UnitTestCase class for PHPUnit < 7.5.

Follow-up to [51331], [51451], [51461].

Props jrf, dd32, SergeyBiryukov.
See #53363, #46149.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/category/wpDropdownCategories.php

    r46586 r51462  
    2626
    2727        // Test to see if it returns the default with the category ID.
    28         $this->assertContains( 'value="' . $cat_id . '"', $dropdown_default );
     28        $this->assertStringContainsString( 'value="' . $cat_id . '"', $dropdown_default );
    2929    }
    3030
     
    5151
    5252        // Test to see if it returns the default with the category ID.
    53         $this->assertContains( 'value="' . $cat_id . '"', $found );
     53        $this->assertStringContainsString( 'value="' . $cat_id . '"', $found );
    5454    }
    5555
     
    7676
    7777        // Test to see if it returns the default with the category slug.
    78         $this->assertContains( 'value="test_category"', $found );
     78        $this->assertStringContainsString( 'value="test_category"', $found );
    7979    }
    8080
     
    101101
    102102        // Test to see if it returns the default with the category slug.
    103         $this->assertContains( 'value="' . $cat_id . '"', $found );
     103        $this->assertStringContainsString( 'value="' . $cat_id . '"', $found );
    104104    }
    105105
     
    131131        );
    132132
    133         $this->assertContains( 'value="test_category_2" selected="selected"', $found );
     133        $this->assertStringContainsString( 'value="test_category_2" selected="selected"', $found );
    134134    }
    135135
     
    149149        );
    150150
    151         $this->assertContains( "value='0' selected='selected'", $found );
     151        $this->assertStringContainsString( "value='0' selected='selected'", $found );
    152152
    153153        foreach ( $cats as $cat ) {
    154154            $_cat = get_term( $cat, 'category' );
    155             $this->assertNotContains( 'value="' . $_cat->slug . '" selected="selected"', $found );
     155            $this->assertStringNotContainsString( 'value="' . $_cat->slug . '" selected="selected"', $found );
    156156        }
    157157    }
     
    173173        );
    174174
    175         $this->assertContains( "value='0' selected='selected'", $found );
     175        $this->assertStringContainsString( "value='0' selected='selected'", $found );
    176176
    177177        foreach ( $cats as $cat ) {
    178178            $_cat = get_term( $cat, 'category' );
    179             $this->assertNotContains( 'value="' . $_cat->slug . '" selected="selected"', $found );
     179            $this->assertStringNotContainsString( 'value="' . $_cat->slug . '" selected="selected"', $found );
    180180        }
    181181    }
Note: See TracChangeset for help on using the changeset viewer.