Make WordPress Core


Ignore:
Timestamp:
05/26/2025 12:03:18 PM (17 months ago)
Author:
johnbillion
Message:

Build/Test Tools: Add assertions that test the tests.

Several tests perform assertions conditionally or iterate dynamic arrays without ensuring they're populated. If the test is faulty and the condition never evaluates to true, or the array being iterated is unexpectedly empty, this will now correctly cause the test to fail.

Props johnbillion, jrf.

See #63167

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-users-controller.php

    r60141 r60251  
    308308
    309309                $rest_post_types = array_values( get_post_types( array( 'show_in_rest' => true ), 'names' ) );
     310
     311                $this->assertNotEmpty( $users );
    310312
    311313                foreach ( $users as $user ) {
    … …  
    33603362                        $this->assertSame( $user->roles, $data['roles'] );
    33613363                        $this->assertSame( get_user_locale( $user ), $data['locale'] );
    3362                 }
    3363 
    3364                 if ( 'edit' !== $context ) {
     3364                } else {
    33653365                        $this->assertArrayNotHasKey( 'roles', $data );
    33663366                        $this->assertArrayNotHasKey( 'capabilities', $data );
Note: See TracChangeset for help on using the changeset viewer.