Make WordPress Core

Changeset 64111


Ignore:
Timestamp:
10/05/2026 07:03:12 PM (2 weeks ago)
Author:
lancewillett
Message:

Tests: Clarify comparisons in top-level test files.

Use assertSame() with a string expectation for the memory limit. Document intentional object-value comparisons and numeric-string differences in user properties.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/14000

Props noruzzaman.
See #64895.

Location:
trunk/tests/phpunit/tests
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/cache.php

    r57987 r64111  
    404404                        $this->assertInstanceOf( 'WP_Object_Cache', $wp_object_cache );
    405405                } else {
     406                        // Keep assertEquals() because the objects are intentionally compared by value.
    406407                        $this->assertEquals( $wp_object_cache, $new_blank_cache_object );
    407408                }
  • trunk/tests/phpunit/tests/functions.php

    r63880 r64111  
    11131113                $this->assertNotEmpty( $date_return, 'The date return could not be an empty string' );
    11141114                $this->assertSame( $expected, $date_return, 'The date does not match' );
     1115                // Keep assertEquals() because the objects are intentionally compared by value.
    11151116                $this->assertEquals( new DateTime( $expected ), new DateTime( $date_return ), 'The date is not the same after the call method' );
    11161117        }
    … …  
    11821183                $this->assertSame( $ini_limit_before, $ini_limit_after );
    11831184                $this->assertFalse( $raised_limit );
    1184                 $this->assertEquals( WP_MAX_MEMORY_LIMIT, $ini_limit_after );
     1185                $this->assertSame( (string) WP_MAX_MEMORY_LIMIT, $ini_limit_after );
    11851186        }
    11861187
  • trunk/tests/phpunit/tests/json-schema.php

    r62591 r64111  
    132132                $this->assertArrayNotHasKey( 'required', $prepared['properties']['title'] );
    133133                $this->assertArrayNotHasKey( 'validate_callback', $prepared['properties']['title'] );
     134                // Keep assertEquals() because the objects are intentionally compared by value.
    134135                $this->assertEquals( new stdClass(), $prepared['properties']['settings']['default'] );
    135136                $this->assertSame( array( 'settings' ), $prepared['dependencies']['title'] );
  • trunk/tests/phpunit/tests/post.php

    r63880 r64111  
    188188                _unregister_post_type( $post_type );
    189189                $count = wp_count_posts( $post_type, 'readable' );
     190                // Keep assertEquals() because the objects are intentionally compared by value.
    190191                $this->assertEquals( new stdClass(), $count );
    191192        }
  • trunk/tests/phpunit/tests/query.php

    r62476 r64111  
    7777                $this->assertEmpty( get_query_var( 'tax_query' ) );
    7878                $this->assertCount( 1, get_query_var( 'tag_slug__in' ) );
     79                // Keep assertEquals() because the objects are intentionally compared by value.
    7980                $this->assertEquals( get_queried_object(), $tag );
    8081
    … …  
    8889                $this->assertNotEmpty( $query->get( 'tag' ) );
    8990                $this->assertCount( 1, $query->get( 'tag_slug__in' ) );
     91                // Keep assertEquals() because the objects are intentionally compared by value.
    9092                $this->assertEquals( $query->get_queried_object(), $tag );
    9193        }
  • trunk/tests/phpunit/tests/theme.php

    r63627 r64111  
    8080                $single_theme = wp_get_theme( $this->theme_slug );
    8181                $this->assertSame( $single_theme->get( 'Name' ), $themes[ $this->theme_slug ]->get( 'Name' ) );
     82                // Keep assertEquals() because the objects are intentionally compared by value.
    8283                $this->assertEquals( $themes[ $this->theme_slug ], $single_theme );
    8384        }
    … …  
    127128                        // This primes internal WP_Theme caches for the next assertion (headers_sanitized, textdomain_loaded).
    128129                        $this->assertSame( $theme->get( 'Name' ), $_theme->get( 'Name' ) );
     130                        // Keep assertEquals() because the objects are intentionally compared by value.
    129131                        $this->assertEquals( $theme, $_theme );
    130132                }
  • trunk/tests/phpunit/tests/user.php

    r63924 r64111  
    219219                $user = new WP_User( self::$author_id );
    220220
     221                // Keep assertEquals() because the public ID is an integer while data->ID may be a numeric string.
    221222                foreach ( $user->data as $key => $data ) {
    222223                        $this->assertEquals( $data, $user->$key );
    … …  
    450451
    451452                $user = new WP_User( self::$author_id );
     453                // Keep assertEquals() because integer preference flags and the user ID may be retrieved as numeric strings.
    452454                foreach ( $user_data as $key => $value ) {
    453455                        $this->assertEquals( $value, $user->get( $key ), $key );
Note: See TracChangeset for help on using the changeset viewer.