Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (4 years 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/import/parser.php

    r47198 r48937  
    3333            $result = $parser->parse( $file );
    3434            $this->assertWPError( $result );
    35             $this->assertEquals( 'There was an error when reading this WXR file', $result->get_error_message() );
     35            $this->assertSame( 'There was an error when reading this WXR file', $result->get_error_message() );
    3636        }
    3737    }
     
    4646                $result = $parser->parse( $file );
    4747                $this->assertWPError( $result );
    48                 $this->assertEquals( 'This does not appear to be a WXR file, missing/invalid WXR version number', $result->get_error_message() );
     48                $this->assertSame( 'This does not appear to be a WXR file, missing/invalid WXR version number', $result->get_error_message() );
    4949            }
    5050        }
     
    6060
    6161            $this->assertTrue( is_array( $result ), $message );
    62             $this->assertEquals( 'http://localhost/', $result['base_url'], $message );
     62            $this->assertSame( 'http://localhost/', $result['base_url'], $message );
    6363            $this->assertEquals(
    6464                array(
     
    107107            );
    108108
    109             $this->assertEquals( 2, count( $result['posts'] ), $message );
    110             $this->assertEquals( 19, count( $result['posts'][0] ), $message );
    111             $this->assertEquals( 18, count( $result['posts'][1] ), $message );
     109            $this->assertSame( 2, count( $result['posts'] ), $message );
     110            $this->assertSame( 19, count( $result['posts'][0] ), $message );
     111            $this->assertSame( 18, count( $result['posts'][1] ), $message );
    112112            $this->assertEquals(
    113113                array(
     
    131131                $message
    132132            );
    133             $this->assertEquals(
     133            $this->assertSame(
    134134                array(
    135135                    array(
     
    153153
    154154            $this->assertTrue( is_array( $result ), $message );
    155             $this->assertEquals( 'http://localhost/', $result['base_url'], $message );
    156             $this->assertEquals( $result['categories'][0]['category_nicename'], 'alpha', $message );
    157             $this->assertEquals( $result['categories'][0]['cat_name'], 'alpha', $message );
    158             $this->assertEquals( $result['categories'][0]['category_parent'], '', $message );
    159             $this->assertEquals( $result['categories'][0]['category_description'], 'The alpha category', $message );
    160             $this->assertEquals( $result['tags'][0]['tag_slug'], 'chicken', $message );
    161             $this->assertEquals( $result['tags'][0]['tag_name'], 'chicken', $message );
    162 
    163             $this->assertEquals( 6, count( $result['posts'] ), $message );
    164             $this->assertEquals( 19, count( $result['posts'][0] ), $message );
    165             $this->assertEquals( 18, count( $result['posts'][1] ), $message );
     155            $this->assertSame( 'http://localhost/', $result['base_url'], $message );
     156            $this->assertSame( $result['categories'][0]['category_nicename'], 'alpha', $message );
     157            $this->assertSame( $result['categories'][0]['cat_name'], 'alpha', $message );
     158            $this->assertSame( $result['categories'][0]['category_parent'], '', $message );
     159            $this->assertSame( $result['categories'][0]['category_description'], 'The alpha category', $message );
     160            $this->assertSame( $result['tags'][0]['tag_slug'], 'chicken', $message );
     161            $this->assertSame( $result['tags'][0]['tag_name'], 'chicken', $message );
     162
     163            $this->assertSame( 6, count( $result['posts'] ), $message );
     164            $this->assertSame( 19, count( $result['posts'][0] ), $message );
     165            $this->assertSame( 18, count( $result['posts'][1] ), $message );
    166166
    167167            $this->assertEquals(
     
    219219            );
    220220
    221             $this->assertEquals(
     221            $this->assertSame(
    222222                array(
    223223                    array(
     
    247247
    248248            $post = $result['posts'][0];
    249             $this->assertEquals( 'Content with nested <![CDATA[ tags ]]> :)', $post['post_content'], $message );
     249            $this->assertSame( 'Content with nested <![CDATA[ tags ]]> :)', $post['post_content'], $message );
    250250            foreach ( $post['postmeta'] as $meta ) {
    251251                switch ( $meta['key'] ) {
     
    262262                        $this->fail( 'Unknown postmeta (' . $meta['key'] . ') was parsed out by' . $p );
    263263                }
    264                 $this->assertEquals( $value, $meta['value'], $message );
     264                $this->assertSame( $value, $meta['value'], $message );
    265265            }
    266266        }
     
    278278
    279279        $post = $result['posts'][0];
    280         $this->assertEquals( 'Content with nested <![CDATA[ tags ]]> :)', $post['post_content'] );
     280        $this->assertSame( 'Content with nested <![CDATA[ tags ]]> :)', $post['post_content'] );
    281281        foreach ( $post['postmeta'] as $meta ) {
    282282            switch ( $meta['key'] ) {
     
    293293                    $this->fail( 'Unknown postmeta (' . $meta['key'] . ') was parsed out by' . $p );
    294294            }
    295             $this->assertEquals( $value, $meta['value'] );
     295            $this->assertSame( $value, $meta['value'] );
    296296        }
    297297    }
Note: See TracChangeset for help on using the changeset viewer.