Making WordPress.org


Ignore:
Timestamp:
12/19/2017 04:22:37 PM (8 years ago)
Author:
obenland
Message:

PLugins: Clean up formatting with phpcbf

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/tests/phpunit/tests/wporg-plugin-api-performance.php

    r5841 r6287  
    1010class Tests_Plugins_API_Performance extends WP_UnitTestCase {
    1111
    12     public $api_endpoint_1_0 = 'http://api.wordpress.org/plugins/info/1.0/';
    13     public $api_endpoint_1_1 = 'http://api.wordpress.org/plugins/info/1.1/';
    14     public $api_endpoint_plugin_php = 'http://api.wordpress.org/plugins/info/1.0/jetpack.php';
    15     public $api_endpoint_plugin_xml = 'http://api.wordpress.org/plugins/info/1.0/jetpack.xml';
     12    public $api_endpoint_1_0         = 'http://api.wordpress.org/plugins/info/1.0/';
     13    public $api_endpoint_1_1         = 'http://api.wordpress.org/plugins/info/1.1/';
     14    public $api_endpoint_plugin_php  = 'http://api.wordpress.org/plugins/info/1.0/jetpack.php';
     15    public $api_endpoint_plugin_xml  = 'http://api.wordpress.org/plugins/info/1.0/jetpack.xml';
    1616    public $api_endpoint_plugin_json = 'http://api.wordpress.org/plugins/info/1.0/jetpack.json';
    1717
    18     public $user_agent = 'WordPress/4.8'; // Tell the API to use the v3 back-end
     18    public $user_agent      = 'WordPress/4.8'; // Tell the API to use the v3 back-end
    1919    public $timeout_seconds = 5.0;
    2020
     
    6161        $median = $values[ floor( count( $values ) / 2 ) ];
    6262
    63         return "mean ". number_format( $mean, $decimals ) . ", median " . number_format( $median, $decimals );
     63        return 'mean ' . number_format( $mean, $decimals ) . ', median ' . number_format( $median, $decimals );
    6464
    6565    }
     
    6868        global $wporg_plugin_api_performance;
    6969
    70         echo "Performance summary for ". get_called_class() . ":\n";
     70        echo 'Performance summary for ' . get_called_class() . ":\n";
    7171        foreach ( $wporg_plugin_api_performance[ get_called_class() ] as $type => $deltas ) {
    7272            echo "$type: " . self::averages( $deltas ) . "\n";
     
    100100
    101101        // The 50 most common plugin tags
    102         $common_terms = explode( ' ', 'widget post admin woocommerce posts comments shortcode twitter google images facebook sidebar image seo page gallery social email links login ecommerce widgets video rss buddypress pages jquery spam content security ajax media slider feed category search analytics menu embed javascript e-commerce link css form comment share youtube custom categories theme');
     102        $common_terms = explode( ' ', 'widget post admin woocommerce posts comments shortcode twitter google images facebook sidebar image seo page gallery social email links login ecommerce widgets video rss buddypress pages jquery spam content security ajax media slider feed category search analytics menu embed javascript e-commerce link css form comment share youtube custom categories theme' );
    103103
    104104        // Each item represents the function arguments to a plugins_api() call.
    105105        $r = array(
    106             array( 'plugin_information', array( 'slug' => 'jetpack', 'fields' => $this->fields ) ),
    107             array( 'query_plugins', array( 'browse' => 'updated', 'per_page' => 24, 'page'=> 103, 'fields' => $this->fields )),
    108             array( 'query_plugins', array( 'user' => 'dd32', 'fields' => $this->fields )),
    109             array( 'query_plugins', array( 'browse' => 'popular', 'per_page' => 20, 'fields' => $this->fields ) ),
    110             array( 'query_plugins', array( 'browse' => 'recommended', 'installed_plugins' => array( 'akismet', 'jetpack' ), 'fields' => $this->fields ) )
     106            array(
     107                'plugin_information',
     108                array(
     109                    'slug'   => 'jetpack',
     110                    'fields' => $this->fields,
     111                ),
     112            ),
     113            array(
     114                'query_plugins',
     115                array(
     116                    'browse'   => 'updated',
     117                    'per_page' => 24,
     118                    'page'     => 103,
     119                    'fields'   => $this->fields,
     120                ),
     121            ),
     122            array(
     123                'query_plugins',
     124                array(
     125                    'user'   => 'dd32',
     126                    'fields' => $this->fields,
     127                ),
     128            ),
     129            array(
     130                'query_plugins',
     131                array(
     132                    'browse'   => 'popular',
     133                    'per_page' => 20,
     134                    'fields'   => $this->fields,
     135                ),
     136            ),
     137            array(
     138                'query_plugins',
     139                array(
     140                    'browse'            => 'recommended',
     141                    'installed_plugins' => array( 'akismet', 'jetpack' ),
     142                    'fields'            => $this->fields,
     143                ),
     144            ),
    111145        );
    112146
    113147        // 20 random searches
    114         for ( $i=0; $i < 20; $i++ ) {
     148        for ( $i = 0; $i < 20; $i++ ) {
    115149            $random_search = join( ' ', array_rand( array_flip( $common_terms ), 3 ) ); // 3 random terms
    116             $r[] = array( 'query_plugins', array( 'search'   => $random_search, 'per_page' => 15, 'page' => 3, 'fields' => $this->fields ) );
     150            $r[]           = array(
     151                'query_plugins',
     152                array(
     153                    'search'   => $random_search,
     154                    'per_page' => 15,
     155                    'page'     => 3,
     156                    'fields'   => $this->fields,
     157                ),
     158            );
    117159        }
    118160
    119161        // 100 recently updated plugins
    120         $recently_updated_plugins = plugins_api( 'query_plugins',
    121                 array(
    122                     'browse' => 'updated',
    123                     'fields' => array( 'description' => false, 'short_description' => false ),
    124                     'per_page' => 100,
    125                     'page' => rand(0 , 400),
    126                     )
    127                 );
     162        $recently_updated_plugins = plugins_api( 'query_plugins', array(
     163            'browse'   => 'updated',
     164            'fields'   => array(
     165                'description'       => false,
     166                'short_description' => false,
     167            ),
     168            'per_page' => 100,
     169            'page'     => rand( 0, 400 ),
     170        ) );
    128171        $this->assertFalse( is_wp_error( $recently_updated_plugins ) );
    129         $this->assertEquals( 100, count( $recently_updated_plugins->plugins ));
    130         foreach ( $recently_updated_plugins->plugins as $plugin )
    131             $r[] = array( 'plugin_information', array( 'slug' => $plugin->slug, 'fields' => $this->fields ) );
     172        $this->assertEquals( 100, count( $recently_updated_plugins->plugins ) );
     173        foreach ( $recently_updated_plugins->plugins as $plugin ) {
     174            $r[] = array(
     175                'plugin_information',
     176                array(
     177                    'slug'   => $plugin->slug,
     178                    'fields' => $this->fields,
     179                ),
     180            );
     181        }
    132182
    133183        return $r;
     
    139189     * @dataProvider performanceTestProvider
    140190     */
    141      function test_api_performance( $action, $args ) {
    142         global $wporg_plugin_api_performance;
    143 
    144         $start = microtime( true );
     191    function test_api_performance( $action, $args ) {
     192        global $wporg_plugin_api_performance;
     193
     194        $start    = microtime( true );
    145195        $response = plugins_api( $action, $args );
    146         $delta = microtime( true ) - $start;
    147 
    148         #error_log( get_class( $this ) . ": $action ". array_keys($args)[0]." ".array_values($args)[0]." took $delta" );
    149         $wporg_plugin_api_performance[ get_class( $this ) ][ $action . ' ' . array_keys($args)[0] ][] = $delta;
     196        $delta    = microtime( true ) - $start;
     197
     198        // error_log( get_class( $this ) . ": $action ". array_keys($args)[0]." ".array_values($args)[0]." took $delta" );
     199        $wporg_plugin_api_performance[ get_class( $this ) ][ $action . ' ' . array_keys( $args )[0] ][] = $delta;
    150200
    151201        $this->assertLessThan( $this->timeout_seconds, $delta, "API call $action took $delta seconds" );
Note: See TracChangeset for help on using the changeset viewer.