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

    r50463 r51367  
    184184        $response = rest_get_server()->dispatch( $request );
    185185        $data     = $response->get_data();
    186         $this->assertSame( 2, count( $data ) );
     186        $this->assertCount( 2, $data );
    187187        $this->assertSame( 'Season 5', $data[0]['name'] );
    188188        $this->assertSame( 'The Be Sharps', $data[1]['name'] );
     
    192192        $response = rest_get_server()->dispatch( $request );
    193193        $data     = $response->get_data();
    194         $this->assertSame( $total_categories, count( $data ) );
     194        $this->assertCount( $total_categories, $data );
    195195    }
    196196
     
    292292        $response = rest_get_server()->dispatch( $request );
    293293        $data     = $response->get_data();
    294         $this->assertSame( 2, count( $data ) );
     294        $this->assertCount( 2, $data );
    295295        $this->assertSame( $id1, $data[0]['id'] );
    296296
     
    299299        $response = rest_get_server()->dispatch( $request );
    300300        $data     = $response->get_data();
    301         $this->assertSame( 2, count( $data ) );
     301        $this->assertCount( 2, $data );
    302302        $this->assertSame( $id2, $data[0]['id'] );
    303303    }
     
    340340        $this->assertSame( 200, $response->get_status() );
    341341        $data = $response->get_data();
    342         $this->assertSame( 1, count( $data ) );
     342        $this->assertCount( 1, $data );
    343343        $this->assertSame( 'Uncategorized', $data[0]['name'] );
    344344
     
    350350        $this->assertSame( 200, $response->get_status() );
    351351        $data = $response->get_data();
    352         $this->assertSame( 2, count( $data ) );
     352        $this->assertCount( 2, $data );
    353353        $this->assertSame( 'Apple', $data[0]['name'] );
    354354    }
     
    440440
    441441        $data = $response->get_data();
    442         $this->assertSame( 3, count( $data ) );
     442        $this->assertCount( 3, $data );
    443443
    444444        // Check ordered by name by default.
     
    458458
    459459        $data = $response->get_data();
    460         $this->assertSame( 3, count( $data ) );
     460        $this->assertCount( 3, $data );
    461461        $names = wp_list_pluck( $data, 'name' );
    462462        $this->assertSame( array( 'Image', 'Marvel', 'DC' ), $names, 'Terms should be ordered by description' );
     
    468468
    469469        $data = $response->get_data();
    470         $this->assertSame( 3, count( $data ) );
     470        $this->assertCount( 3, $data );
    471471        $names = wp_list_pluck( $data, 'name' );
    472472        $this->assertSame( array( 'DC', 'Marvel', 'Image' ), $names, 'Terms should be reverse-ordered by description' );
     
    483483
    484484        $data = $response->get_data();
    485         $this->assertSame( 3, count( $data ) );
     485        $this->assertCount( 3, $data );
    486486        $names = wp_list_pluck( $data, 'name' );
    487487        $this->assertSame( array( 'DC', 'Marvel', 'Image' ), $names );
     
    519519
    520520        $data = $response->get_data();
    521         $this->assertSame( 2, count( $data ) );
     521        $this->assertCount( 2, $data );
    522522        $this->assertSame( 'Cape', $data[0]['name'] );
    523523    }
     
    536536        $this->assertSame( 200, $response->get_status() );
    537537        $data = $response->get_data();
    538         $this->assertSame( 1, count( $data ) );
     538        $this->assertCount( 1, $data );
    539539        $this->assertSame( 'Apple', $data[0]['name'] );
    540540
     
    544544        $this->assertSame( 200, $response->get_status() );
    545545        $data = $response->get_data();
    546         $this->assertSame( 0, count( $data ) );
     546        $this->assertCount( 0, $data );
    547547    }
    548548
     
    556556        $this->assertSame( 200, $response->get_status() );
    557557        $data = $response->get_data();
    558         $this->assertSame( 1, count( $data ) );
     558        $this->assertCount( 1, $data );
    559559        $this->assertSame( 'Apple', $data[0]['name'] );
    560560    }
     
    573573        $response = rest_get_server()->dispatch( $request );
    574574        $data     = $response->get_data();
    575         $this->assertSame( 1, count( $data ) );
     575        $this->assertCount( 1, $data );
    576576        $this->assertSame( 'Child', $data[0]['name'] );
    577577    }
     
    11311131        $data       = $response->get_data();
    11321132        $properties = $data['schema']['properties'];
    1133         $this->assertSame( 9, count( $properties ) );
     1133        $this->assertCount( 9, $properties );
    11341134        $this->assertArrayHasKey( 'id', $properties );
    11351135        $this->assertArrayHasKey( 'count', $properties );
Note: See TracChangeset for help on using the changeset viewer.