Make WordPress Core


Ignore:
Timestamp:
06/28/2024 03:45:08 PM (3 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/wpInteractivityAPIDirectivesProcessor.php

    r57987 r58594  
    2525        $p       = new WP_Interactivity_API_Directives_Processor( $content );
    2626        $p->next_tag();
    27         $this->assertEquals( 'Text', $p->get_content_between_balanced_template_tags() );
     27        $this->assertSame( 'Text', $p->get_content_between_balanced_template_tags() );
    2828
    2929        $content = '<template>Text</template><template>More text</template>';
    3030        $p       = new WP_Interactivity_API_Directives_Processor( $content );
    3131        $p->next_tag();
    32         $this->assertEquals( 'Text', $p->get_content_between_balanced_template_tags() );
    33         $p->next_tag();
    34         $this->assertEquals( 'More text', $p->get_content_between_balanced_template_tags() );
     32        $this->assertSame( 'Text', $p->get_content_between_balanced_template_tags() );
     33        $p->next_tag();
     34        $this->assertSame( 'More text', $p->get_content_between_balanced_template_tags() );
    3535    }
    3636
     
    4747        $p       = new WP_Interactivity_API_Directives_Processor( $content );
    4848        $p->next_tag();
    49         $this->assertEquals( '', $p->get_content_between_balanced_template_tags() );
     49        $this->assertSame( '', $p->get_content_between_balanced_template_tags() );
    5050    }
    5151
     
    8282        $p       = new WP_Interactivity_API_Directives_Processor( $content );
    8383        $p->next_tag();
    84         $this->assertEquals( '<span>Content</span><strong>More Content</strong>', $p->get_content_between_balanced_template_tags() );
     84        $this->assertSame( '<span>Content</span><strong>More Content</strong>', $p->get_content_between_balanced_template_tags() );
    8585
    8686        $content = '<template><template>Content</template><img src="example.jpg"></template>';
    8787        $p       = new WP_Interactivity_API_Directives_Processor( $content );
    8888        $p->next_tag();
    89         $this->assertEquals( '<template>Content</template><img src="example.jpg">', $p->get_content_between_balanced_template_tags() );
     89        $this->assertSame( '<template>Content</template><img src="example.jpg">', $p->get_content_between_balanced_template_tags() );
    9090    }
    9191
     
    132132        $p       = new WP_Interactivity_API_Directives_Processor( $content );
    133133        $p->next_tag();
    134         $this->assertEquals( 'Missing opening span</span>', $p->get_content_between_balanced_template_tags() );
     134        $this->assertSame( 'Missing opening span</span>', $p->get_content_between_balanced_template_tags() );
    135135    }
    136136
     
    164164        $p->next_tag();
    165165        $p->get_content_between_balanced_template_tags();
    166         $this->assertEquals( 'TEMPLATE', $p->get_tag() );
     166        $this->assertSame( 'TEMPLATE', $p->get_tag() );
    167167        $this->assertTrue( $p->is_tag_closer() );
    168168        $p->next_tag();
    169         $this->assertEquals( 'DIV', $p->get_tag() );
     169        $this->assertSame( 'DIV', $p->get_tag() );
    170170    }
    171171
     
    480480        $this->assertEquals( $content_1 . $content_2, $p );
    481481        $p->next_tag( array( 'tag_closers' => 'visit' ) );
    482         $this->assertEquals( 'content-2', $p->get_attribute( 'class' ) );
     482        $this->assertSame( 'content-2', $p->get_attribute( 'class' ) );
    483483        $p->next_tag( array( 'tag_closers' => 'visit' ) );
    484484        $result = $p->append_content_after_template_tag_closer( $content_3 );
     
    486486        $p->next_tag( array( 'tag_closers' => 'visit' ) );
    487487        $this->assertEquals( $content_1 . $content_2 . $content_3, $p );
    488         $this->assertEquals( 'content-3', $p->get_attribute( 'class' ) );
     488        $this->assertSame( 'content-3', $p->get_attribute( 'class' ) );
    489489    }
    490490
     
    510510        $this->assertEquals( $content_1 . $content_2 . $content_3, $p );
    511511        $p->next_tag( array( 'tag_closers' => 'visit' ) );
    512         $this->assertEquals( 'content-3', $p->get_attribute( 'class' ) );
     512        $this->assertSame( 'content-3', $p->get_attribute( 'class' ) );
    513513
    514514        $p = new WP_Interactivity_API_Directives_Processor( $content_1 . $content_3 );
     
    519519        $this->assertEquals( $content_1 . $content_4 . $content_3, $p );
    520520        $p->next_tag( array( 'tag_closers' => 'visit' ) );
    521         $this->assertEquals( 'content-4', $p->get_attribute( 'class' ) );
     521        $this->assertSame( 'content-4', $p->get_attribute( 'class' ) );
    522522    }
    523523
     
    559559        $this->assertEquals( $content_1 . $content_2, $p );
    560560        $p->next_tag( array( 'tag_closers' => 'visit' ) );
    561         $this->assertEquals( 'content-2', $p->get_attribute( 'class' ) );
     561        $this->assertSame( 'content-2', $p->get_attribute( 'class' ) );
    562562        // Rewinds to the first template.
    563563        $p->seek( 'first template' );
    564564        $p->release_bookmark( 'first template' );
    565         $this->assertEquals( 'content-1', $p->get_attribute( 'class' ) );
     565        $this->assertSame( 'content-1', $p->get_attribute( 'class' ) );
    566566        $p->next_tag( array( 'tag_closers' => 'visit' ) );
    567567        $result = $p->append_content_after_template_tag_closer( $content_3 );
    568568        $this->assertEquals( $content_1 . $content_3 . $content_2, $p );
    569569        $p->next_tag( array( 'tag_closers' => 'visit' ) );
    570         $this->assertEquals( 'content-3', $p->get_attribute( 'class' ) );
     570        $this->assertSame( 'content-3', $p->get_attribute( 'class' ) );
    571571    }
    572572
     
    616616        $this->assertEquals( $content_1 . $content_2, $p );
    617617        $p->next_tag();
    618         $this->assertEquals( 'content-2-template-1', $p->get_attribute( 'class' ) );
    619         $p->next_tag();
    620         $this->assertEquals( 'content-2-template-2', $p->get_attribute( 'class' ) );
     618        $this->assertSame( 'content-2-template-1', $p->get_attribute( 'class' ) );
     619        $p->next_tag();
     620        $this->assertSame( 'content-2-template-2', $p->get_attribute( 'class' ) );
    621621        $p->next_tag( array( 'tag_closers' => 'visit' ) );
    622622        $result = $p->append_content_after_template_tag_closer( $content_3 );
     
    641641        $this->assertFalse( $result );
    642642        $this->assertEquals( $content, $p );
    643         $this->assertEquals( 'TEMPLATE', $p->get_tag() ); // It didn't move.
     643        $this->assertSame( 'TEMPLATE', $p->get_tag() ); // It didn't move.
    644644        $this->assertTrue( $p->is_tag_closer() ); // It didn't move.
    645645    }
     
    695695        $p->next_tag();
    696696        $this->assertTrue( $p->next_balanced_tag_closer_tag() );
    697         $this->assertEquals( 'DIV', $p->get_tag() );
     697        $this->assertSame( 'DIV', $p->get_tag() );
    698698        $this->assertTrue( $p->is_tag_closer() );
    699699    }
     
    732732        $p->next_tag();
    733733        $this->assertTrue( $p->next_balanced_tag_closer_tag() );
    734         $this->assertEquals( 'DIV', $p->get_tag() );
     734        $this->assertSame( 'DIV', $p->get_tag() );
    735735        $this->assertTrue( $p->is_tag_closer() );
    736736
     
    739739        $p->next_tag();
    740740        $this->assertTrue( $p->next_balanced_tag_closer_tag() );
    741         $this->assertEquals( 'DIV', $p->get_tag() );
     741        $this->assertSame( 'DIV', $p->get_tag() );
    742742        $this->assertTrue( $p->is_tag_closer() );
    743743        $this->assertFalse( $p->next_tag() ); // No more content.
     
    794794        $this->assertTrue( $p->skip_to_tag_closer() );
    795795        $this->assertTrue( $p->is_tag_closer() );
    796         $this->assertEquals( 'DIV', $p->get_tag() );
     796        $this->assertSame( 'DIV', $p->get_tag() );
    797797    }
    798798
Note: See TracChangeset for help on using the changeset viewer.