Skip to content
Snippets Groups Projects

Fix fatal in test run under PHP 8

Merged Erick Hitter requested to merge fix/test into master
@@ -36,11 +36,10 @@ class PostFilters extends WP_UnitTestCase {
/**
* Prepare data for tests.
*
* Not using `setUp` because Yoast polyfills add a return type for PHP 8
* that isn't supported before PHP 7.1.
*/
protected function _create_post() {
public function set_up() {
parent::set_up();
static::$post_id = $this->factory->post->create(
array(
'post_title' => 'Pagination Test',
@@ -55,8 +54,6 @@ class PostFilters extends WP_UnitTestCase {
* Test retrieving page 1 content.
*/
public function test_view_page_1() {
$this->_create_post();
query_posts(
array(
'p' => static::$post_id,
@@ -76,8 +73,6 @@ class PostFilters extends WP_UnitTestCase {
* Test retrieving page 2 content.
*/
public function test_view_page_2() {
$this->_create_post();
query_posts(
array(
'p' => static::$post_id,
@@ -98,8 +93,6 @@ class PostFilters extends WP_UnitTestCase {
* Test retrieving page 3 content.
*/
public function test_view_page_3() {
$this->_create_post();
query_posts(
array(
'p' => static::$post_id,
@@ -120,8 +113,6 @@ class PostFilters extends WP_UnitTestCase {
* Test retrieving "view all" contents.
*/
public function test_view_all() {
$this->_create_post();
query_posts(
array(
'p' => static::$post_id,
@@ -137,7 +128,7 @@ class PostFilters extends WP_UnitTestCase {
$content = get_the_content();
foreach ( static::$pages_content as $page => $text ) {
$this->assertContains( $text, $content, "Failed to assert that content contained page {$page}." );
$this->assertStringContainsString( $text, $content, "Failed to assert that content contained page {$page}." );
}
}
}
Loading