Skip to content
Snippets Groups Projects
Commit 8e386725 authored by Erick Hitter's avatar Erick Hitter
Browse files

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
```
parent 22a7e572
No related branches found
No related tags found
1 merge request!18Fix fatal in test run under PHP 8
Pipeline #4785 failed
This commit is part of merge request !18. Comments created here will be created in the context of that merge request.
...@@ -27,8 +27,5 @@ function _manually_load_plugin() { ...@@ -27,8 +27,5 @@ function _manually_load_plugin() {
} }
tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' );
// Load base class for compatibility.
require __DIR__ . '/class-test-case.php';
// Start up the WP testing environment. // Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php'; require $_tests_dir . '/includes/bootstrap.php';
<?php
/**
* Compatibility shim for PHP 8 tests.
*
* Yoast polyfills add return type declaration to `setUp` that isn't supported
* before PHP 7.1, hence this workaround.
*/
namespace View_All_Posts_Pages\Tests;
use WP_UnitTestCase;
if ( version_compare( phpversion(), '8.0.0', '<' ) ) {
/**
* Class TestCase.
*/
abstract class TestCase extends WP_UnitTestCase {
/**
* Set up the test.
*
* @return void
*/
protected function setUp() {
parent::setUp();
$this->_do_set_up();
}
/**
* Set up the test.
*
* @return void
*/
abstract function _do_set_up();
}
} else {
abstract class TestCase extends WP_UnitTestCase {
/**
* Set up the test.
*
* @return void
*/
protected function setUp(): void {
parent::setUp();
$this->_do_set_up();
}
/**
* Set up the test.
*
* Not setting a return type as implementing methods cannot always do
* so.
*
* @return void
*/
abstract protected function _do_set_up();
}
}
...@@ -5,12 +5,10 @@ ...@@ -5,12 +5,10 @@
* @package View_All_Posts_Pages * @package View_All_Posts_Pages
*/ */
use View_All_Posts_Pages\Tests\TestCase;
/** /**
* Content-filter test case. * Content-filter test case.
*/ */
class PostFilters extends TestCase { class PostFilters extends WP_UnitTestCase {
/** /**
* Text for each page of multipage post. * Text for each page of multipage post.
* *
...@@ -42,7 +40,7 @@ class PostFilters extends TestCase { ...@@ -42,7 +40,7 @@ class PostFilters extends TestCase {
* Not using `setUp` because Yoast polyfills add a return type for PHP 8 * Not using `setUp` because Yoast polyfills add a return type for PHP 8
* that isn't supported before PHP 7.1. * that isn't supported before PHP 7.1.
*/ */
protected function _do_set_up() { protected function set_up() {
static::$post_id = $this->factory->post->create( static::$post_id = $this->factory->post->create(
array( array(
'post_title' => 'Pagination Test', 'post_title' => 'Pagination Test',
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment