Make WordPress Core


Ignore:
Timestamp:
07/12/2021 10:35:44 AM (3 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-comments-controller.php

    r51367 r51404  
    248248
    249249        $collection_data = $response->get_data();
    250         $this->assertTrue( in_array( $password_comment, wp_list_pluck( $collection_data, 'id' ), true ) );
     250        $this->assertContains( $password_comment, wp_list_pluck( $collection_data, 'id' ) );
    251251    }
    252252
     
    271271
    272272        $collection_data = $response->get_data();
    273         $this->assertFalse( in_array( $password_comment, wp_list_pluck( $collection_data, 'id' ), true ) );
     273        $this->assertNotContains( $password_comment, wp_list_pluck( $collection_data, 'id' ) );
    274274    }
    275275
     
    311311
    312312        $collection_data = $response->get_data();
    313         $this->assertFalse( in_array( $password_comment, wp_list_pluck( $collection_data, 'id' ), true ) );
     313        $this->assertNotContains( $password_comment, wp_list_pluck( $collection_data, 'id' ) );
    314314    }
    315315
     
    330330
    331331        $collection_data = $response->get_data();
    332         $this->assertTrue( in_array( $password_comment, wp_list_pluck( $collection_data, 'id' ), true ) );
     332        $this->assertContains( $password_comment, wp_list_pluck( $collection_data, 'id' ) );
    333333    }
    334334
     
    349349
    350350        $collection_data = $response->get_data();
    351         $this->assertFalse( in_array( $private_comment, wp_list_pluck( $collection_data, 'id' ), true ) );
     351        $this->assertNotContains( $private_comment, wp_list_pluck( $collection_data, 'id' ) );
    352352    }
    353353
     
    368368
    369369        $collection_data = $response->get_data();
    370         $this->assertTrue( in_array( $private_comment, wp_list_pluck( $collection_data, 'id' ), true ) );
     370        $this->assertContains( $private_comment, wp_list_pluck( $collection_data, 'id' ) );
    371371    }
    372372
     
    387387
    388388        $collection_data = $response->get_data();
    389         $this->assertFalse( in_array( $comment_id, wp_list_pluck( $collection_data, 'id' ), true ) );
     389        $this->assertNotContains( $comment_id, wp_list_pluck( $collection_data, 'id' ) );
    390390
    391391        wp_delete_comment( $comment_id );
     
    408408
    409409        $collection_data = $response->get_data();
    410         $this->assertTrue( in_array( $comment_id, wp_list_pluck( $collection_data, 'id' ), true ) );
     410        $this->assertContains( $comment_id, wp_list_pluck( $collection_data, 'id' ) );
    411411
    412412        wp_delete_comment( $comment_id );
     
    526526        $data     = $response->get_data();
    527527        $ids      = wp_list_pluck( $data, 'id' );
    528         $this->assertTrue( in_array( $id1, $ids, true ) );
    529         $this->assertTrue( in_array( $id2, $ids, true ) );
     528        $this->assertContains( $id1, $ids );
     529        $this->assertContains( $id2, $ids );
    530530
    531531        $request->set_param( 'exclude', array( $id2 ) );
     
    533533        $data     = $response->get_data();
    534534        $ids      = wp_list_pluck( $data, 'id' );
    535         $this->assertTrue( in_array( $id1, $ids, true ) );
    536         $this->assertFalse( in_array( $id2, $ids, true ) );
     535        $this->assertContains( $id1, $ids );
     536        $this->assertNotContains( $id2, $ids );
    537537
    538538        // Invalid 'exclude' should error.
Note: See TracChangeset for help on using the changeset viewer.