Make WordPress Core

Changeset 57680


Ignore:
Timestamp:
02/21/2024 05:33:54 PM (8 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use assertSame() in wp_insert_post() tests.

This ensures that not only the return values match the expected results, but also that their type is the same.

Going forward, stricter type checking by using assertSame() should generally be preferred to assertEquals() where appropriate, to make the tests more reliable.

Follow-up to [34085], [35183], [48937], [53782], [53785], [53883], [54402].

Props costdev.
See #59655.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/post/wpInsertPost.php

    r56548 r57680  
    129129        $this->assertSame( $data['post_title'], $post->post_title );
    130130        $this->assertSame( $data['post_status'], $post->post_status );
    131         $this->assertEquals( $data['post_author'], $post->post_author );
     131        $this->assertSame( (string) $data['post_author'], $post->post_author );
    132132
    133133        // Test cache state.
     
    676676
    677677        $post = get_post( $post_id );
    678         $this->assertEquals( self::$user_ids['editor'], $post->post_author );
     678        $this->assertSame( (string) self::$user_ids['editor'], $post->post_author );
    679679        $this->assertSame( $title, $post->post_title );
    680680    }
     
    788788        $post_id = self::factory()->post->create( array( 'post_author' => 0 ) );
    789789
    790         $this->assertEquals( 0, get_post( $post_id )->post_author );
     790        $this->assertSame( '0', get_post( $post_id )->post_author );
    791791    }
    792792
     
    799799        $post_id = self::factory()->post->create( array( 'post_author' => null ) );
    800800
    801         $this->assertEquals( self::$user_ids['editor'], get_post( $post_id )->post_author );
     801        $this->assertSame( (string) self::$user_ids['editor'], get_post( $post_id )->post_author );
    802802    }
    803803
     
    917917        // Validate that the post has had the default category assigned again.
    918918        $this->assertCount( 1, $assigned_terms );
    919         $this->assertEquals( get_option( 'default_category' ), $assigned_terms[0]->term_id );
     919        $this->assertSame( (int) get_option( 'default_category' ), $assigned_terms[0]->term_id );
    920920    }
    921921
Note: See TracChangeset for help on using the changeset viewer.