Skip to content

Commit b33eb5e

Browse files
committed
Tests: Use strict assertions across additional test directories.
Replace loose comparisons with strict assertions where the expected types are known. Cast expected database IDs and serialized lengths to strings, and use float expectations for XPath counts. Correct the expected default idempotent ability annotation to null, matching the API's documented default. Preserve object-value comparisons where distinct instances are expected. Developed in: WordPress#13756 Props haritpanchal. See #64895. git-svn-id: https://develop.svn.wordpress.org/trunk@63934 602fd350-edb4-49c9-b593-d223f7449a82
1 parent a1129d6 commit b33eb5e

19 files changed

Lines changed: 29 additions & 29 deletions

‎tests/phpunit/tests/abilities-api/wpRegisterAbility.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function test_register_valid_ability(): void {
187187
$expected_annotations = array_merge(
188188
self::$test_ability_args['meta']['annotations'],
189189
array(
190-
'idempotent' => false,
190+
'idempotent' => null,
191191
)
192192
);
193193
$expected_meta = array_merge(
@@ -205,7 +205,7 @@ public function test_register_valid_ability(): void {
205205
$this->assertSame( self::$test_ability_args['description'], $result->get_description() );
206206
$this->assertSame( self::$test_ability_args['input_schema'], $result->get_input_schema() );
207207
$this->assertSame( self::$test_ability_args['output_schema'], $result->get_output_schema() );
208-
$this->assertEquals( $expected_meta, $result->get_meta() );
208+
$this->assertSame( $expected_meta, $result->get_meta() );
209209
$this->assertTrue(
210210
$result->check_permissions(
211211
array(

‎tests/phpunit/tests/admin/includes/misc/WpRefreshHeartbeatNonces_Test.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ public function test_wp_refresh_heartbeat_nonces_overwrites_existing() {
3838

3939
$result = wp_refresh_heartbeat_nonces( $response );
4040

41-
$this->assertNotEquals( 'old_rest_nonce', $result['rest_nonce'], 'The rest_nonce should be updated.' );
42-
$this->assertNotEquals( 'old_heartbeat_nonce', $result['heartbeat_nonce'], 'The heartbeat_nonce should be updated.' );
41+
$this->assertNotSame( 'old_rest_nonce', $result['rest_nonce'], 'The rest_nonce should be updated.' );
42+
$this->assertNotSame( 'old_heartbeat_nonce', $result['heartbeat_nonce'], 'The heartbeat_nonce should be updated.' );
4343

4444
$this->assertNotFalse( wp_verify_nonce( $result['rest_nonce'], 'wp_rest' ), 'The rest_nonce should be valid for "wp_rest".' );
4545
$this->assertNotFalse( wp_verify_nonce( $result['heartbeat_nonce'], 'heartbeat-nonce' ), 'The heartbeat_nonce should be valid for "heartbeat-nonce".' );

‎tests/phpunit/tests/admin/includesPost.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public function test_bulk_edit_posts_stomping() {
253253

254254
// Check that the first post's values don't stomp the second post.
255255
$this->assertSame( 'draft', $post->post_status );
256-
$this->assertEquals( self::$author_ids[1], $post->post_author );
256+
$this->assertSame( (string) self::$author_ids[1], $post->post_author );
257257
$this->assertSame( 'closed', $post->comment_status );
258258
$this->assertSame( 'closed', $post->ping_status );
259259
}

‎tests/phpunit/tests/admin/wpCommentsListTable.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ public function test_comments_list_table_does_not_show_note_comment_type( string
260260
$this->table->prepare_items();
261261
$items = $this->table->items;
262262
$this->assertCount( 2, $items );
263-
$this->assertEquals( $pingback_comment_id, $items[0]->comment_ID );
264-
$this->assertEquals( $regular_comment_id, $items[1]->comment_ID );
263+
$this->assertSame( (string) $pingback_comment_id, $items[0]->comment_ID );
264+
$this->assertSame( (string) $regular_comment_id, $items[1]->comment_ID );
265265
}
266266

267267
/**

‎tests/phpunit/tests/ajax/wpAjaxHeartbeat.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function test_autosave_locked_post() {
9393
wp_set_current_user( self::$admin_id );
9494

9595
// Ensure post is locked.
96-
$this->assertEquals( self::$editor_id, wp_check_post_lock( self::$post_id ) );
96+
$this->assertSame( self::$editor_id, wp_check_post_lock( self::$post_id ) );
9797

9898
// Set up the $_POST request.
9999
$md5 = md5( uniqid() );

‎tests/phpunit/tests/ajax/wpCustomizeManager.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public function test_success_save_post_date() {
425425
$this->assertArrayHasKey( 'next_changeset_uuid', $this->_last_response_parsed['data'] );
426426
$this->assertTrue( wp_is_uuid( $this->_last_response_parsed['data']['next_changeset_uuid'], 4 ) );
427427
$changeset_post_publish = get_post( $post_id );
428-
$this->assertNotEquals( $future_date, $changeset_post_publish->post_date );
428+
$this->assertNotSame( $future_date, $changeset_post_publish->post_date );
429429

430430
// Check response when trying to update an already-published post.
431431
$this->assertSame( 'trash', get_post_status( $post_id ) );

‎tests/phpunit/tests/block-supports/layout.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ public function test_layout_support_flag_renders_consistent_container_hash( $blo
796796
}
797797
}
798798

799-
$this->assertEquals(
799+
$this->assertSame(
800800
$expected_class,
801801
$actual_class,
802802
'Expected class not found in the rendered output, probably because of a different hash.'

‎tests/phpunit/tests/block-templates/WpBlockTemplatesRegistry.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public function test_unregister() {
273273

274274
$unregistered_template = self::$registry->unregister( $template_name );
275275

276-
$this->assertEquals( $template, $unregistered_template, 'Unregistered template should be the same as the registered one.' );
276+
$this->assertSame( $template, $unregistered_template, 'Unregistered template should be the same as the registered one.' );
277277
$this->assertFalse( self::$registry->is_registered( $template_name ), 'Template should not be registered after unregistering.' );
278278
}
279279

‎tests/phpunit/tests/blocks/wpBlockMetadataRegistry.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function test_register_collection_and_get_metadata() {
3434
WP_Block_Metadata_Registry::register_collection( $path, $this->temp_manifest_file );
3535

3636
$retrieved_metadata = WP_Block_Metadata_Registry::get_metadata( $path . '/test-block' );
37-
$this->assertEquals( $manifest_data['test-block'], $retrieved_metadata );
37+
$this->assertSame( $manifest_data['test-block'], $retrieved_metadata );
3838
}
3939

4040
public function test_get_nonexistent_metadata() {

‎tests/phpunit/tests/db/charset.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ public function data_strip_invalid_text() {
449449
$big5 = mb_convert_encoding( $utf8, 'BIG-5', 'UTF-8' );
450450
$conv_utf8 = mb_convert_encoding( $big5, 'UTF-8', 'BIG-5' );
451451
// Make sure PHP's multibyte conversions are working correctly.
452-
$this->assertNotEquals( $utf8, $big5 );
452+
$this->assertNotSame( $utf8, $big5 );
453453
$this->assertSame( $utf8, $conv_utf8 );
454454

455455
$fields['big5'] = array(

0 commit comments

Comments
 (0)