Make WordPress Core


Ignore:
Timestamp:
07/07/2021 10:32:56 AM (5 years 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-users-controller.php

    r51331 r51367  
    388388                $request  = new WP_REST_Request( 'GET', '/wp/v2/users' );
    389389                $response = rest_get_server()->dispatch( $request );
    390                 $this->assertSame( 10, count( $response->get_data() ) );
     390                $this->assertCount( 10, $response->get_data() );
    391391
    392392                $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
    393393                $request->set_param( 'per_page', 5 );
    394394                $response = rest_get_server()->dispatch( $request );
    395                 $this->assertSame( 5, count( $response->get_data() ) );
     395                $this->assertCount( 5, $response->get_data() );
    396396        }
    397397
    … …  
    403403                $request->set_param( 'page', 2 );
    404404                $response = rest_get_server()->dispatch( $request );
    405                 $this->assertSame( 5, count( $response->get_data() ) );
     405                $this->assertCount( 5, $response->get_data() );
    406406                $prev_link = add_query_arg(
    407407                        array(
    … …  
    599599                $response = rest_get_server()->dispatch( $request );
    600600                $data     = $response->get_data();
    601                 $this->assertSame( 2, count( $data ) );
     601                $this->assertCount( 2, $data );
    602602                $this->assertSame( $id1, $data[0]['id'] );
    603603
    … …  
    606606                $response = rest_get_server()->dispatch( $request );
    607607                $data     = $response->get_data();
    608                 $this->assertSame( 2, count( $data ) );
     608                $this->assertCount( 2, $data );
    609609                $this->assertSame( $id2, $data[0]['id'] );
    610610
    … …  
    619619                $response = rest_get_server()->dispatch( $request );
    620620                $data     = $response->get_data();
    621                 $this->assertSame( 0, count( $data ) );
     621                $this->assertCount( 0, $data );
    622622
    623623        }
    … …  
    656656                $request->set_param( 'search', 'yololololo' );
    657657                $response = rest_get_server()->dispatch( $request );
    658                 $this->assertSame( 0, count( $response->get_data() ) );
     658                $this->assertCount( 0, $response->get_data() );
    659659
    660660                $yolo_id = $this->factory->user->create( array( 'display_name' => 'yololololo' ) );
    … …  
    663663                $request->set_param( 'search', 'yololololo' );
    664664                $response = rest_get_server()->dispatch( $request );
    665                 $this->assertSame( 1, count( $response->get_data() ) );
     665                $this->assertCount( 1, $response->get_data() );
    666666                // Default to wildcard search.
    667667                $adam_id = $this->factory->user->create(
    … …  
    676676                $response = rest_get_server()->dispatch( $request );
    677677                $data     = $response->get_data();
    678                 $this->assertSame( 1, count( $data ) );
     678                $this->assertCount( 1, $data );
    679679                $this->assertSame( $adam_id, $data[0]['id'] );
    680680        }
    … …  
    700700                $response = rest_get_server()->dispatch( $request );
    701701                $data     = $response->get_data();
    702                 $this->assertSame( 1, count( $data ) );
     702                $this->assertCount( 1, $data );
    703703                $this->assertSame( $id2, $data[0]['id'] );
    704704        }
    … …  
    813813                $response = rest_get_server()->dispatch( $request );
    814814                $data     = $response->get_data();
    815                 $this->assertSame( 3, count( $data ) );
     815                $this->assertCount( 3, $data );
    816816                $this->assertSame( $tango, $data[1]['id'] );
    817817                $this->assertSame( $yolo, $data[2]['id'] );
    … …  
    820820                $response = rest_get_server()->dispatch( $request );
    821821                $data     = $response->get_data();
    822                 $this->assertSame( 1, count( $data ) );
     822                $this->assertCount( 1, $data );
    823823                $this->assertSame( $yolo, $data[0]['id'] );
    824824
    … …  
    850850                $response = rest_get_server()->dispatch( $request );
    851851                $data     = $response->get_data();
    852                 $this->assertSame( 1, count( $data ) );
     852                $this->assertCount( 1, $data );
    853853                $this->assertSame( $lolz, $data[0]['id'] );
    854854
    … …  
    857857                $response = rest_get_server()->dispatch( $request );
    858858                $data     = $response->get_data();
    859                 $this->assertSame( 0, count( $data ) );
     859                $this->assertCount( 0, $data );
    860860                $this->assertSame( array(), $data );
    861861        }
    … …  
    26212621                $properties = $data['schema']['properties'];
    26222622
    2623                 $this->assertSame( 19, count( $properties ) );
     2623                $this->assertCount( 19, $properties );
    26242624                $this->assertArrayHasKey( 'avatar_urls', $properties );
    26252625                $this->assertArrayHasKey( 'capabilities', $properties );
Note: See TracChangeset for help on using the changeset viewer.