WordPress.org

Make WordPress Core


Ignore:
Timestamp:
07/07/2021 10:32:56 AM (3 months ago)
Author:
SergeyBiryukov
Message:

Tests: Use more appropriate assertions in various tests.

This replaces instances of assertSame( [number], count( ... ) ) with assertCount() to use native PHPUnit functionality.

Follow-up to [51335], [51337].

See #53363.

File:
1 edited

Legend:

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

    r51137 r51367  
    269269        $response = rest_get_server()->dispatch( $request );
    270270        $this->assertSame( 200, $response->get_status() );
    271         $this->assertSame( $total_posts, count( $response->get_data() ) );
     271        $this->assertCount( $total_posts, $response->get_data() );
    272272
    273273        // Limit to editor and author.
     
    277277        $this->assertSame( 200, $response->get_status() );
    278278        $data = $response->get_data();
    279         $this->assertSame( 2, count( $data ) );
     279        $this->assertCount( 2, $data );
    280280        $this->assertSameSets( array( self::$editor_id, self::$author_id ), wp_list_pluck( $data, 'author' ) );
    281281
     
    286286        $this->assertSame( 200, $response->get_status() );
    287287        $data = $response->get_data();
    288         $this->assertSame( 1, count( $data ) );
     288        $this->assertCount( 1, $data );
    289289        $this->assertSame( self::$editor_id, $data[0]['author'] );
    290290    }
     
    301301        $response = rest_get_server()->dispatch( $request );
    302302        $this->assertSame( 200, $response->get_status() );
    303         $this->assertSame( $total_posts, count( $response->get_data() ) );
     303        $this->assertCount( $total_posts, $response->get_data() );
    304304
    305305        // Exclude editor and author.
     
    310310        $this->assertSame( 200, $response->get_status() );
    311311        $data = $response->get_data();
    312         $this->assertSame( $total_posts - 2, count( $data ) );
     312        $this->assertCount( $total_posts - 2, $data );
    313313        $this->assertNotEquals( self::$editor_id, $data[0]['author'] );
    314314        $this->assertNotEquals( self::$author_id, $data[0]['author'] );
     
    321321        $this->assertSame( 200, $response->get_status() );
    322322        $data = $response->get_data();
    323         $this->assertSame( $total_posts - 1, count( $data ) );
     323        $this->assertCount( $total_posts - 1, $data );
    324324        $this->assertNotEquals( self::$editor_id, $data[0]['author'] );
    325325        $this->assertNotEquals( self::$editor_id, $data[1]['author'] );
     
    352352        $response = rest_get_server()->dispatch( $request );
    353353        $data     = $response->get_data();
    354         $this->assertSame( 2, count( $data ) );
     354        $this->assertCount( 2, $data );
    355355        $this->assertSame( $id2, $data[0]['id'] );
    356356        $this->assertPostsOrderedBy( '{posts}.post_date DESC' );
     
    360360        $response = rest_get_server()->dispatch( $request );
    361361        $data     = $response->get_data();
    362         $this->assertSame( 2, count( $data ) );
     362        $this->assertCount( 2, $data );
    363363        $this->assertSame( $id1, $data[0]['id'] );
    364364        $this->assertPostsOrderedBy( "FIELD({posts}.ID,$id1,$id2)" );
     
    510510        $request->set_param( 'per_page', self::$per_page );
    511511        $response = rest_get_server()->dispatch( $request );
    512         $this->assertSame( $total_posts, count( $response->get_data() ) );
     512        $this->assertCount( $total_posts,  $response->get_data() );
    513513
    514514        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     
    516516        $response = rest_get_server()->dispatch( $request );
    517517        $data     = $response->get_data();
    518         $this->assertSame( 1, count( $data ) );
     518        $this->assertCount( 1, $data );
    519519        $this->assertSame( 'Search Result', $data[0]['title']['rendered'] );
    520520    }
     
    539539        $this->assertSame( 200, $response->get_status() );
    540540        $data = $response->get_data();
    541         $this->assertSame( 1, count( $data ) );
     541        $this->assertCount( 1, $data );
    542542        $this->assertSame( 'Apple', $data[0]['title']['rendered'] );
    543543    }
     
    568568        $this->assertSame( 200, $response->get_status() );
    569569        $data = $response->get_data();
    570         $this->assertSame( 2, count( $data ) );
     570        $this->assertCount( 2, $data );
    571571        $titles = array(
    572572            $data[0]['title']['rendered'],
     
    602602        $this->assertSame( 200, $response->get_status() );
    603603        $data = $response->get_data();
    604         $this->assertSame( 2, count( $data ) );
     604        $this->assertCount( 2, $data );
    605605        $titles = array(
    606606            $data[0]['title']['rendered'],
     
    621621        $response = rest_get_server()->dispatch( $request );
    622622        $this->assertSame( 200, $response->get_status() );
    623         $this->assertSame( self::$total_posts, count( $response->get_data() ) );
     623        $this->assertCount( self::$total_posts, $response->get_data() );
    624624
    625625        $request = new WP_REST_Request( 'GET', '/wp/v2/posts' );
     
    634634        $response = rest_get_server()->dispatch( $request );
    635635        $this->assertSame( 200, $response->get_status() );
    636         $this->assertSame( 1, count( $response->get_data() ) );
     636        $this->assertCount( 1, $response->get_data() );
    637637    }
    638638
     
    651651        $this->assertSame( 200, $response->get_status() );
    652652        $data = $response->get_data();
    653         $this->assertSame( 2, count( $data ) );
     653        $this->assertCount( 2, $data );
    654654        $statuses = array(
    655655            $data[0]['status'],
     
    674674        $this->assertSame( 200, $response->get_status() );
    675675        $data = $response->get_data();
    676         $this->assertSame( 2, count( $data ) );
     676        $this->assertCount( 2, $data );
    677677        $statuses = array(
    678678            $data[0]['status'],
     
    41684168        $data       = $response->get_data();
    41694169        $properties = $data['schema']['properties'];
    4170         $this->assertSame( 26, count( $properties ) );
     4170        $this->assertCount( 26, $properties );
    41714171        $this->assertArrayHasKey( 'author', $properties );
    41724172        $this->assertArrayHasKey( 'comment_status', $properties );
Note: See TracChangeset for help on using the changeset viewer.