Make WordPress Core


Ignore:
Timestamp:
07/19/2021 02:00:11 PM (6 months 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/term/getTermLink.php

    r50565 r51462  
    2929
    3030        $actual = get_term_link( $term, 'wptests_tax' );
    31         $this->assertContains( 'wptests_tax=foo', $actual );
     31        $this->assertStringContainsString( 'wptests_tax=foo', $actual );
    3232    }
    3333
     
    4949
    5050        $actual = get_term_link( $term, 'wptests_tax' );
    51         $this->assertContains( 'wptests_tax=' . $term, $actual );
     51        $this->assertStringContainsString( 'wptests_tax=' . $term, $actual );
    5252    }
    5353
     
    6161
    6262        $actual = get_term_link( $c, 'category' );
    63         $this->assertContains( 'cat=' . $c, $actual );
     63        $this->assertStringContainsString( 'cat=' . $c, $actual );
    6464    }
    6565
     
    8181
    8282        $actual = get_term_link( $t, 'wptests_tax2' );
    83         $this->assertContains( 'foo=bar', $actual );
     83        $this->assertStringContainsString( 'foo=bar', $actual );
    8484    }
    8585
     
    101101
    102102        $actual = get_term_link( $t, 'wptests_tax2' );
    103         $this->assertContains( 'taxonomy=wptests_tax2', $actual );
    104         $this->assertContains( 'term=bar', $actual );
     103        $this->assertStringContainsString( 'taxonomy=wptests_tax2', $actual );
     104        $this->assertStringContainsString( 'term=bar', $actual );
    105105    }
    106106
     
    132132        remove_permastruct( 'wptests_tax2' );
    133133
    134         $this->assertContains( '/foo/bar/', $actual );
     134        $this->assertStringContainsString( '/foo/bar/', $actual );
    135135    }
    136136
     
    169169        $actual = get_term_link( $t2, 'wptests_tax2' );
    170170
    171         $this->assertContains( '/foo/term1/term2/', $actual );
     171        $this->assertStringContainsString( '/foo/term1/term2/', $actual );
    172172    }
    173173
     
    206206        $actual = get_term_link( $t2, 'wptests_tax2' );
    207207
    208         $this->assertContains( '/foo/term2/', $actual );
     208        $this->assertStringContainsString( '/foo/term2/', $actual );
    209209    }
    210210}
Note: See TracChangeset for help on using the changeset viewer.