Make WordPress Core

Changeset 56421


Ignore:
Timestamp:
08/21/2023 03:53:04 PM (14 months ago)
Author:
SergeyBiryukov
Message:

Build/Test Tools: Update PHPUnit Polyfills to version 1.1.0.

PHPUnit 9.6.1 deprecated the assertObjectHasAttribute() and assertObjectNotHasAttribute() methods, leading to deprecation notices in a number of tests.

PHPUnit 10.1.0 brought the methods back by popular request, though renamed as assertObjectHasProperty() and assertObjectNotHasProperty(), to prevent confusion with PHP 8.0 attributes.

This meant that users which cannot (yet) upgrade to PHPUnit 10.1+ would always have deprecation notices for these methods without recourse. So, after much discussion, the new methods have been backported to PHPUnit 9.6.11, leaving just the 10.0.x series with a deprecation notice and no recourse.

What does this mean for WordPress?

WordPress uses the PHPUnit Polyfills to be able to write tests for the most recent versions of PHPUnit, with the Polyfills taking care of polyfilling any new PHPUnit methods on older PHPUnit versions.

  • The PHPUnit Polyfills 1.x series supports PHPUnit 4.x to 9.x.
  • The PHPUnit Polyfills 2.x series supports PHPUnit 5.x to 10.x.

WordPress currently runs against PHPUnit 6.x to 9.x with PHPUnit Polyfills 1.x, while the new methods were previously only included in PHPUnit Polyfills 2.0.0+, as they were introduced in PHPUnit 10.x.

Since the assertObjectHasProperty() and assertObjectNotHasProperty() methods have been backported to PHPUnit 9.x, the PHPUnit Polyfills will now include these methods in the 1.x series as well.

By upgrading to the latest PHPUnit Polyfills 1.1.0 release, we can get rid of the deprecation notices related to the use of the assertObjectHasAttribute() and assertObjectNotHasAttribute() methods.

This could have implications for plugins or themes running integration tests with WordPress if they have set their PHPUnit Polyfills dependency to a fixed version or have a too strict version constraint (limiting the PHPUnit Polyfills to the 1.0.x series). The solution for those plugins or themes is to update their version constraints for the PHPUnit Polyfills to allow for the 1.1.x series.

Follow-up to [51559], [51598].

Props jrf, ayeshrajans.
Fixes #59150.

Location:
trunk
Files:
18 edited

Legend:

Unmodified
Added
Removed
  • trunk/composer.json

    r56141 r56421  
    1818        "wp-coding-standards/wpcs": "~2.3.0",
    1919        "phpcompatibility/phpcompatibility-wp": "~2.1.3",
    20         "yoast/phpunit-polyfills": "^1.0.1"
     20        "yoast/phpunit-polyfills": "^1.1.0"
    2121    },
    2222    "config": {
  • trunk/tests/phpunit/includes/abstract-testcase.php

    r56212 r56421  
    870870
    871871        foreach ( $fields as $field_name => $field_value ) {
    872             $this->assertObjectHasAttribute( $field_name, $actual, $message . " Property $field_name does not exist on the object." );
     872            $this->assertObjectHasProperty( $field_name, $actual, $message . " Property $field_name does not exist on the object." );
    873873            $this->assertSame( $field_value, $actual->$field_name, $message . " Value of property $field_name is not $field_value." );
    874874        }
  • trunk/tests/phpunit/includes/bootstrap.php

    r55891 r56421  
    140140 * Only needs updating when new polyfill features start being used in the test suite.
    141141 */
    142 $phpunit_polyfills_minimum_version = '1.0.1';
     142$phpunit_polyfills_minimum_version = '1.1.0';
    143143if ( class_exists( '\Yoast\PHPUnitPolyfills\Autoload' )
    144144    && ( defined( '\Yoast\PHPUnitPolyfills\Autoload::VERSION' ) === false
  • trunk/tests/phpunit/includes/phpunit-adapter-testcase.php

    r51567 r56421  
    77 *
    88 * This class enhances the PHPUnit native `TestCase` with polyfills
    9  * for assertions and expectation methods added between PHPUnit 4.8 - 9.5.
     9 * for assertions and expectation methods added between PHPUnit 4.8 - 9.6.
    1010 *
    1111 * Additionally, the Polyfill TestCase offers a workaround for the addition
  • trunk/tests/phpunit/tests/ajax/wpAjaxImageEditor.php

    r55935 r56421  
    5252        $ret = wp_save_image( $id );
    5353
    54         $this->assertObjectHasAttribute( 'error', $ret );
     54        $this->assertObjectHasProperty( 'error', $ret );
    5555        $this->assertEquals( 'Images cannot be scaled to a size larger than the original.', $ret->error );
    5656    }
  • trunk/tests/phpunit/tests/blocks/register.php

    r56044 r56421  
    721721        $registry   = WP_Block_Type_Registry::get_instance();
    722722        $block_type = $registry->get_registered( 'core/test-static' );
    723         $this->assertObjectHasAttribute( 'editor_script_handles', $block_type );
     723        $this->assertObjectHasProperty( 'editor_script_handles', $block_type );
    724724        $actual_script         = $block_type->editor_script;
    725725        $actual_script_handles = $block_type->editor_script_handles;
     
    787787        $registry   = WP_Block_Type_Registry::get_instance();
    788788        $block_type = $registry->get_registered( 'core/test-static' );
    789         $this->assertObjectHasAttribute( 'editor_script_handles', $block_type );
     789        $this->assertObjectHasProperty( 'editor_script_handles', $block_type );
    790790        $actual_script         = $block_type->editor_script;
    791791        $actual_script_handles = $block_type->editor_script_handles;
  • trunk/tests/phpunit/tests/comment.php

    r56222 r56421  
    482482        );
    483483
    484         $this->assertObjectHasAttribute(
     484        $this->assertObjectHasProperty(
    485485            'comment_author',
    486486            $comment,
  • trunk/tests/phpunit/tests/customize/manager.php

    r55942 r56421  
    33403340        $setting    = $manager->add_setting( $setting_id );
    33413341        $this->assertSame( 'WP_Customize_Setting', get_class( $setting ) );
    3342         $this->assertObjectNotHasAttribute( 'custom', $setting );
     3342        $this->assertObjectNotHasProperty( 'custom', $setting );
    33433343        $manager->remove_setting( $setting_id );
    33443344
     
    33473347        $setting = $manager->add_setting( $setting_id );
    33483348        $this->assertSame( 'Test_Dynamic_Customize_Setting', get_class( $setting ) );
    3349         $this->assertObjectHasAttribute( 'custom', $setting );
     3349        $this->assertObjectHasProperty( 'custom', $setting );
    33503350        $this->assertSame( 'foo', $setting->custom );
    33513351    }
  • trunk/tests/phpunit/tests/customize/nav-menu-item-setting.php

    r54865 r56421  
    927927        $this->assertSame( 'Custom Label', $nav_menu_item->type_label );
    928928
    929         $this->assertObjectNotHasAttribute( 'nav_menu_term_id', $nav_menu_item );
    930         $this->assertObjectNotHasAttribute( 'status', $nav_menu_item );
     929        $this->assertObjectNotHasProperty( 'nav_menu_term_id', $nav_menu_item );
     930        $this->assertObjectNotHasProperty( 'status', $nav_menu_item );
    931931        $this->assertSame( 'publish', $nav_menu_item->post_status );
    932932        $this->assertSame( 'nav_menu_item', $nav_menu_item->post_type );
    933         $this->assertObjectNotHasAttribute( 'position', $nav_menu_item );
     933        $this->assertObjectNotHasProperty( 'position', $nav_menu_item );
    934934        $this->assertSame( $post_value['position'], $nav_menu_item->menu_order );
    935935        $this->assertSame( $post_value['title'], $nav_menu_item->post_title );
     
    937937        $this->assertSame( 123, $nav_menu_item->db_id );
    938938        $this->assertSame( wp_get_current_user()->ID, $nav_menu_item->post_author );
    939         $this->assertObjectHasAttribute( 'type_label', $nav_menu_item );
     939        $this->assertObjectHasProperty( 'type_label', $nav_menu_item );
    940940        $expected = apply_filters( 'nav_menu_attr_title', wp_unslash( apply_filters( 'excerpt_save_pre', wp_slash( $post_value['attr_title'] ) ) ) );
    941941        $this->assertSame( $expected, $nav_menu_item->attr_title );
     
    10711071        $this->assertSame( '', $item_value['title'] );
    10721072        $item = $setting->value_as_wp_post_nav_menu_item();
    1073         $this->assertObjectHasAttribute( 'type_label', $item );
     1073        $this->assertObjectHasProperty( 'type_label', $item );
    10741074        $this->assertSame( $original_post_title, $item->original_title );
    10751075        $this->assertSame( $original_post_title, $item->title );
     
    10981098        $this->assertSame( '', $item_value['title'] );
    10991099        $item = $setting->value_as_wp_post_nav_menu_item();
    1100         $this->assertObjectHasAttribute( 'type_label', $item );
     1100        $this->assertObjectHasProperty( 'type_label', $item );
    11011101        $this->assertSame( $original_post_title, $item->original_title );
    11021102        $this->assertSame( $original_post_title, $item->title );
     
    11251125        $this->assertSame( '', $item_value['title'] );
    11261126        $item = $setting->value_as_wp_post_nav_menu_item();
    1127         $this->assertObjectHasAttribute( 'type_label', $item );
     1127        $this->assertObjectHasProperty( 'type_label', $item );
    11281128        $this->assertSame( $original_term_title, $item->original_title );
    11291129        $this->assertSame( $original_term_title, $item->title );
     
    11521152        $this->assertSame( '', $item_value['title'] );
    11531153        $item = $setting->value_as_wp_post_nav_menu_item();
    1154         $this->assertObjectHasAttribute( 'type_label', $item );
     1154        $this->assertObjectHasProperty( 'type_label', $item );
    11551155        $this->assertSame( $original_term_title, $item->original_title );
    11561156        $this->assertSame( $original_term_title, $item->title );
     
    11781178        $this->assertSame( '', $item_value['title'] );
    11791179        $item = $setting->value_as_wp_post_nav_menu_item();
    1180         $this->assertObjectHasAttribute( 'type_label', $item );
     1180        $this->assertObjectHasProperty( 'type_label', $item );
    11811181        $this->assertSame( get_post_type_object( 'press_release' )->labels->archives, $item->original_title );
    11821182        $this->assertSame( get_post_type_object( 'press_release' )->labels->archives, $item->title );
     
    12041204        $this->assertSame( '', $item_value['title'] );
    12051205        $item = $setting->value_as_wp_post_nav_menu_item();
    1206         $this->assertObjectHasAttribute( 'type_label', $item );
     1206        $this->assertObjectHasProperty( 'type_label', $item );
    12071207        $this->assertSame( get_post_type_object( 'press_release' )->labels->archives, $item->original_title );
    12081208        $this->assertSame( get_post_type_object( 'press_release' )->labels->archives, $item->title );
  • trunk/tests/phpunit/tests/post.php

    r55365 r56421  
    237237
    238238        $counts = wp_count_posts();
    239         $this->assertObjectHasAttribute( 'test', $counts );
     239        $this->assertObjectHasProperty( 'test', $counts );
    240240        $this->assertSame( 0, $counts->test );
    241241    }
  • trunk/tests/phpunit/tests/post/getPostTypeLabels.php

    r51331 r56421  
    9696        unregister_post_type( 'foo' );
    9797
    98         $this->assertObjectHasAttribute( 'labels', $post_type_object );
    99         $this->assertObjectHasAttribute( 'label', $post_type_object );
    100         $this->assertObjectHasAttribute( 'not_found_in_trash', $post_type_object->labels );
     98        $this->assertObjectHasProperty( 'labels', $post_type_object );
     99        $this->assertObjectHasProperty( 'label', $post_type_object );
     100        $this->assertObjectHasProperty( 'not_found_in_trash', $post_type_object->labels );
    101101    }
    102102
     
    123123        register_post_type( 'foo' );
    124124
    125         $this->assertObjectHasAttribute( 'featured_image', get_post_type_object( 'foo' )->labels );
    126         $this->assertObjectHasAttribute( 'set_featured_image', get_post_type_object( 'foo' )->labels );
     125        $this->assertObjectHasProperty( 'featured_image', get_post_type_object( 'foo' )->labels );
     126        $this->assertObjectHasProperty( 'set_featured_image', get_post_type_object( 'foo' )->labels );
    127127
    128128        unregister_post_type( 'foo' );
  • trunk/tests/phpunit/tests/post/updatePostCache.php

    r53483 r56421  
    5858        );
    5959
    60         $this->assertObjectHasAttribute(
     60        $this->assertObjectHasProperty(
    6161            'filter',
    6262            $cached_post,
     
    9999        );
    100100
    101         $this->assertObjectHasAttribute(
     101        $this->assertObjectHasProperty(
    102102            'filter',
    103103            $cached_post,
     
    127127        );
    128128
    129         $this->assertObjectHasAttribute(
     129        $this->assertObjectHasProperty(
    130130            'filter',
    131131            $cached_post,
  • trunk/tests/phpunit/tests/rest-api/rest-server.php

    r56096 r56421  
    12621262        $result = json_decode( rest_get_server()->sent_body );
    12631263
    1264         $this->assertObjectNotHasAttribute( 'code', $result );
     1264        $this->assertObjectNotHasProperty( 'code', $result );
    12651265    }
    12661266
  • trunk/tests/phpunit/tests/rest-api/wpRestTemplatesController.php

    r56248 r56421  
    871871        $this->assertInstanceOf( 'stdClass', $prepared, 'The item could not be prepared for the database.' );
    872872
    873         $this->assertObjectHasAttribute( 'post_type', $prepared, 'The "post_type" was not included in the prepared template part.' );
    874         $this->assertObjectHasAttribute( 'post_status', $prepared, 'The "post_status" was not included in the prepared template part.' );
    875         $this->assertObjectHasAttribute( 'tax_input', $prepared, 'The "tax_input" was not included in the prepared template part.' );
     873        $this->assertObjectHasProperty( 'post_type', $prepared, 'The "post_type" was not included in the prepared template part.' );
     874        $this->assertObjectHasProperty( 'post_status', $prepared, 'The "post_status" was not included in the prepared template part.' );
     875        $this->assertObjectHasProperty( 'tax_input', $prepared, 'The "tax_input" was not included in the prepared template part.' );
    876876        $this->assertArrayHasKey( 'wp_theme', $prepared->tax_input, 'The "wp_theme" tax was not included in the prepared template part.' );
    877877        $this->assertArrayHasKey( 'wp_template_part_area', $prepared->tax_input, 'The "wp_template_part_area" tax was not included in the prepared template part.' );
    878         $this->assertObjectHasAttribute( 'post_content', $prepared, 'The "post_content" was not included in the prepared template part.' );
    879         $this->assertObjectHasAttribute( 'post_title', $prepared, 'The "post_title" was not included in the prepared template part.' );
     878        $this->assertObjectHasProperty( 'post_content', $prepared, 'The "post_content" was not included in the prepared template part.' );
     879        $this->assertObjectHasProperty( 'post_title', $prepared, 'The "post_title" was not included in the prepared template part.' );
    880880
    881881        $this->assertSame( 'wp_template_part', $prepared->post_type, 'The "post_type" in the prepared template part should be "wp_template_part".' );
  • trunk/tests/phpunit/tests/taxonomy.php

    r54090 r56421  
    285285        $post_type = 'test_cpt';
    286286        $this->assertFalse( get_post_type( $post_type ) );
    287         $this->assertObjectHasAttribute( 'name', register_post_type( $post_type ) );
     287        $this->assertObjectHasProperty( 'name', register_post_type( $post_type ) );
    288288
    289289        // Core taxonomy, core post type.
  • trunk/tests/phpunit/tests/term/query.php

    r55745 r56421  
    403403        foreach ( $terms as $term ) {
    404404            $this->assertInstanceOf( 'WP_Term', $term );
    405             $this->assertObjectHasAttribute( 'object_id', $term );
     405            $this->assertObjectHasProperty( 'object_id', $term );
    406406        }
    407407
     
    411411        foreach ( $terms as $term ) {
    412412            $this->assertInstanceOf( 'WP_Term', $term );
    413             $this->assertObjectHasAttribute( 'object_id', $term );
     413            $this->assertObjectHasProperty( 'object_id', $term );
    414414        }
    415415    }
  • trunk/tests/phpunit/tests/term/wpGetObjectTerms.php

    r55759 r56421  
    851851
    852852        $term = get_term( $t );
    853         $this->assertObjectNotHasAttribute( 'object_id', $term );
     853        $this->assertObjectNotHasProperty( 'object_id', $term );
    854854    }
    855855
  • trunk/tests/phpunit/tests/user/multisite.php

    r53489 r56421  
    6060            foreach ( $blogs_of_user as $blog_id => $blog ) {
    6161                $this->assertSame( $blog_id, $blog->userblog_id );
    62                 $this->assertObjectHasAttribute( 'userblog_id', $blog );
    63                 $this->assertObjectHasAttribute( 'blogname', $blog );
    64                 $this->assertObjectHasAttribute( 'domain', $blog );
    65                 $this->assertObjectHasAttribute( 'path', $blog );
    66                 $this->assertObjectHasAttribute( 'site_id', $blog );
    67                 $this->assertObjectHasAttribute( 'siteurl', $blog );
    68                 $this->assertObjectHasAttribute( 'archived', $blog );
    69                 $this->assertObjectHasAttribute( 'spam', $blog );
    70                 $this->assertObjectHasAttribute( 'deleted', $blog );
     62                $this->assertObjectHasProperty( 'userblog_id', $blog );
     63                $this->assertObjectHasProperty( 'blogname', $blog );
     64                $this->assertObjectHasProperty( 'domain', $blog );
     65                $this->assertObjectHasProperty( 'path', $blog );
     66                $this->assertObjectHasProperty( 'site_id', $blog );
     67                $this->assertObjectHasProperty( 'siteurl', $blog );
     68                $this->assertObjectHasProperty( 'archived', $blog );
     69                $this->assertObjectHasProperty( 'spam', $blog );
     70                $this->assertObjectHasProperty( 'deleted', $blog );
    7171            }
    7272
Note: See TracChangeset for help on using the changeset viewer.