WordPress.org

Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (17 months ago)
Author:
SergeyBiryukov
Message:

Tests: First pass at using assertSame() instead of assertEquals() in most of the unit 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.

Props johnbillion, jrf, SergeyBiryukov.
See #38266.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/oembed/WpEmbed.php

    r44577 r48937  
    110110
    111111        $actual = $this->wp_embed->autoembed( $content );
    112         $this->assertEquals( $content, $actual );
     112        $this->assertSame( $content, $actual );
    113113    }
    114114
     
    125125        wp_embed_unregister_handler( $handle );
    126126
    127         $this->assertEquals( "\nEmbedded http://example.com/embed/foo\n", $actual );
     127        $this->assertSame( "\nEmbedded http://example.com/embed/foo\n", $actual );
    128128    }
    129129
     
    137137        $this->wp_embed->delete_oembed_caches( $post_id );
    138138
    139         $this->assertEquals( array(), get_post_meta( $post_id, '_oembed_foo' ) );
    140         $this->assertEquals( array(), get_post_meta( $post_id, '_oembed_baz' ) );
     139        $this->assertSame( array(), get_post_meta( $post_id, '_oembed_foo' ) );
     140        $this->assertSame( array(), get_post_meta( $post_id, '_oembed_baz' ) );
    141141    }
    142142
     
    169169
    170170        $this->assertSame( $post_id, $this->wp_embed->post_ID );
    171         $this->assertEquals( $expected, get_post_meta( $post_id, $cachekey, true ) );
     171        $this->assertSame( $expected, get_post_meta( $post_id, $cachekey, true ) );
    172172        $this->assertNotEmpty( get_post_meta( $post_id, $cachekey_time, true ) );
    173173    }
     
    195195        unset( $post );
    196196
    197         $this->assertEquals( $expected, $actual );
    198         $this->assertEquals( $expected, $actual_2 );
    199         $this->assertEquals( $expected, $cached );
     197        $this->assertSame( $expected, $actual );
     198        $this->assertSame( $expected, $actual_2 );
     199        $this->assertSame( $expected, $cached );
    200200    }
    201201
     
    226226        unset( $post );
    227227
    228         $this->assertEquals( $expected, $actual );
    229         $this->assertEquals( '{{unknown}}', $cached );
     228        $this->assertSame( $expected, $actual );
     229        $this->assertSame( '{{unknown}}', $cached );
    230230        $this->assertEmpty( $cached_time );
    231         $this->assertEquals( $expected, $actual_2 );
     231        $this->assertSame( $expected, $actual_2 );
    232232    }
    233233
     
    253253
    254254        $this->assertNotNull( $oembed_post_id );
    255         $this->assertEquals( $expected, $post_content );
    256         $this->assertEquals( $expected, $actual );
    257         $this->assertEquals( $expected, $actual_2 );
     255        $this->assertSame( $expected, $post_content );
     256        $this->assertSame( $expected, $actual );
     257        $this->assertSame( $expected, $actual_2 );
    258258    }
    259259
     
    278278        wp_delete_post( $oembed_post_id );
    279279
    280         $this->assertEquals( $expected, $actual );
    281         $this->assertEquals( $expected, $actual_2 );
     280        $this->assertSame( $expected, $actual );
     281        $this->assertSame( $expected, $actual_2 );
    282282        $this->assertNotNull( $oembed_post_id );
    283         $this->assertEquals( '{{unknown}}', $post_content );
     283        $this->assertSame( '{{unknown}}', $post_content );
    284284    }
    285285
     
    322322        $actual = $this->wp_embed->shortcode( array( 'src' => $url ) );
    323323
    324         $this->assertEquals( '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>', $actual );
     324        $this->assertSame( '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>', $actual );
    325325    }
    326326
     
    333333        $actual = $this->wp_embed->shortcode( array(), $url );
    334334
    335         $this->assertEquals( '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>', $actual );
     335        $this->assertSame( '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>', $actual );
    336336    }
    337337
     
    339339        $url    = 'http://example.com/embed/foo';
    340340        $actual = $this->wp_embed->run_shortcode( '[embed]' . $url . '[/embed]' );
    341         $this->assertEquals( '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>', $actual );
     341        $this->assertSame( '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>', $actual );
    342342    }
    343343
     
    346346        $actual = $this->wp_embed->maybe_make_link( $url );
    347347
    348         $this->assertEquals( '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>', $actual );
     348        $this->assertSame( '<a href="' . esc_url( $url ) . '">' . esc_html( $url ) . '</a>', $actual );
    349349    }
    350350
     
    358358
    359359        $this->wp_embed->linkifunknown = false;
    360         $this->assertEquals( $url, $this->wp_embed->maybe_make_link( $url ) );
     360        $this->assertSame( $url, $this->wp_embed->maybe_make_link( $url ) );
    361361    }
    362362}
Note: See TracChangeset for help on using the changeset viewer.