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-posts-controller.php

    r51397 r51404  
    476476                $data     = $response->get_data();
    477477                $ids      = wp_list_pluck( $data, 'id' );
    478                 $this->assertTrue( in_array( $id1, $ids, true ) );
    479                 $this->assertTrue( in_array( $id2, $ids, true ) );
     478                $this->assertContains( $id1, $ids );
     479                $this->assertContains( $id2, $ids );
    480480
    481481                $request->set_param( 'exclude', array( $id2 ) );
    … …  
    483483                $data     = $response->get_data();
    484484                $ids      = wp_list_pluck( $data, 'id' );
    485                 $this->assertTrue( in_array( $id1, $ids, true ) );
    486                 $this->assertFalse( in_array( $id2, $ids, true ) );
     485                $this->assertContains( $id1, $ids );
     486                $this->assertNotContains( $id2, $ids );
    487487
    488488                $request->set_param( 'exclude', (string) $id2 );
    … …  
    490490                $data     = $response->get_data();
    491491                $ids      = wp_list_pluck( $data, 'id' );
    492                 $this->assertTrue( in_array( $id1, $ids, true ) );
    493                 $this->assertFalse( in_array( $id2, $ids, true ) );
     492                $this->assertContains( $id1, $ids );
     493                $this->assertNotContains( $id2, $ids );
    494494
    495495                $request->set_param( 'exclude', 'invalid' );
    … …  
    14831483                $posts = $response->get_data();
    14841484                $ids   = wp_list_pluck( $posts, 'id' );
    1485                 $this->assertTrue( in_array( $id1, $ids, true ) );
    1486                 $this->assertFalse( in_array( $id2, $ids, true ) );
    1487                 $this->assertFalse( in_array( $id3, $ids, true ) );
     1485                $this->assertContains( $id1, $ids );
     1486                $this->assertNotContains( $id2, $ids );
     1487                $this->assertNotContains( $id3, $ids);
    14881488
    14891489                $this->assertPostsWhere( " AND {posts}.ID NOT IN ($id3,$id2) AND {posts}.post_type = 'post' AND (({posts}.post_status = 'publish'))" );
    … …  
    15091509                $posts = $response->get_data();
    15101510                $ids   = wp_list_pluck( $posts, 'id' );
    1511                 $this->assertTrue( in_array( $id1, $ids, true ) );
    1512                 $this->assertTrue( in_array( $id2, $ids, true ) );
    1513                 $this->assertFalse( in_array( $id3, $ids, true ) );
     1511                $this->assertContains( $id1, $ids );
     1512                $this->assertContains( $id2, $ids );
     1513                $this->assertNotContains( $id3, $ids );
    15141514
    15151515                $this->assertPostsWhere( " AND {posts}.ID NOT IN ($id3) AND {posts}.post_type = 'post' AND (({posts}.post_status = 'publish'))" );
Note: See TracChangeset for help on using the changeset viewer.