Make WordPress Core

Changeset 44903


Ignore:
Timestamp:
03/15/2019 12:15:08 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Build/Test Tools: Add missing access modifiers to factory classes in phpunit/includes/factory.

Props andizer.
Fixes #46504.

Location:
trunk/tests/phpunit/includes/factory
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-callback-after-create.php

    r44497 r44903  
    66     * @var callable
    77     */
    8     var $callback;
     8    public $callback;
    99
    1010    /**
     
    1313     * @param callable $callback A callback function.
    1414     */
    15     function __construct( $callback ) {
     15    public function __construct( $callback ) {
    1616        $this->callback = $callback;
    1717    }
     
    2424     * @return mixed The possibly altered object.
    2525     */
    26     function call( $object ) {
     26    public function call( $object ) {
    2727        return call_user_func( $this->callback, $object );
    2828    }
  • trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php

    r44785 r44903  
    1717     * @return  int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
    1818     */
    19     function create_object( $args, $legacy_parent = 0, $legacy_args = array() ) {
     19    public function create_object( $args, $legacy_parent = 0, $legacy_args = array() ) {
    2020        // Backward compatibility for legacy argument format.
    2121        if ( is_string( $args ) ) {
     
    4545     * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure.
    4646     */
    47     function create_upload_object( $file, $parent = 0 ) {
     47    public function create_upload_object( $file, $parent = 0 ) {
    4848        $contents = file_get_contents( $file );
    4949        $upload   = wp_upload_bits( wp_basename( $file ), null, $contents );
  • trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php

    r44497 r44903  
    1313class WP_UnitTest_Factory_For_Blog extends WP_UnitTest_Factory_For_Thing {
    1414
    15     function __construct( $factory = null ) {
     15    public function __construct( $factory = null ) {
    1616        global $current_site, $base;
    1717        parent::__construct( $factory );
     
    3131     * @return int|WP_Error Returns WP_Error object on failure, the site ID on success.
    3232     */
    33     function create_object( $args ) {
     33    public function create_object( $args ) {
    3434        global $wpdb;
    3535        $meta    = isset( $args['meta'] ) ? $args['meta'] : array( 'public' => 1 );
     
    5454     * @return void
    5555     */
    56     function update_object( $blog_id, $fields ) {}
     56    public function update_object( $blog_id, $fields ) {}
    5757
    5858    /**
     
    6363     * @return null|WP_Site The site object or null if not found.
    6464     */
    65     function get_object_by_id( $blog_id ) {
     65    public function get_object_by_id( $blog_id ) {
    6666        return get_site( $blog_id );
    6767    }
  • trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-comment.php

    r44497 r44903  
    1313class WP_UnitTest_Factory_For_Comment extends WP_UnitTest_Factory_For_Thing {
    1414
    15     function __construct( $factory = null ) {
     15    public function __construct( $factory = null ) {
    1616        parent::__construct( $factory );
    1717        $this->default_generation_definitions = array(
     
    3030     * @return false|int The comment's ID on success, false on failure.
    3131     */
    32     function create_object( $args ) {
     32    public function create_object( $args ) {
    3333        return wp_insert_comment( $this->addslashes_deep( $args ) );
    3434    }
     
    4242     * @return int When updated 1, not update 0.
    4343     */
    44     function update_object( $comment_id, $fields ) {
     44    public function update_object( $comment_id, $fields ) {
    4545        $fields['comment_ID'] = $comment_id;
    4646        return wp_update_comment( $this->addslashes_deep( $fields ) );
     
    5757     * @return int[] Array with the comment ids.
    5858     */
    59     function create_post_comments( $post_id, $count = 1, $args = array(), $generation_definitions = null ) {
     59    public function create_post_comments( $post_id, $count = 1, $args = array(), $generation_definitions = null ) {
    6060        $args['comment_post_ID'] = $post_id;
    6161        return $this->create_many( $count, $args, $generation_definitions );
     
    6969     * @return null|WP_Comment WP_Comment when found, null when not found.
    7070     */
    71     function get_object_by_id( $comment_id ) {
     71    public function get_object_by_id( $comment_id ) {
    7272        return get_comment( $comment_id );
    7373    }
  • trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-network.php

    r42343 r44903  
    1313class WP_UnitTest_Factory_For_Network extends WP_UnitTest_Factory_For_Thing {
    1414
    15     function __construct( $factory = null ) {
     15    public function __construct( $factory = null ) {
    1616        parent::__construct( $factory );
    1717        $this->default_generation_definitions = array(
     
    2424    }
    2525
    26     function create_object( $args ) {
     26    public function create_object( $args ) {
    2727        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    2828
     
    3737    }
    3838
    39     function update_object( $network_id, $fields ) {}
     39    public function update_object( $network_id, $fields ) {}
    4040
    41     function get_object_by_id( $network_id ) {
     41    public function get_object_by_id( $network_id ) {
    4242        return get_network( $network_id );
    4343    }
  • trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-post.php

    r44497 r44903  
    1313class WP_UnitTest_Factory_For_Post extends WP_UnitTest_Factory_For_Thing {
    1414
    15     function __construct( $factory = null ) {
     15    public function __construct( $factory = null ) {
    1616        parent::__construct( $factory );
    1717        $this->default_generation_definitions = array(
     
    3131     * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure.
    3232     */
    33     function create_object( $args ) {
     33    public function create_object( $args ) {
    3434        return wp_insert_post( $args );
    3535    }
     
    4343     * @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success.
    4444     */
    45     function update_object( $post_id, $fields ) {
     45    public function update_object( $post_id, $fields ) {
    4646        $fields['ID'] = $post_id;
    4747        return wp_update_post( $fields );
     
    5555     * @return null|WP_Post WP_Post on success or null on failure.
    5656     */
    57     function get_object_by_id( $post_id ) {
     57    public function get_object_by_id( $post_id ) {
    5858        return get_post( $post_id );
    5959    }
  • trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php

    r44497 r44903  
    1515    const DEFAULT_TAXONOMY = 'post_tag';
    1616
    17     function __construct( $factory = null, $taxonomy = null ) {
     17    public function __construct( $factory = null, $taxonomy = null ) {
    1818        parent::__construct( $factory );
    1919        $this->taxonomy                       = $taxonomy ? $taxonomy : self::DEFAULT_TAXONOMY;
     
    3232     * @return array|WP_Error
    3333     */
    34     function create_object( $args ) {
     34    public function create_object( $args ) {
    3535        $args         = array_merge( array( 'taxonomy' => $this->taxonomy ), $args );
    3636        $term_id_pair = wp_insert_term( $args['name'], $args['taxonomy'], $args );
     
    4949     * @return int The term id.
    5050     */
    51     function update_object( $term, $fields ) {
     51    public function update_object( $term, $fields ) {
    5252        $fields = array_merge( array( 'taxonomy' => $this->taxonomy ), $fields );
    5353        if ( is_object( $term ) ) {
     
    7272     * @return array|false|WP_Error Array of term taxonomy IDs of affected terms. WP_Error or false on failure.
    7373     */
    74     function add_post_terms( $post_id, $terms, $taxonomy, $append = true ) {
     74    public function add_post_terms( $post_id, $terms, $taxonomy, $append = true ) {
    7575        return wp_set_post_terms( $post_id, $terms, $taxonomy, $append );
    7676    }
     
    8484     * @return null|WP_Error|WP_Term WP_Term on success. WP_error if taxonomy does not exist. Null for miscellaneous failure.
    8585     */
    86     function create_and_get( $args = array(), $generation_definitions = null ) {
     86    public function create_and_get( $args = array(), $generation_definitions = null ) {
    8787        $term_id  = $this->create( $args, $generation_definitions );
    8888        $taxonomy = isset( $args['taxonomy'] ) ? $args['taxonomy'] : $this->taxonomy;
     
    9797     * @return null|WP_Error|WP_Term WP_Term on success. WP_error if taxonomy does not exist. Null for miscellaneous failure.
    9898     */
    99     function get_object_by_id( $term_id ) {
     99    public function get_object_by_id( $term_id ) {
    100100        return get_term( $term_id, $this->taxonomy );
    101101    }
  • trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php

    r44497 r44903  
    66abstract class WP_UnitTest_Factory_For_Thing {
    77
    8     var $default_generation_definitions;
    9     var $factory;
     8    public $default_generation_definitions;
     9    public $factory;
    1010
    1111    /**
     
    1717     * {@link WP_UnitTest_Generator_Locale_Name}, {@link WP_UnitTest_Factory_Callback_After_Create}.
    1818     */
    19     function __construct( $factory, $default_generation_definitions = array() ) {
     19    public function __construct( $factory, $default_generation_definitions = array() ) {
    2020        $this->factory                        = $factory;
    2121        $this->default_generation_definitions = $default_generation_definitions;
     
    2929     * @return mixed The result. Can be anything.
    3030     */
    31     abstract function create_object( $args );
     31    abstract public function create_object( $args );
    3232
    3333    /**
     
    3939     * @return mixed The result. Can be anything.
    4040     */
    41     abstract function update_object( $object, $fields );
     41    abstract public function update_object( $object, $fields );
    4242
    4343    /**
     
    4949     * @return mixed The result. Can be anything.
    5050     */
    51     function create( $args = array(), $generation_definitions = null ) {
     51    public function create( $args = array(), $generation_definitions = null ) {
    5252        if ( is_null( $generation_definitions ) ) {
    5353            $generation_definitions = $this->default_generation_definitions;
     
    7878     * @return mixed The created object. Can be anything.
    7979     */
    80     function create_and_get( $args = array(), $generation_definitions = null ) {
     80    public function create_and_get( $args = array(), $generation_definitions = null ) {
    8181        $object_id = $this->create( $args, $generation_definitions );
    8282        return $this->get_object_by_id( $object_id );
     
    9090     * @return mixed The object. Can be anything.
    9191     */
    92     abstract function get_object_by_id( $object_id );
     92    abstract public function get_object_by_id( $object_id );
    9393
    9494    /**
     
    101101     * @return array
    102102     */
    103     function create_many( $count, $args = array(), $generation_definitions = null ) {
     103    public function create_many( $count, $args = array(), $generation_definitions = null ) {
    104104        $results = array();
    105105        for ( $i = 0; $i < $count; $i++ ) {
     
    119119     * @return array|WP_Error Combined array on success. WP_Error when default value is incorrent.
    120120     */
    121     function generate_args( $args = array(), $generation_definitions = null, &$callbacks = null ) {
     121    public function generate_args( $args = array(), $generation_definitions = null, &$callbacks = null ) {
    122122        $callbacks = array();
    123123        if ( is_null( $generation_definitions ) ) {
     
    156156     * @return array The altered fields.
    157157     */
    158     function apply_callbacks( $callbacks, $created ) {
     158    public function apply_callbacks( $callbacks, $created ) {
    159159        $updated_fields = array();
    160160
     
    172172     * @return WP_UnitTest_Factory_Callback_After_Create
    173173     */
    174     function callback( $function ) {
     174    public function callback( $function ) {
    175175        return new WP_UnitTest_Factory_Callback_After_Create( $function );
    176176    }
     
    183183     * @return array|string The value with the possibly applied slashes.
    184184     */
    185     function addslashes_deep( $value ) {
     185    public function addslashes_deep( $value ) {
    186186        if ( is_array( $value ) ) {
    187187            $value = array_map( array( $this, 'addslashes_deep' ), $value );
  • trunk/tests/phpunit/includes/factory/class-wp-unittest-factory-for-user.php

    r44497 r44903  
    1313class WP_UnitTest_Factory_For_User extends WP_UnitTest_Factory_For_Thing {
    1414
    15     function __construct( $factory = null ) {
     15    public function __construct( $factory = null ) {
    1616        parent::__construct( $factory );
    1717        $this->default_generation_definitions = array(
     
    2929     * @return int|WP_Error
    3030     */
    31     function create_object( $args ) {
     31    public function create_object( $args ) {
    3232        return wp_insert_user( $args );
    3333    }
     
    4141     * @return int|WP_Error User id on success. WP_Error on failure.
    4242     */
    43     function update_object( $user_id, $fields ) {
     43    public function update_object( $user_id, $fields ) {
    4444        $fields['ID'] = $user_id;
    4545        return wp_update_user( $fields );
     
    5353     * @return WP_User The user.
    5454     */
    55     function get_object_by_id( $user_id ) {
     55    public function get_object_by_id( $user_id ) {
    5656        return new WP_User( $user_id );
    5757    }
  • trunk/tests/phpunit/includes/factory/class-wp-unittest-factory.php

    r42343 r44903  
    5959    public $network;
    6060
    61     function __construct() {
     61    public function __construct() {
    6262        $this->post       = new WP_UnitTest_Factory_For_Post( $this );
    6363        $this->attachment = new WP_UnitTest_Factory_For_Attachment( $this );
  • trunk/tests/phpunit/includes/factory/class-wp-unittest-generator-sequence.php

    r42343 r44903  
    66    public $template_string;
    77
    8     function __construct( $template_string = '%s', $start = null ) {
     8    public function __construct( $template_string = '%s', $start = null ) {
    99        if ( $start ) {
    1010            $this->next = $start;
     
    1616    }
    1717
    18     function next() {
     18    public function next() {
    1919        $generated = sprintf( $this->template_string, $this->next );
    2020        $this->next++;
Note: See TracChangeset for help on using the changeset viewer.