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.

git-svn-id: https://develop.svn.wordpress.org/trunk@51462 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2021-07-19 14:00:11 +00:00
parent bb3bf22547
commit c70fe62ed1
97 changed files with 811 additions and 811 deletions

View File

@@ -93,8 +93,8 @@ class Tests_Query_InvalidQueries extends WP_UnitTestCase {
$query = new WP_Query( array( 'post_type' => 'unregistered_cpt' ) );
$posts = $query->get_posts();
$this->assertContains( "{$wpdb->posts}.post_type = 'unregistered_cpt'", self::$last_posts_request );
$this->assertContains( "{$wpdb->posts}.post_status = 'publish'", self::$last_posts_request );
$this->assertStringContainsString( "{$wpdb->posts}.post_type = 'unregistered_cpt'", self::$last_posts_request );
$this->assertStringContainsString( "{$wpdb->posts}.post_status = 'publish'", self::$last_posts_request );
$this->assertCount( 0, $posts );
}
@@ -113,7 +113,7 @@ class Tests_Query_InvalidQueries extends WP_UnitTestCase {
);
$posts = $query->get_posts();
$this->assertContains( "{$wpdb->posts}.post_type = 'unregistered_cpt'", self::$last_posts_request );
$this->assertStringContainsString( "{$wpdb->posts}.post_type = 'unregistered_cpt'", self::$last_posts_request );
$this->assertCount( 1, $posts, 'the valid `page` post type should still return one post' );
}
@@ -127,8 +127,8 @@ class Tests_Query_InvalidQueries extends WP_UnitTestCase {
$this->go_to( home_url( '?post_type=unregistered_cpt' ) );
$this->assertContains( "{$wpdb->posts}.post_type = 'unregistered_cpt'", self::$last_posts_request );
$this->assertContains( "{$wpdb->posts}.post_status = 'publish'", self::$last_posts_request );
$this->assertStringContainsString( "{$wpdb->posts}.post_type = 'unregistered_cpt'", self::$last_posts_request );
$this->assertStringContainsString( "{$wpdb->posts}.post_status = 'publish'", self::$last_posts_request );
// $wp_query recovers to the post type "post" and is expected to return one.
$this->assertCount( 1, $wp_query->get_posts() );
}