Make WordPress Core


Ignore:
Timestamp:
06/28/2024 03:45:08 PM (21 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use assertSame() in WP_Interactivity_API 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 [57563], [57649], [57822], [57826], [57835], [58159], [58327].

See #61530.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-text.php

    r58327 r58594  
    4040        $html     = '<div data-wp-text="myPlugin::state.text">Text</div>';
    4141        $new_html = $this->interactivity->process_directives( $html );
    42         $this->assertEquals( '<div data-wp-text="myPlugin::state.text">Updated</div>', $new_html );
     42        $this->assertSame( '<div data-wp-text="myPlugin::state.text">Updated</div>', $new_html );
    4343    }
    4444
     
    5454        $html     = '<div data-wp-text="myPlugin::state.number">Text</div>';
    5555        $new_html = $this->interactivity->process_directives( $html );
    56         $this->assertEquals( '<div data-wp-text="myPlugin::state.number">100</div>', $new_html );
     56        $this->assertSame( '<div data-wp-text="myPlugin::state.number">100</div>', $new_html );
    5757    }
    5858
     
    7878        $html     = '<div data-wp-text="myPlugin::state.true">Text</div>';
    7979        $new_html = $this->interactivity->process_directives( $html );
    80         $this->assertEquals( '<div data-wp-text="myPlugin::state.true"></div>', $new_html );
     80        $this->assertSame( '<div data-wp-text="myPlugin::state.true"></div>', $new_html );
    8181
    8282        $html     = '<div data-wp-text="myPlugin::state.false">Text</div>';
    8383        $new_html = $this->interactivity->process_directives( $html );
    84         $this->assertEquals( '<div data-wp-text="myPlugin::state.false"></div>', $new_html );
     84        $this->assertSame( '<div data-wp-text="myPlugin::state.false"></div>', $new_html );
    8585
    8686        $html     = '<div data-wp-text="myPlugin::state.null">Text</div>';
    8787        $new_html = $this->interactivity->process_directives( $html );
    88         $this->assertEquals( '<div data-wp-text="myPlugin::state.null"></div>', $new_html );
     88        $this->assertSame( '<div data-wp-text="myPlugin::state.null"></div>', $new_html );
    8989
    9090        $html     = '<div data-wp-text="myPlugin::state.array">Text</div>';
    9191        $new_html = $this->interactivity->process_directives( $html );
    92         $this->assertEquals( '<div data-wp-text="myPlugin::state.array"></div>', $new_html );
     92        $this->assertSame( '<div data-wp-text="myPlugin::state.array"></div>', $new_html );
    9393
    9494        $html     = '<div data-wp-text="myPlugin::state.func">Text</div>';
    9595        $new_html = $this->interactivity->process_directives( $html );
    96         $this->assertEquals( '<div data-wp-text="myPlugin::state.func"></div>', $new_html );
     96        $this->assertSame( '<div data-wp-text="myPlugin::state.func"></div>', $new_html );
    9797    }
    9898
     
    108108        $html     = '<div data-wp-text="myPlugin::state.text"><div><div>Text</div><div>Another text</div></div></div>';
    109109        $new_html = $this->interactivity->process_directives( $html );
    110         $this->assertEquals( '<div data-wp-text="myPlugin::state.text">Updated</div>', $new_html );
     110        $this->assertSame( '<div data-wp-text="myPlugin::state.text">Updated</div>', $new_html );
    111111    }
    112112
     
    122122        $html     = '<div data-wp-text="myPlugin::state.text"><span>Text</div>';
    123123        $new_html = $this->interactivity->process_directives( $html );
    124         $this->assertEquals( '<div data-wp-text="myPlugin::state.text">Updated</div>', $new_html );
     124        $this->assertSame( '<div data-wp-text="myPlugin::state.text">Updated</div>', $new_html );
    125125    }
    126126
     
    138138        $html     = '<div data-wp-text="myPlugin::state.text">Text<div></div>';
    139139        $new_html = $this->interactivity->process_directives( $html );
    140         $this->assertEquals( '<div data-wp-text="myPlugin::state.text">Text<div></div>', $new_html );
     140        $this->assertSame( '<div data-wp-text="myPlugin::state.text">Text<div></div>', $new_html );
    141141    }
    142142
     
    153153        $html     = '<div data-wp-text="myPlugin::state.text">Text</div>';
    154154        $new_html = $this->interactivity->process_directives( $html );
    155         $this->assertEquals( '<div data-wp-text="myPlugin::state.text">&lt;span&gt;Updated&lt;/span&gt;</div>', $new_html );
     155        $this->assertSame( '<div data-wp-text="myPlugin::state.text">&lt;span&gt;Updated&lt;/span&gt;</div>', $new_html );
    156156    }
    157157}
Note: See TracChangeset for help on using the changeset viewer.