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

@@ -2484,7 +2484,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
'search' => false,
)
);
$this->assertNotContains( 'comment_author LIKE', $q->request );
$this->assertStringNotContainsString( 'comment_author LIKE', $q->request );
}
/**
@@ -2497,7 +2497,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
'search' => null,
)
);
$this->assertNotContains( 'comment_author LIKE', $q->request );
$this->assertStringNotContainsString( 'comment_author LIKE', $q->request );
}
/**
@@ -2510,7 +2510,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
'search' => false,
)
);
$this->assertNotContains( 'comment_author LIKE', $q->request );
$this->assertStringNotContainsString( 'comment_author LIKE', $q->request );
}
/**
@@ -2524,7 +2524,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
'search' => 0,
)
);
$this->assertContains( "comment_author LIKE '%0%'", $wpdb->remove_placeholder_escape( $q->request ) );
$this->assertStringContainsString( "comment_author LIKE '%0%'", $wpdb->remove_placeholder_escape( $q->request ) );
}
/**
@@ -2538,7 +2538,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
'search' => '0',
)
);
$this->assertContains( "comment_author LIKE '%0%'", $wpdb->remove_placeholder_escape( $q->request ) );
$this->assertStringContainsString( "comment_author LIKE '%0%'", $wpdb->remove_placeholder_escape( $q->request ) );
}
public function test_orderby_default() {
@@ -2547,7 +2547,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
$q = new WP_Comment_Query();
$q->query( array() );
$this->assertContains( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request );
$this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request );
}
public function test_orderby_single() {
@@ -2560,7 +2560,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
)
);
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent", $q->request );
$this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent", $q->request );
}
public function test_orderby_single_invalid() {
@@ -2573,7 +2573,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
)
);
$this->assertContains( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request );
$this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request );
}
public function test_orderby_space_separated() {
@@ -2586,7 +2586,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
)
);
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request );
$this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request );
}
public function test_orderby_comma_separated() {
@@ -2599,7 +2599,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
)
);
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request );
$this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request );
}
public function test_orderby_flat_array() {
@@ -2612,7 +2612,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
)
);
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request );
$this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request );
}
public function test_orderby_array_contains_invalid_item() {
@@ -2625,7 +2625,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
)
);
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request );
$this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_approved DESC", $q->request );
}
public function test_orderby_array_contains_all_invalid_items() {
@@ -2638,7 +2638,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
)
);
$this->assertContains( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request );
$this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_date_gmt", $q->request );
}
/**
@@ -2652,7 +2652,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
)
);
$this->assertNotContains( 'ORDER BY', $q->request );
$this->assertStringNotContainsString( 'ORDER BY', $q->request );
}
/**
@@ -2666,7 +2666,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
)
);
$this->assertNotContains( 'ORDER BY', $q->request );
$this->assertStringNotContainsString( 'ORDER BY', $q->request );
}
/**
@@ -2680,7 +2680,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
)
);
$this->assertNotContains( 'ORDER BY', $q->request );
$this->assertStringNotContainsString( 'ORDER BY', $q->request );
}
/**
@@ -2701,7 +2701,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
)
);
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt ASC, $wpdb->comments.comment_ID DESC", $q->request );
$this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt ASC, $wpdb->comments.comment_ID DESC", $q->request );
}
/**
@@ -2722,7 +2722,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
)
);
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_ID DESC", $q->request );
$this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_ID DESC", $q->request );
}
/**
@@ -2743,7 +2743,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
)
);
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt DESC, $wpdb->comments.comment_ID DESC", $q->request );
$this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt DESC, $wpdb->comments.comment_ID DESC", $q->request );
}
/**
@@ -2763,7 +2763,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
)
);
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt ASC, $wpdb->comments.comment_ID ASC", $q->request );
$this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date_gmt ASC, $wpdb->comments.comment_ID ASC", $q->request );
}
/**
@@ -2783,7 +2783,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
)
);
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date ASC, $wpdb->comments.comment_ID ASC", $q->request );
$this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent DESC, $wpdb->comments.comment_date ASC, $wpdb->comments.comment_ID ASC", $q->request );
}
/**
@@ -2802,7 +2802,7 @@ class Tests_Comment_Query extends WP_UnitTestCase {
)
);
$this->assertContains( "ORDER BY $wpdb->comments.comment_agent ASC, $wpdb->comments.comment_ID DESC", $q->request );
$this->assertStringContainsString( "ORDER BY $wpdb->comments.comment_agent ASC, $wpdb->comments.comment_ID DESC", $q->request );
}
/**