Make WordPress Core


Ignore:
Timestamp:
06/07/2021 11:16:29 AM (5 years 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 [50380], [50959], [50960], [50973], [50993], [51003], [51051], [51054].

See #52482.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-templates-controller.php

    r51003 r51079  
    8181        $data     = $response->get_data();
    8282
    83         $this->assertEquals(
     83        $this->assertSame(
    8484            array(
    8585                'id'             => 'default//my_template',
    8686                'theme'          => 'default',
    8787                'slug'           => 'my_template',
     88                'source'         => 'custom',
     89                'type'           => 'wp_template',
     90                'description'    => 'Description of my template.',
    8891                'title'          => array(
    8992                    'raw'      => 'My Template',
    9093                    'rendered' => 'My Template',
    9194                ),
    92                 'description'    => 'Description of my template.',
    9395                'status'         => 'publish',
    94                 'source'         => 'custom',
    95                 'type'           => 'wp_template',
    9696                'wp_id'          => self::$post->ID,
    9797                'has_theme_file' => false,
     
    109109        unset( $data['_links'] );
    110110
    111         $this->assertEquals(
     111        $this->assertSame(
    112112            array(
    113113                'id'             => 'default//my_template',
    114114                'theme'          => 'default',
    115115                'slug'           => 'my_template',
     116                'source'         => 'custom',
     117                'type'           => 'wp_template',
     118                'description'    => 'Description of my template.',
    116119                'title'          => array(
    117120                    'raw'      => 'My Template',
    118121                    'rendered' => 'My Template',
    119122                ),
    120                 'description'    => 'Description of my template.',
    121123                'status'         => 'publish',
    122                 'source'         => 'custom',
    123                 'type'           => 'wp_template',
    124124                'wp_id'          => self::$post->ID,
    125125                'has_theme_file' => false,
     
    135135            array(
    136136                'slug'        => 'my_custom_template',
     137                'description' => 'Just a description',
    137138                'title'       => 'My Template',
    138                 'description' => 'Just a description',
    139139                'content'     => 'Content',
    140140            )
     
    145145        unset( $data['wp_id'] );
    146146
    147         $this->assertEquals(
     147        $this->assertSame(
    148148            array(
    149149                'id'             => 'default//my_custom_template',
    150150                'theme'          => 'default',
     151                'content'        => array(
     152                    'raw' => 'Content',
     153                ),
    151154                'slug'           => 'my_custom_template',
     155                'source'         => 'custom',
     156                'type'           => 'wp_template',
     157                'description'    => 'Just a description',
    152158                'title'          => array(
    153159                    'raw'      => 'My Template',
    154160                    'rendered' => 'My Template',
    155161                ),
    156                 'description'    => 'Just a description',
    157162                'status'         => 'publish',
    158                 'source'         => 'custom',
    159                 'type'           => 'wp_template',
    160                 'content'        => array(
    161                     'raw' => 'Content',
    162                 ),
    163163                'has_theme_file' => false,
    164164            ),
     
    177177        $response = rest_get_server()->dispatch( $request );
    178178        $data     = $response->get_data();
    179         $this->assertEquals( 'My new Index Title', $data['title']['raw'] );
    180         $this->assertEquals( 'custom', $data['source'] );
     179        $this->assertSame( 'My new Index Title', $data['title']['raw'] );
     180        $this->assertSame( 'custom', $data['source'] );
    181181    }
    182182
Note: See TracChangeset for help on using the changeset viewer.