Skip to content

Commit

Permalink
Tests: Use assertSame() in block support tests.
Browse files Browse the repository at this point in the history
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.

Includes renaming a few test classes per the naming conventions.

Reference: [https://make.wordpress.org/core/handbook/testing/automated-testing/writing-phpunit-tests/#naming-and-organization Writing PHP Tests: Naming and Organization].

Follow-up to [53076], [53085], [54497], [56046], [56614], [57246], [57491].

See #60705.

git-svn-id: https://develop.svn.wordpress.org/trunk@58181 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed May 21, 2024
1 parent d56791a commit c7db788
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion tests/phpunit/tests/block-supports/border.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @covers ::wp_apply_border_support
*/
class Test_Block_Supports_Border extends WP_UnitTestCase {
class Tests_Block_Supports_Border extends WP_UnitTestCase {
/**
* @var string|null
*/
Expand Down
4 changes: 2 additions & 2 deletions tests/phpunit/tests/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @covers ::wp_restore_image_outer_container
*/
class Test_Block_Supports_Layout extends WP_UnitTestCase {
class Tests_Block_Supports_Layout extends WP_UnitTestCase {

/**
* Theme root directory.
Expand Down Expand Up @@ -310,7 +310,7 @@ public function data_layout_support_flag_renders_classnames_on_wrapper() {
*/
public function test_restore_group_inner_container( $args, $expected_output ) {
$actual_output = wp_restore_group_inner_container( $args['block_content'], $args['block'] );
$this->assertEquals( $expected_output, $actual_output );
$this->assertSame( $expected_output, $actual_output );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/block-supports/shadow.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @covers ::wp_apply_shadow_support
*/
class Test_Block_Supports_Shadow extends WP_UnitTestCase {
class Tests_Block_Supports_Shadow extends WP_UnitTestCase {
/**
* @var string|null
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/tests/block-supports/spacing.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @covers ::wp_apply_spacing_support
*/
class Test_Block_Supports_Spacing extends WP_UnitTestCase {
class Tests_Block_Supports_Spacing extends WP_UnitTestCase {
/**
* @var string|null
*/
Expand Down
12 changes: 6 additions & 6 deletions tests/phpunit/tests/block-supports/typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ public function data_generate_replace_inline_font_styles_with_fluid_values_fixtu
* @param mixed $expected An expected return value.
*/
public function test_valid_size_wp_get_typography_value_and_unit( $raw_value, $expected ) {
$this->assertEquals( $expected, wp_get_typography_value_and_unit( $raw_value ) );
$this->assertSame( $expected, wp_get_typography_value_and_unit( $raw_value ) );
}

/**
Expand All @@ -1143,14 +1143,14 @@ public function data_valid_size_wp_get_typography_value_and_unit() {
'size: `"10"`' => array(
'raw_value' => '10',
'expected' => array(
'value' => 10,
'value' => 10.0,
'unit' => 'px',
),
),
'size: `11`' => array(
'raw_value' => 11,
'expected' => array(
'value' => 11,
'value' => 11.0,
'unit' => 'px',
),
),
Expand All @@ -1164,21 +1164,21 @@ public function data_valid_size_wp_get_typography_value_and_unit() {
'size: `"12rem"`' => array(
'raw_value' => '12rem',
'expected' => array(
'value' => 12,
'value' => 12.0,
'unit' => 'rem',
),
),
'size: `"12px"`' => array(
'raw_value' => '12px',
'expected' => array(
'value' => 12,
'value' => 12.0,
'unit' => 'px',
),
),
'size: `"12em"`' => array(
'raw_value' => '12em',
'expected' => array(
'value' => 12,
'value' => 12.0,
'unit' => 'em',
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function test_background_block_support( $theme_name, $block_name, $backgr

$actual = wp_render_background_support( $wrapper, $block );

$this->assertEquals(
$this->assertSame(
$expected_wrapper,
$actual,
'Background block wrapper markup should be correct'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function test_dimensions_block_support( $theme_name, $block_name, $dimens

$actual = wp_render_dimensions_support( $wrapper, $block );

$this->assertEquals(
$this->assertSame(
$expected_wrapper,
$actual,
'Dimensions block wrapper markup should be correct'
Expand Down

0 comments on commit c7db788

Please sign in to comment.