WordPress.org

Make WordPress Core


Ignore:
Timestamp:
02/10/2021 01:24:24 PM (10 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use assertSame() in some newly introduced 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 [49904], [49925], [49992], [50012], [50013], [50065], [50075], [50131], [50150], [50157].

See #38266, #52482.

File:
1 edited

Legend:

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

    r50012 r50284  
    14121412        $post    = get_post( $post_id );
    14131413        $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' );
    1414         $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
     1414        $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
    14151415
    14161416        $post_id = self::factory()->post->create(
     
    14221422        $post    = get_post( $post_id );
    14231423        $this->assertEqualsWithDelta( strtotime( gmdate( 'Y-m-d H:i:s' ) ), strtotime( $post->post_date ), 2, 'The dates should be equal' );
    1424         $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
     1424        $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
    14251425
    14261426        // Empty post_date_gmt without floating status
     
    14511451        );
    14521452        $post    = get_post( $post_id );
    1453         $this->assertEquals( get_date_from_gmt( $post_date_gmt ), $post->post_date );
    1454         $this->assertEquals( $post_date_gmt, $post->post_date_gmt );
     1453        $this->assertSame( get_date_from_gmt( $post_date_gmt ), $post->post_date );
     1454        $this->assertSame( $post_date_gmt, $post->post_date_gmt );
    14551455
    14561456        // Invalid post_date_gmt
     
    14611461        );
    14621462        $post    = get_post( $post_id );
    1463         $this->assertEquals( '1970-01-01 00:00:00', $post->post_date );
    1464         $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
     1463        $this->assertSame( '1970-01-01 00:00:00', $post->post_date );
     1464        $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
    14651465    }
    14661466
     
    14811481        );
    14821482        $post    = get_post( $post_id );
    1483         $this->assertEquals( $post_date, $post->post_date );
    1484         $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
     1483        $this->assertSame( $post_date, $post->post_date );
     1484        $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
    14851485
    14861486        $post_id = self::factory()->post->create(
     
    14921492        );
    14931493        $post    = get_post( $post_id );
    1494         $this->assertEquals( $post_date, $post->post_date );
    1495         $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
     1494        $this->assertSame( $post_date, $post->post_date );
     1495        $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
    14961496
    14971497        // Empty post_date_gmt without floating status
     
    15031503        );
    15041504        $post    = get_post( $post_id );
    1505         $this->assertEquals( $post_date, $post->post_date );
    1506         $this->assertEquals( get_gmt_from_date( $post_date ), $post->post_date_gmt );
     1505        $this->assertSame( $post_date, $post->post_date );
     1506        $this->assertSame( get_gmt_from_date( $post_date ), $post->post_date_gmt );
    15071507
    15081508        $post_id = self::factory()->post->create(
     
    15141514        );
    15151515        $post    = get_post( $post_id );
    1516         $this->assertEquals( $post_date, $post->post_date );
    1517         $this->assertEquals( get_gmt_from_date( $post_date ), $post->post_date_gmt );
     1516        $this->assertSame( $post_date, $post->post_date );
     1517        $this->assertSame( get_gmt_from_date( $post_date ), $post->post_date_gmt );
    15181518
    15191519        // Valid post_date_gmt
     
    15251525        );
    15261526        $post    = get_post( $post_id );
    1527         $this->assertEquals( $post_date, $post->post_date );
    1528         $this->assertEquals( $post_date_gmt, $post->post_date_gmt );
     1527        $this->assertSame( $post_date, $post->post_date );
     1528        $this->assertSame( $post_date_gmt, $post->post_date_gmt );
    15291529
    15301530        // Invalid post_date_gmt
     
    15361536        );
    15371537        $post    = get_post( $post_id );
    1538         $this->assertEquals( $post_date, $post->post_date );
    1539         $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
     1538        $this->assertSame( $post_date, $post->post_date );
     1539        $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
    15401540    }
    15411541
     
    15551555            )
    15561556        );
    1557         $this->assertEquals( 0, $post_id );
     1557        $this->assertSame( 0, $post_id );
    15581558
    15591559        $post_id = self::factory()->post->create(
     
    15641564            )
    15651565        );
    1566         $this->assertEquals( 0, $post_id );
     1566        $this->assertSame( 0, $post_id );
    15671567
    15681568        // Empty post_date_gmt without floating status
     
    15731573            )
    15741574        );
    1575         $this->assertEquals( 0, $post_id );
     1575        $this->assertSame( 0, $post_id );
    15761576
    15771577        $post_id = self::factory()->post->create(
     
    15821582            )
    15831583        );
    1584         $this->assertEquals( 0, $post_id );
     1584        $this->assertSame( 0, $post_id );
    15851585
    15861586        // Valid post_date_gmt
     
    15911591            )
    15921592        );
    1593         $this->assertEquals( 0, $post_id );
     1593        $this->assertSame( 0, $post_id );
    15941594
    15951595        // Invalid post_date_gmt
     
    16001600            )
    16011601        );
    1602         $this->assertEquals( 0, $post_id );
     1602        $this->assertSame( 0, $post_id );
    16031603    }
    16041604
     
    16151615
    16161616        $resolved_post_date = wp_resolve_post_date( '', $post_date_gmt );
    1617         $this->assertEquals( get_date_from_gmt( $post_date_gmt ), $resolved_post_date );
     1617        $this->assertSame( get_date_from_gmt( $post_date_gmt ), $resolved_post_date );
    16181618
    16191619        $resolved_post_date = wp_resolve_post_date( '', $invalid_date );
    1620         $this->assertEquals( '1970-01-01 00:00:00', $resolved_post_date );
     1620        $this->assertSame( '1970-01-01 00:00:00', $resolved_post_date );
    16211621
    16221622        $resolved_post_date = wp_resolve_post_date( $post_date );
    1623         $this->assertEquals( $post_date, $resolved_post_date );
     1623        $this->assertSame( $post_date, $resolved_post_date );
    16241624
    16251625        $resolved_post_date = wp_resolve_post_date( $post_date, $post_date_gmt );
    1626         $this->assertEquals( $post_date, $resolved_post_date );
     1626        $this->assertSame( $post_date, $resolved_post_date );
    16271627
    16281628        $resolved_post_date = wp_resolve_post_date( $post_date, $invalid_date );
    1629         $this->assertEquals( $post_date, $resolved_post_date );
     1629        $this->assertSame( $post_date, $resolved_post_date );
    16301630
    16311631        $resolved_post_date = wp_resolve_post_date( $invalid_date );
Note: See TracChangeset for help on using the changeset viewer.