From 19660d31e2fd92270d364f8586cb31ad7fbd92e9 Mon Sep 17 00:00:00 2001 From: Erick Hitter <git-contrib@ethitter.com> Date: Sat, 11 Jun 2022 12:51:20 -0700 Subject: [PATCH] Fix fatal in test run under PHP 8 ``` Fatal error: Declaration of PostFilters::setUp() must be compatible with Yoast\PHPUnitPolyfills\TestCases\TestCase::setUp(): void in /builds/wp-plugins/view-all-posts-pages/tests/test-post-filters.php on line 40 ``` --- tests/test-post-filters.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/test-post-filters.php b/tests/test-post-filters.php index 38a9037..c1a97a8 100755 --- a/tests/test-post-filters.php +++ b/tests/test-post-filters.php @@ -36,10 +36,11 @@ 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 setUp() { - parent::setUp(); - + protected function _create_post() { static::$post_id = $this->factory->post->create( array( 'post_title' => 'Pagination Test', @@ -54,6 +55,8 @@ 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, @@ -73,6 +76,8 @@ 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, @@ -93,6 +98,8 @@ 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, @@ -113,6 +120,8 @@ 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, -- GitLab