Skip to content

Commit

Permalink
Merge pull request #7650 from Automattic/fix/deprecation-notices
Browse files Browse the repository at this point in the history
Fix deprecation notices on PHP 8.2
  • Loading branch information
m1r0 authored Aug 1, 2024
2 parents 53dbffa + 6a2ac9b commit a13fc40
Show file tree
Hide file tree
Showing 30 changed files with 207 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [7.4, 8.1]
php: [7.4, 8.2]
steps:
- name: Download Build Artifact
uses: actions/download-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
matrix:
wp: ['latest']
wpmu: [0]
php: ['7.4', '8.0']
php: ['7.4', '8.2']
include:
- php: 7.4
wp: '6.1'
Expand Down
4 changes: 0 additions & 4 deletions changelog/fix-deprecation-notice-on-question-edit-screen

This file was deleted.

4 changes: 0 additions & 4 deletions changelog/fix-deprecation-notice-on-reports-screen

This file was deleted.

4 changes: 4 additions & 0 deletions changelog/fix-deprecation-notices
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Deprecation notices on PHP 8.2
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ private function get_learner_courses_html( $user_id ) {
$more_button = '';

foreach ( $courses as $course ) {
$html_items[] = '<a href="' . esc_url( $this->controller->get_learner_management_course_url( $course->ID ) ) .
$html_items[] = '<a href="' . esc_url( (string) $this->controller->get_learner_management_course_url( $course->ID ) ) .
'" class="sensei-students__enrolled-course" data-course-id="' . esc_attr( $course->ID ) . '">' .
esc_html( $course->post_title ) .
'</a>';
Expand Down
2 changes: 1 addition & 1 deletion includes/class-sensei-lesson.php
Original file line number Diff line number Diff line change
Expand Up @@ -4804,7 +4804,7 @@ public static function course_signup_link() {
* @return {bool} Whether to show the course sign up notice.
*/
if ( apply_filters( 'sensei_lesson_show_course_signup_notice', $show_course_signup_notice, $course_id ) ) {
$course_link = '<a href="' . esc_url( Sensei()->lesson->get_take_course_url( $course_id ) ) . '" title="' . esc_attr__( 'Sign Up', 'sensei-lms' ) . '">';
$course_link = '<a href="' . esc_url( (string) Sensei()->lesson->get_take_course_url( $course_id ) ) . '" title="' . esc_attr__( 'Sign Up', 'sensei-lms' ) . '">';
$course_link .= esc_html__( 'course', 'sensei-lms' );
$course_link .= '</a>';

Expand Down
3 changes: 1 addition & 2 deletions includes/class-sensei-quiz.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

use Sensei\Internal\Student_Progress\Quiz_Progress\Models\Quiz_Progress_Interface;
use Sensei\Internal\Student_Progress\Quiz_Progress\Repositories\Quiz_Progress_Repository_Factory;

if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
Expand Down Expand Up @@ -1335,7 +1334,7 @@ public function get_user_answers_feedback( $lesson_id, $user_id = 0 ) {

foreach ( $encoded_feedback as $question_id => $feedback ) {

$answers_feedback[ $question_id ] = base64_decode( $feedback );
$answers_feedback[ $question_id ] = base64_decode( (string) $feedback );

}

Expand Down
2 changes: 1 addition & 1 deletion includes/course-theme/class-sensei-course-theme-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private static function get_property_value( $value ) {
);
$value = "var(--wp--$unwrapped_name)";
} elseif ( preg_match( '/^[a-z0-9-]+$/i', $value ) ) {
$value = "var(--wp--preset--color--${value})";
$value = "var(--wp--preset--color--{$value})";
}

return $value;
Expand Down
2 changes: 1 addition & 1 deletion includes/data-port/class-sensei-data-port-utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ private static function create_term( $term_name, $taxonomy_name, $teacher_user_i
*
* @return array|string[]
*/
public static function split_list_safely( $str_list, $remove_quotes = false ) {
public static function split_list_safely( string $str_list, bool $remove_quotes = false ) {
if ( empty( trim( $str_list ) ) ) {
return [];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ private function get_taxonomy_terms() {

$taxonomy_terms[ Sensei_Data_Port_Question_Schema::TAXONOMY_QUESTION_CATEGORY ] = [];

$category_list = Sensei_Data_Port_Utilities::split_list_safely( $this->get_value( Sensei_Data_Port_Question_Schema::COLUMN_CATEGORIES ), true );
$category_list = Sensei_Data_Port_Utilities::split_list_safely( (string) $this->get_value( Sensei_Data_Port_Question_Schema::COLUMN_CATEGORIES ), true );
if ( ! empty( $category_list ) ) {
foreach ( $category_list as $category ) {
$category_term = Sensei_Data_Port_Utilities::get_term( $category, Sensei_Data_Port_Question_Schema::TAXONOMY_QUESTION_CATEGORY );
Expand Down
4 changes: 1 addition & 3 deletions includes/internal/emails/class-email-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
namespace Sensei\Internal\Emails;

use Sensei_List_Table;
use WP_Post;
use WP_Query;

if ( ! defined( 'ABSPATH' ) ) {
exit;
Expand Down Expand Up @@ -130,7 +128,7 @@ protected function get_row_data( $post ) {
$description = $is_available ?
sprintf(
'<strong><a href="%1$s" class="row-title">%2$s</a></strong>%3$s',
esc_url( get_edit_post_link( $post ) ),
esc_url( (string) get_edit_post_link( $post ) ),
get_post_meta( $post->ID, '_sensei_email_description', true ),
$this->row_actions( $actions )
) : sprintf(
Expand Down
2 changes: 1 addition & 1 deletion includes/lib/usage-tracking/class-usage-tracking-base.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ private function send_tracks_request( $event, $properties = array(), $event_time
$p = array();

foreach ( $properties as $key => $value ) {
$p[] = rawurlencode( $key ) . '=' . rawurlencode( $value );
$p[] = rawurlencode( $key ) . '=' . rawurlencode( (string) $value );
}

$pixel .= '?' . implode( '&', $p ) . '&_=_'; // EOF marker.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ class Sensei_Base_Usage_Tracking_Test extends WP_UnitTestCase {
private $event_counts = array();
private $track_http_request = array();

/**
* Usage tracking test subclass instance.
*
* @var Usage_Tracking_Test_Subclass
*/
private $usage_tracking;

public function setUp(): void {
parent::setUp();
// Update the class name here to match the Usage Tracking class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Sensei_REST_API_Course_Progress_Controller extends \WP_REST_Controller {
*
* @param string $namespace Routes namespace.
*/
public function __construct( $namespace ) {
public function __construct( $namespace ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.namespaceFound -- The variable name if defined in the WP_REST_Controller class.
$this->namespace = $namespace;
}

Expand Down Expand Up @@ -74,6 +74,7 @@ public function batch_delete_items( WP_REST_Request $request ) {
$student = new WP_User( $student_id );
$result[ $student_id ] = false;
if ( $student->exists() ) {
$result[ $student_id ] = array();
foreach ( $course_ids as $course_id ) {
$result[ $student_id ][ $course_id ] = false;
if ( Sensei_Utils::has_started_course( $course_id, $student_id ) ) {
Expand All @@ -83,7 +84,7 @@ public function batch_delete_items( WP_REST_Request $request ) {
}
}

return new WP_REST_Response( $result, WP_HTTP::OK );
return new WP_REST_Response( $result, WP_Http::OK );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function batch_create_items( WP_REST_Request $request ) {
$user = new WP_User( $user_id );
$result[ $user_id ] = false;
if ( $user->exists() ) {
$result[ $user_id ] = array();
foreach ( $course_ids as $course_id ) {
$course_enrolment = Sensei_Course_Enrolment::get_course_instance( $course_id );
$result[ $user_id ][ $course_id ] = $course_enrolment->enrol( $user_id );
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
convertDeprecationsToExceptions="true"
verbose="true"
>
<php>
Expand Down
23 changes: 23 additions & 0 deletions tests/framework/factories/class-sensei-factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,41 +45,64 @@ class Sensei_Factory extends WP_UnitTest_Factory {
protected $basic_test_question_ids;

/**
* Course factory.
*
* @var WP_UnitTest_Factory_For_Course
*/
public $course;

/**
* Lesson factory.
*
* @var WP_UnitTest_Factory_For_Lesson
*/
public $lesson;

/**
* Quiz factory.
*
* @var WP_UnitTest_Factory_For_Quiz
*/
public $quiz;

/**
* Question factory.
*
* @var WP_UnitTest_Factory_For_Question
*/
public $question;

/**
* Multiple question factory.
*
* @var WP_UnitTest_Factory_For_Multiple_Question
*/
public $multiple_question;

/**
* Module factory.
*
* @var WP_UnitTest_Factory_For_Module
*/
public $module;

/**
* Question category factory.
*
* @var WP_UnitTest_Factory_For_Question_Category
*/
public $question_category;

/**
* Course category factory.
*
* @var Sensei_UnitTest_Factory_For_Course_Category
*/
public $course_category;

/**
* Message factory.
*
* @var WP_UnitTest_Factory_For_Message
*/
public $message;
Expand Down
43 changes: 43 additions & 0 deletions tests/framework/trait-sensei-hpps-helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

// phpcs:disable WordPress.NamingConventions.ValidFunctionName.MethodNameInvalid -- Using PHPUnit conventions.
// phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore

use Sensei\Internal\Quiz_Submission\Answer\Repositories\Answer_Repository_Factory;
use Sensei\Internal\Quiz_Submission\Grade\Repositories\Grade_Repository_Factory;
Expand All @@ -25,6 +26,48 @@
* @since 4.20.0
*/
trait Sensei_HPPS_Helpers {
/**
* Course progress repository.
*
* @var \Sensei\Internal\Student_Progress\Course_Progress\Repositories\Course_Progress_Repository_Interface
*/
private $_course_progress_repository;

/**
* Lesson progress repository.
*
* @var \Sensei\Internal\Student_Progress\Lesson_Progress\Repositories\Lesson_Progress_Repository_Interface
*/
private $_lesson_progress_repository;

/**
* Quiz repository.
*
* @var \Sensei\Internal\Student_Progress\Quiz_Progress\Repositories\Quiz_Progress_Repository_Interface
*/
private $_quiz_progress_repository;

/**
* Submission repository.
*
* @var \Sensei\Internal\Quiz_Submission\Submission\Repositories\Submission_Repository_Interface
*/
private $_quiz_submission_repository;

/**
* Answer repository.
*
* @var \Sensei\Internal\Quiz_Submission\Answer\Repositories\Answer_Repository_Interface
*/
private $_quiz_answer_repository;

/**
* Grade repository.
*
* @var \Sensei\Internal\Quiz_Submission\Grade\Repositories\Grade_Repository_Interface
*/
private $_quiz_grade_repository;

private function enable_hpps_tables_repository() {
Sensei()->settings->settings['experimental_progress_storage_repository'] = Progress_Storage_Settings::TABLES_STORAGE;

Expand Down
9 changes: 9 additions & 0 deletions tests/unit-tests/admin/test-class-sensei-setup-wizard.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
class Sensei_Setup_Wizard_Test extends WP_UnitTestCase {
use Sensei_Test_Redirect_Helpers;

/**
* The original screen.
*
* @var WP_Screen
*/
private $original_screen;

/**
* Set up before the class.
*/
Expand Down Expand Up @@ -339,7 +346,9 @@ public function testRenderWizardPage_WhenRendered_ClearsRedirectOption() {
update_option( 'sensei_activation_redirect', 1 );

// Act.
ob_start();
Sensei()->setup_wizard->render_wizard_page();
ob_end_clean();

// Assert.
$this->assertFalse( get_option( 'sensei_activation_redirect', false ) );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class Sensei_Course_Progress_Block_Test extends WP_UnitTestCase {
*/
private $block;

/**
* The course post.
*
* @var WP_Post
*/
private $course;

/**
* Factory for setting up testing data.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ class Sensei_Block_Learner_Courses_Test extends WP_UnitTestCase {
*/
private $block;

/**
* The course post.
*
* @var WP_Post
*/
private $course;

/**
* Factory for setting up testing data.
*
* @var Sensei_Factory
*/
protected $factory;

/**
* Set up the test.
*/
Expand Down
14 changes: 14 additions & 0 deletions tests/unit-tests/blocks/test-class-sensei-block-view-results.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,20 @@ class Sensei_Block_View_Results_Test extends WP_UnitTestCase {
*/
private $block;

/**
* The course post.
*
* @var WP_Post
*/
private $course;

/**
* Factory for setting up testing data.
*
* @var Sensei_Factory
*/
protected $factory;

/**
* Block content.
*/
Expand Down
Loading

0 comments on commit a13fc40

Please sign in to comment.