Make WordPress Core


Ignore:
Timestamp:
07/19/2021 02:00:11 PM (3 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/comment/getCommentLink.php

    r49603 r51462  
    6767        $found = get_comment_link( self::$comments[1] );
    6868
    69         $this->assertContains( 'cpage=3', $found );
     69        $this->assertStringContainsString( 'cpage=3', $found );
    7070    }
    7171
     
    8080        $found = get_comment_link( self::$comments[3] );
    8181
    82         $this->assertContains( 'cpage=2', $found );
     82        $this->assertStringContainsString( 'cpage=2', $found );
    8383    }
    8484
     
    9393        $found = get_comment_link( self::$comments[5] );
    9494
    95         $this->assertContains( 'cpage=1', $found );
     95        $this->assertStringContainsString( 'cpage=1', $found );
    9696    }
    9797
     
    105105        $found = get_comment_link( self::$comments[5] );
    106106
    107         $this->assertNotContains( 'cpage', $found );
     107        $this->assertStringNotContainsString( 'cpage', $found );
    108108    }
    109109
     
    118118        $found = get_comment_link( self::$comments[3] );
    119119
    120         $this->assertContains( 'cpage=2', $found );
     120        $this->assertStringContainsString( 'cpage=2', $found );
    121121    }
    122122
     
    131131        $found = get_comment_link( self::$comments[1] );
    132132
    133         $this->assertContains( 'cpage=3', $found );
     133        $this->assertStringContainsString( 'cpage=3', $found );
    134134    }
    135135
     
    143143        $found = get_comment_link( self::$comments[1] );
    144144
    145         $this->assertNotContains( 'comment-page-1', $found );
     145        $this->assertStringNotContainsString( 'comment-page-1', $found );
    146146    }
    147147}
Note: See TracChangeset for help on using the changeset viewer.