Make WordPress Core

Changeset 57244


Ignore:
Timestamp:
01/06/2024 12:59:49 PM (13 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 [55859], [56380], [56802], [57115], [57129], [57185].

See #59655.

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

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/ajax/wpAjaxImageEditor.php

    r56421 r57244  
    5353
    5454        $this->assertObjectHasProperty( 'error', $ret );
    55         $this->assertEquals( 'Images cannot be scaled to a size larger than the original.', $ret->error );
     55        $this->assertSame( 'Images cannot be scaled to a size larger than the original.', $ret->error );
    5656    }
    5757
  • trunk/tests/phpunit/tests/ajax/wpAjaxInlineSave.php

    r56802 r57244  
    111111        $this->assertSame( 'draft', $post->post_status );
    112112
    113         $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
     113        $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
    114114
    115115        // Set up a request.
     
    143143        $post_date = sprintf( '%04d-%02d-%02d %02d:%02d:%02d', $_POST['aa'], $_POST['mm'], $_POST['jj'], $_POST['hh'], $_POST['mn'], $_POST['ss'] );
    144144
    145         $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
     145        $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
    146146    }
    147147
     
    168168        $this->assertSame( 'draft', $post->post_status );
    169169
    170         $this->assertEquals( '0000-00-00 00:00:00', $post->post_date_gmt );
     170        $this->assertSame( '0000-00-00 00:00:00', $post->post_date_gmt );
    171171
    172172        // Set up a request.
     
    198198        $post = get_post( $post->ID );
    199199
    200         $this->assertEquals( '2020-09-11 19:20:11', $post->post_date_gmt );
     200        $this->assertSame( '2020-09-11 19:20:11', $post->post_date_gmt );
    201201    }
    202202}
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r57187 r57244  
    33673367        wp_default_packages_vendor( $wp_scripts );
    33683368
    3369         $this->assertEquals( $package_json[ $script ], $wp_scripts->query( $script, 'registered' )->ver );
     3369        $this->assertSame( $package_json[ $script ], $wp_scripts->query( $script, 'registered' )->ver );
    33703370    }
    33713371
  • trunk/tests/phpunit/tests/html-api/wpHtmlProcessorSemanticRules.php

    r57186 r57244  
    3636        }
    3737
    38         $this->assertEquals(
     38        $this->assertSame(
    3939            $tag_name,
    4040            $processor->get_tag(),
     
    126126
    127127        $p->step();
    128         $this->assertEquals( 'DIV', $p->get_tag(), 'Did not stop at initial DIV tag.' );
     128        $this->assertSame( 'DIV', $p->get_tag(), 'Did not stop at initial DIV tag.' );
    129129        $this->assertFalse( $p->is_tag_closer(), 'Did not find that initial DIV tag is an opener.' );
    130130
     
    134134         */
    135135        $this->assertTrue( $p->step(), 'Found no further tags when it should have found the closing DIV' );
    136         $this->assertEquals( 'DIV', $p->get_tag(), "Did not skip unexpected BUTTON; stopped at {$p->get_tag()}." );
     136        $this->assertSame( 'DIV', $p->get_tag(), "Did not skip unexpected BUTTON; stopped at {$p->get_tag()}." );
    137137        $this->assertTrue( $p->is_tag_closer(), 'Did not find that the terminal DIV tag is a closer.' );
    138138    }
  • trunk/tests/phpunit/tests/theme.php

    r57129 r57244  
    12601260        switch_theme( $old_theme->get_stylesheet() );
    12611261
    1262         $this->assertEquals( $old_root . '/test', $path1, 'The original stylesheet path is not correct' );
    1263         $this->assertEquals( $new_root . '/test', $path2, 'The new stylesheet path is not correct' );
     1262        $this->assertSame( $old_root . '/test', $path1, 'The original stylesheet path is not correct' );
     1263        $this->assertSame( $new_root . '/test', $path2, 'The new stylesheet path is not correct' );
    12641264    }
    12651265
     
    13031303        switch_theme( $old_theme->get_stylesheet() );
    13041304
    1305         $this->assertEquals( $old_root . '/test-parent', $path1, 'The original template path is not correct' );
    1306         $this->assertEquals( $new_root . '/test-parent', $path2, 'The new template path is not correct' );
     1305        $this->assertSame( $old_root . '/test-parent', $path1, 'The original template path is not correct' );
     1306        $this->assertSame( $new_root . '/test-parent', $path2, 'The new template path is not correct' );
    13071307    }
    13081308}
Note: See TracChangeset for help on using the changeset viewer.