Make WordPress Core


Ignore:
Timestamp:
09/02/2020 12:35:36 AM (6 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/blocks/block.php

    r48845 r48937  
    5858
    5959                $this->assertSame( $parsed_block, $block->parsed_block );
    60                 $this->assertEquals( $parsed_block['blockName'], $block->name );
    61                 $this->assertEquals( $parsed_block['attrs'], $block->attributes );
    62                 $this->assertEquals( $parsed_block['innerContent'], $block->inner_content );
    63                 $this->assertEquals( $parsed_block['innerHTML'], $block->inner_html );
     60                $this->assertSame( $parsed_block['blockName'], $block->name );
     61                $this->assertSame( $parsed_block['attrs'], $block->attributes );
     62                $this->assertSame( $parsed_block['innerContent'], $block->inner_content );
     63                $this->assertSame( $parsed_block['innerHTML'], $block->inner_html );
    6464        }
    6565
    … …  
    8383
    8484                $this->assertInstanceOf( WP_Block_Type::class, $block->block_type );
    85                 $this->assertEquals(
     85                $this->assertSame(
    8686                        $block_type_settings['attributes'],
    8787                        $block->block_type->attributes
    … …  
    114114                $block        = new WP_Block( $parsed_block, $context, $this->registry );
    115115
    116                 $this->assertEquals(
    117                         array(
     116                $this->assertSame(
     117                        array(
     118                                'explicit'  => 20,
    118119                                'defaulted' => 10,
    119                                 'explicit'  => 20,
    120120                        ),
    121121                        $block->attributes
    … …  
    146146                $block        = new WP_Block( $parsed_block, $context, $this->registry );
    147147
    148                 $this->assertEquals( array( 'defaulted' => 10 ), $block->attributes );
     148                $this->assertSame( array( 'defaulted' => 10 ), $block->attributes );
    149149                // Intentionally call a second time, to ensure property was assigned.
    150                 $this->assertEquals( array( 'defaulted' => 10 ), $block->attributes );
     150                $this->assertSame( array( 'defaulted' => 10 ), $block->attributes );
    151151        }
    152152
    … …  
    169169                $block        = new WP_Block( $parsed_block, $context, $this->registry );
    170170
    171                 $this->assertEquals( array( 'requested' => 'included' ), $block->context );
     171                $this->assertSame( array( 'requested' => 'included' ), $block->context );
    172172        }
    173173
    … …  
    185185                $this->assertCount( 1, $block->inner_blocks );
    186186                $this->assertInstanceOf( WP_Block::class, $block->inner_blocks[0] );
    187                 $this->assertEquals( 'core/example', $block->inner_blocks[0]->name );
     187                $this->assertSame( 'core/example', $block->inner_blocks[0]->name );
    188188        }
    189189
    … …  
    218218
    219219                $this->assertCount( 0, $block->context );
    220                 $this->assertEquals(
     220                $this->assertSame(
    221221                        array( 'core/recordId' => 10 ),
    222222                        $block->inner_blocks[0]->context
    … …  
    254254                $block         = new WP_Block( $parsed_block, $context, $this->registry );
    255255
    256                 $this->assertEquals(
     256                $this->assertSame(
    257257                        array( 'core/value' => 'original' ),
    258258                        $block->context
    259259                );
    260                 $this->assertEquals(
     260                $this->assertSame(
    261261                        array( 'core/value' => 'merged' ),
    262262                        $block->inner_blocks[0]->context
    263263                );
    264                 $this->assertEquals(
     264                $this->assertSame(
    265265                        array( 'core/value' => null ),
    266266                        $block->inner_blocks[0]->inner_blocks[0]->context
Note: See TracChangeset for help on using the changeset viewer.