Make WordPress Core


Ignore:
Timestamp:
07/12/2021 10:35:44 AM (5 years ago)
Author:
SergeyBiryukov
Message:

Tests: Use more appropriate assertions in various tests.

This replaces instances of assertTrue( in_array( ... ) ) with assertContains() to use native PHPUnit functionality.

Follow-up to [51335], [51337], [51367], [51397], [51403].

Props hellofromTonya, jrf, SergeyBiryukov.
Fixes #53123. See #53363.

File:
1 edited

Legend:

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

    r51403 r51404  
    278278                $user_ids = wp_list_pluck( $users, 'id' );
    279279
    280                 $this->assertTrue( in_array( self::$editor, $user_ids, true ) );
    281                 $this->assertTrue( in_array( self::$authors['r_true_p_true'], $user_ids, true ) );
    282                 $this->assertTrue( in_array( self::$authors['r_true_p_false'], $user_ids, true ) );
     280                $this->assertContains( self::$editor, $user_ids );
     281                $this->assertContains( self::$authors['r_true_p_true'], $user_ids );
     282                $this->assertContains( self::$authors['r_true_p_false'], $user_ids );
    283283                $this->assertCount( 3, $user_ids );
    284284        }
    … …  
    290290                $user_ids = wp_list_pluck( $users, 'id' );
    291291
    292                 $this->assertFalse( in_array( self::$authors['r_false_p_true'], $user_ids, true ) );
    293                 $this->assertFalse( in_array( self::$authors['r_false_p_false'], $user_ids, true ) );
     292                $this->assertNotContains( self::$authors['r_false_p_true'], $user_ids );
     293                $this->assertNotContains( self::$authors['r_false_p_false'], $user_ids );
    294294        }
    295295
    … …  
    300300                $user_ids = wp_list_pluck( $users, 'id' );
    301301
    302                 $this->assertFalse( in_array( self::$draft_editor, $user_ids, true ) );
    303                 $this->assertFalse( in_array( self::$user, $user_ids, true ) );
     302                $this->assertNotContains( self::$draft_editor, $user_ids );
     303                $this->assertNotContains( self::$user, $user_ids );
    304304        }
    305305
    … …  
    634634                $data     = $response->get_data();
    635635                $ids      = wp_list_pluck( $data, 'id' );
    636                 $this->assertTrue( in_array( $id1, $ids, true ) );
    637                 $this->assertTrue( in_array( $id2, $ids, true ) );
     636                $this->assertContains( $id1, $ids );
     637                $this->assertContains( $id2, $ids );
    638638
    639639                $request->set_param( 'exclude', array( $id2 ) );
    … …  
    641641                $data     = $response->get_data();
    642642                $ids      = wp_list_pluck( $data, 'id' );
    643                 $this->assertTrue( in_array( $id1, $ids, true ) );
    644                 $this->assertFalse( in_array( $id2, $ids, true ) );
     643                $this->assertContains( $id1, $ids );
     644                $this->assertNotContains( $id2, $ids );
    645645
    646646                // Invalid 'exclude' should error.
Note: See TracChangeset for help on using the changeset viewer.