Skip to content

Commit e2f5452

Browse files
committed
Tests: Replace native assertions in PHPUnit test classes.
Use PHPUnit type assertions in test setup and helpers so checks remain active when native PHP assertions are disabled and report failures through PHPUnit. Retain native assertions outside PHPUnit test classes and add messages describing their invariants. Developed in: WordPress#13651 Props soean. See #64895. git-svn-id: https://develop.svn.wordpress.org/trunk@63936 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 4df55dd commit e2f5452

5 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎tests/phpstan/GlobalDocBlockVisitor.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private function parse_global_tags( string $docblock ): array {
165165
if ( preg_match_all( '/@global\s+(?P<type>\S.*?)\s+\$(?P<variable>\w+)/', $docblock, $matches, PREG_SET_ORDER ) > 0 ) {
166166
foreach ( $matches as $match ) {
167167
$type = preg_replace( '/\s+/', '', $match['type'] );
168-
assert( is_string( $type ) && '' !== $type );
168+
assert( is_string( $type ) && '' !== $type, 'Collapsing whitespace in a non-empty type must yield a non-empty string.' );
169169
$map[ $match['variable'] ] = $type;
170170
}
171171
}

‎tests/phpunit/tests/comment/wpNotifyNoteMentions.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ private function insert_note( string $content, int $user_id, int $parent_id = 0
121121
'user_id' => $user_id,
122122
)
123123
);
124-
assert( $comment instanceof WP_Comment );
124+
$this->assertInstanceOf( WP_Comment::class, $comment );
125125
return $comment;
126126
}
127127

‎tests/phpunit/tests/dependencies/scripts.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ private function assertEqualHTMLScriptTagById( string $expected, string $html, s
101101
$find_id_tag_processor = new WP_HTML_Tag_Processor( $expected );
102102
$find_id_tag_processor->next_token();
103103
$id = $find_id_tag_processor->get_attribute( 'id' );
104-
assert( is_string( $id ) );
104+
$this->assertIsString( $id, 'The expected SCRIPT tag must have an ID attribute.' );
105105

106106
$processor = ( new class('', WP_HTML_Processor::CONSTRUCTOR_UNLOCK_CODE ) extends WP_HTML_Processor {
107107
public function get_script_html() {
108-
assert( 'SCRIPT' === $this->get_tag() );
108+
assert( 'SCRIPT' === $this->get_tag(), 'The processor must be paused on a SCRIPT tag.' );
109109
$this->set_bookmark( 'here' );
110110
$span = $this->bookmarks['_here'];
111111
return substr( $this->html, $span->start, $span->length );

‎tests/phpunit/tests/post/getPost.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Tests_Post_GetPost extends WP_UnitTestCase {
1313
public static function set_up_before_class(): void {
1414
parent::set_up_before_class();
1515
$post_id = self::factory()->post->create();
16-
assert( is_int( $post_id ) );
16+
self::assertIsInt( $post_id );
1717
self::$post_id = $post_id;
1818

1919
global $wpdb;

‎tests/phpunit/tests/privacy/wpPrivacyResetPolicyPageForPost.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function set_up(): void {
2121
parent::set_up();
2222

2323
$page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );
24-
assert( is_int( $page_id ) );
24+
$this->assertIsInt( $page_id );
2525
$this->policy_page_id = $page_id;
2626
update_option( 'wp_page_for_privacy_policy', $this->policy_page_id );
2727
}

0 commit comments

Comments
 (0)