Skip to content

Tests: Document value comparisons in post tests - #13939

Closed
noruzzamans wants to merge 2 commits into
WordPress:trunkfrom
noruzzamans:test/post-assert-equals
Closed

noruzzamans wants to merge 2 commits into
WordPress:trunkfrom
noruzzamans:test/post-assert-equals

Conversation

@noruzzamans

Copy link
Copy Markdown

Description

Reviewed tests/phpunit/tests/post/ for ticket #64895.

There are 6 calls to assertEquals() across 4 files:

  • tests/phpunit/tests/post/getPageByPath.php:
    • Line 41: Comparing $page (WP_Post) with object returned from get_page_by_path( 'some-page' ).
    • Line 44: Comparing $other_att (WP_Post) with object returned from get_page_by_path( 'some-other-page' ).
  • tests/phpunit/tests/post/meta.php:
    • Line 174: Comparing $mobj (stdClass) with database row object returned from get_post_meta_by_id( $mid ).
    • Line 181: Comparing $mobj (stdClass) with database row object returned from get_post_meta_by_id( $mid ).
  • tests/phpunit/tests/post/types.php:
    • Line 295: Comparing $before labels object (stdClass) with $after labels object after calling get_post_type_labels().
  • tests/phpunit/tests/post/wpCountAttachments.php:
    • Line 31: Comparing $expected object with cached object returned from wp_cache_get( $cache_key, 'counts' ).

All 6 calls intentionally compare object instances by value:

  1. get_page_by_path() queries the database and instantiates a WP_Post object, which is a separate instance from fixture references in the test.
  2. get_post_meta_by_id() constructs a database row object, distinct from the manually constructed $mobj fixture.
  3. get_post_type_labels() casts the labels array to a fresh (object), producing a distinct instance from $before.
  4. WP_Object_Cache::get() intentionally clones objects upon cache retrieval, returning a distinct instance in memory from $expected.

In accordance with maintainer guidance on Trac #64895 (comments 88 & 93), these intentional loose comparisons are preserved and documented with:
// Keep assertEquals() because the objects are intentionally compared by value.

Testing Instructions

npm run test:php -- tests/phpunit/tests/post/getPageByPath.php tests/phpunit/tests/post/meta.php tests/phpunit/tests/post/types.php tests/phpunit/tests/post/wpCountAttachments.php
npm run test:php -- -c tests/phpunit/multisite.xml tests/phpunit/tests/post/getPageByPath.php tests/phpunit/tests/post/meta.php tests/phpunit/tests/post/types.php tests/phpunit/tests/post/wpCountAttachments.php
composer run lint tests/phpunit/tests/post/getPageByPath.php tests/phpunit/tests/post/meta.php tests/phpunit/tests/post/types.php tests/phpunit/tests/post/wpCountAttachments.php

Trac ticket: https://core.trac.wordpress.org/ticket/64895


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@noruzzamans
noruzzamans marked this pull request as ready for review October 2, 2026 18:45
@github-actions

github-actions Bot commented Oct 2, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props noruzzaman.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

wporg-sync pushed a commit that referenced this pull request Oct 2, 2026
Explain why post lookup, metadata, post type label, and attachment count tests retain `assertEquals()` when comparing separately constructed or cached objects by value.

Developed in: #13939

Props noruzzaman.
See #64895.


git-svn-id: https://develop.svn.wordpress.org/trunk@64071 602fd350-edb4-49c9-b593-d223f7449a82
@lancewillett

Copy link
Copy Markdown
Member

wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 2, 2026
Explain why post lookup, metadata, post type label, and attachment count tests retain `assertEquals()` when comparing separately constructed or cached objects by value.

Developed in: WordPress/wordpress-develop#13939

Props noruzzaman.
See #64895.

Built from https://develop.svn.wordpress.org/trunk@64071


git-svn-id: http://core.svn.wordpress.org/trunk@63230 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants