Make WordPress Core

Changeset 63936


Ignore:
Timestamp:
09/25/2026 03:31:07 PM (5 days ago)
Author:
lancewillett
Message:

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: ​https://github.com/WordPress/wordpress-develop/pull/13651

Props soean.
See #64895.

Location:
trunk/tests
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpstan/GlobalDocBlockVisitor.php

    r62642 r63936  
    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                        }
  • trunk/tests/phpunit/tests/comment/wpNotifyNoteMentions.php

    r63924 r63936  
    122122                        )
    123123                );
    124                 assert( $comment instanceof WP_Comment );
     124                $this->assertInstanceOf( WP_Comment::class, $comment );
    125125                return $comment;
    126126        }
  • trunk/tests/phpunit/tests/dependencies/scripts.php

    r63934 r63936  
    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'];
  • trunk/tests/phpunit/tests/post/getPost.php

    r61789 r63936  
    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
  • trunk/tests/phpunit/tests/privacy/wpPrivacyResetPolicyPageForPost.php

    r63924 r63936  
    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 );
Note: See TracChangeset for help on using the changeset viewer.