Skip to content

Commit

Permalink
Tests: Apply fixes for PHP 8.1 and 8.2
Browse files Browse the repository at this point in the history
- Make dynamic properties explicit.
- Skip a test that generates a deprecation notice in PHP 8.1 + WP < 6.3.
  • Loading branch information
GaryJones committed Jul 23, 2023
1 parent 0f3def8 commit 43c4136
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 4 deletions.
3 changes: 2 additions & 1 deletion php/class-coauthors-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ public function get_coauthors_search_results( $request ) {
$response = array();

$search = strtolower( $request->get_param( 'q' ) );
$ignore = explode( ',', $request->get_param( 'existing_authors' ) );
$ignorable = null === $request->get_param( 'existing_authors' ) ? '' : $request->get_param( 'existing_authors' );
$ignore = explode( ',', $ignorable );
$authors = $this->coauthors->search_authors( $search, $ignore );

if ( ! empty( $authors ) ) {
Expand Down
3 changes: 0 additions & 3 deletions php/class-coauthors-guest-authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,6 @@ function __construct() {
);
register_post_type( $this->post_type, $args );

// Some of the common sizes used by get_avatar
$this->avatar_sizes = array();

// Hacky way to remove the title and the editor
remove_post_type_support( $this->post_type, 'title' );
remove_post_type_support( $this->post_type, 'editor' );
Expand Down
10 changes: 10 additions & 0 deletions tests/coauthorsplus-testcase.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
* Base unit test class for Co-Authors Plus
*/
class CoAuthorsPlus_TestCase extends \Yoast\WPTestUtils\WPIntegration\TestCase {

/**
* @var CoAuthors_Plus
*/
protected $_cap;
/**
* @var Endpoints
*/
protected $_api;

public function set_up() {
parent::set_up();

Expand Down
15 changes: 15 additions & 0 deletions tests/test-coauthors-endpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,21 @@ class Test_Endpoints extends CoAuthorsPlus_TestCase {

use \DMS\PHPUnitExtensions\ArraySubset\ArraySubsetAsserts;

private $author1;
private $author2;
private $editor1;
private $contributor1;
private $subscriber1;
/**
* @var int|WP_Error
*/
private $coauthor1;
/**
* @var int|WP_Error
*/
private $coauthor2;
private $post;

public function set_up() {

parent::set_up();
Expand Down
5 changes: 5 additions & 0 deletions tests/test-coauthors-guest-authors.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ class Test_CoAuthors_Guest_Authors extends CoAuthorsPlus_TestCase {

use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains;

private $admin1;
private $author1;
private $editor1;
private $post;

public function set_up() {

parent::set_up();
Expand Down
4 changes: 4 additions & 0 deletions tests/test-coauthors-plus.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

class Test_CoAuthors_Plus extends CoAuthorsPlus_TestCase {

private $author1;
private $editor1;
private $post;

public function set_up() {

parent::set_up();
Expand Down
20 changes: 20 additions & 0 deletions tests/test-manage-coauthors.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@

class Test_Manage_CoAuthors extends CoAuthorsPlus_TestCase {

private $admin1;
private $author1;
private $editor1;
/**
* @var int|WP_Error
*/
private $author1_post1;
/**
* @var int|WP_Error
*/
private $author1_post2;
/**
* @var int|WP_Error
*/
private $author1_page1;
/**
* @var int|WP_Error
*/
private $author1_page2;

public function set_up() {
parent::set_up();

Expand Down
13 changes: 13 additions & 0 deletions tests/test-template-tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ class Test_Template_Tags extends CoAuthorsPlus_TestCase {

use Yoast\PHPUnitPolyfills\Polyfills\AssertStringContains;

private $author1;
private $editor1;
private $post;

public function set_up() {

parent::set_up();
Expand Down Expand Up @@ -718,6 +722,15 @@ public function test_coauthors_links_single_author_url_is_set() {
* @covers ::coauthors_links_single()
*/
public function test_coauthors_links_single_when_url_not_exist() {
global $wp_version;
if ( PHP_VERSION_ID >= 80100 && version_compare( $wp_version, '6.3.0', '<' ) ) {
/*
* Ignoring PHP 8.1 "null to non-nullable" deprecation that is fixed in WP 6.3.
*
* @see https://core.trac.wordpress.org/ticket/58157
*/
$this->markTestSkipped( 'PHP 8.1 gives a deprecation notice that is fixed in WP 6.3' );
}

global $post, $authordata;

Expand Down

0 comments on commit 43c4136

Please sign in to comment.