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/blocks/block-list.php

    r48845 r48937  
    5555
    5656        // Test "offsetGet".
    57         $this->assertEquals( 'core/example', $blocks[0]->name );
     57        $this->assertSame( 'core/example', $blocks[0]->name );
    5858
    5959        // Test "offsetSet".
    6060        $parsed_blocks[0]['blockName'] = 'core/updated';
    6161        $blocks[0]                     = new WP_Block( $parsed_blocks[0], $context, $this->registry );
    62         $this->assertEquals( 'core/updated', $blocks[0]->name );
     62        $this->assertSame( 'core/updated', $blocks[0]->name );
    6363
    6464        // Test "offsetUnset".
     
    7777
    7878        foreach ( $blocks as $block ) {
    79             $this->assertEquals( 'core/example', $block->name );
     79            $this->assertSame( 'core/example', $block->name );
    8080            $assertions++;
    8181            foreach ( $block->inner_blocks as $inner_block ) {
    82                 $this->assertEquals( 'core/example', $inner_block->name );
     82                $this->assertSame( 'core/example', $inner_block->name );
    8383                $assertions++;
    8484            }
     
    8989            $key   = $blocks->key();
    9090            $block = $blocks->current();
    91             $this->assertEquals( 0, $key );
     91            $this->assertSame( 0, $key );
    9292            $assertions++;
    93             $this->assertEquals( 'core/example', $block->name );
     93            $this->assertSame( 'core/example', $block->name );
    9494            $assertions++;
    9595            $blocks->next();
    9696        }
    9797
    98         $this->assertEquals( 4, $assertions );
     98        $this->assertSame( 4, $assertions );
    9999    }
    100100
     
    107107        $blocks        = new WP_Block_List( $parsed_blocks, $context, $this->registry );
    108108
    109         $this->assertEquals( 1, count( $blocks ) );
     109        $this->assertSame( 1, count( $blocks ) );
    110110    }
    111111
Note: See TracChangeset for help on using the changeset viewer.