From 1bfa9370f7455f4ca43cc4ea534f2171d91cb278 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 15 Mar 2019 12:15:08 +0000 Subject: [PATCH] Build/Test Tools: Add missing access modifiers to factory classes in `phpunit/includes/factory`. Props andizer. Fixes #46504. git-svn-id: https://develop.svn.wordpress.org/trunk@44903 602fd350-edb4-49c9-b593-d223f7449a82 --- ...unittest-factory-callback-after-create.php | 6 ++--- ...ass-wp-unittest-factory-for-attachment.php | 4 +-- .../class-wp-unittest-factory-for-blog.php | 8 +++--- .../class-wp-unittest-factory-for-comment.php | 10 +++---- .../class-wp-unittest-factory-for-network.php | 8 +++--- .../class-wp-unittest-factory-for-post.php | 8 +++--- .../class-wp-unittest-factory-for-term.php | 12 ++++----- .../class-wp-unittest-factory-for-thing.php | 26 +++++++++---------- .../class-wp-unittest-factory-for-user.php | 8 +++--- .../factory/class-wp-unittest-factory.php | 2 +- .../class-wp-unittest-generator-sequence.php | 4 +-- 11 files changed, 48 insertions(+), 48 deletions(-) diff --git a/tests/phpunit/includes/factory/class-wp-unittest-factory-callback-after-create.php b/tests/phpunit/includes/factory/class-wp-unittest-factory-callback-after-create.php index 9b00e7279a..8becb3239f 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-factory-callback-after-create.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-factory-callback-after-create.php @@ -5,14 +5,14 @@ class WP_UnitTest_Factory_Callback_After_Create { /** * @var callable */ - var $callback; + public $callback; /** * WP_UnitTest_Factory_Callback_After_Create constructor. * * @param callable $callback A callback function. */ - function __construct( $callback ) { + public function __construct( $callback ) { $this->callback = $callback; } @@ -23,7 +23,7 @@ class WP_UnitTest_Factory_Callback_After_Create { * * @return mixed The possibly altered object. */ - function call( $object ) { + public function call( $object ) { return call_user_func( $this->callback, $object ); } } diff --git a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php index f02b3e26b8..98f1be8fde 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-attachment.php @@ -16,7 +16,7 @@ class WP_UnitTest_Factory_For_Attachment extends WP_UnitTest_Factory_For_Post { * * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure. */ - function create_object( $args, $legacy_parent = 0, $legacy_args = array() ) { + public function create_object( $args, $legacy_parent = 0, $legacy_args = array() ) { // Backward compatibility for legacy argument format. if ( is_string( $args ) ) { $file = $args; @@ -44,7 +44,7 @@ class WP_UnitTest_Factory_For_Attachment extends WP_UnitTest_Factory_For_Post { * * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure. */ - function create_upload_object( $file, $parent = 0 ) { + public function create_upload_object( $file, $parent = 0 ) { $contents = file_get_contents( $file ); $upload = wp_upload_bits( wp_basename( $file ), null, $contents ); diff --git a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php index 5a5b5d3718..68d24d30bb 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-blog.php @@ -12,7 +12,7 @@ */ class WP_UnitTest_Factory_For_Blog extends WP_UnitTest_Factory_For_Thing { - function __construct( $factory = null ) { + public function __construct( $factory = null ) { global $current_site, $base; parent::__construct( $factory ); $this->default_generation_definitions = array( @@ -30,7 +30,7 @@ class WP_UnitTest_Factory_For_Blog extends WP_UnitTest_Factory_For_Thing { * * @return int|WP_Error Returns WP_Error object on failure, the site ID on success. */ - function create_object( $args ) { + public function create_object( $args ) { global $wpdb; $meta = isset( $args['meta'] ) ? $args['meta'] : array( 'public' => 1 ); $user_id = isset( $args['user_id'] ) ? $args['user_id'] : get_current_user_id(); @@ -53,7 +53,7 @@ class WP_UnitTest_Factory_For_Blog extends WP_UnitTest_Factory_For_Thing { * * @return void */ - function update_object( $blog_id, $fields ) {} + public function update_object( $blog_id, $fields ) {} /** * Retrieves a site by given blog id. @@ -62,7 +62,7 @@ class WP_UnitTest_Factory_For_Blog extends WP_UnitTest_Factory_For_Thing { * * @return null|WP_Site The site object or null if not found. */ - function get_object_by_id( $blog_id ) { + public function get_object_by_id( $blog_id ) { return get_site( $blog_id ); } } diff --git a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-comment.php b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-comment.php index 4ca3b2fd6d..dcec0439aa 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-comment.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-comment.php @@ -12,7 +12,7 @@ */ class WP_UnitTest_Factory_For_Comment extends WP_UnitTest_Factory_For_Thing { - function __construct( $factory = null ) { + public function __construct( $factory = null ) { parent::__construct( $factory ); $this->default_generation_definitions = array( 'comment_author' => new WP_UnitTest_Generator_Sequence( 'Commenter %s' ), @@ -29,7 +29,7 @@ class WP_UnitTest_Factory_For_Comment extends WP_UnitTest_Factory_For_Thing { * * @return false|int The comment's ID on success, false on failure. */ - function create_object( $args ) { + public function create_object( $args ) { return wp_insert_comment( $this->addslashes_deep( $args ) ); } @@ -41,7 +41,7 @@ class WP_UnitTest_Factory_For_Comment extends WP_UnitTest_Factory_For_Thing { * * @return int When updated 1, not update 0. */ - function update_object( $comment_id, $fields ) { + public function update_object( $comment_id, $fields ) { $fields['comment_ID'] = $comment_id; return wp_update_comment( $this->addslashes_deep( $fields ) ); } @@ -56,7 +56,7 @@ class WP_UnitTest_Factory_For_Comment extends WP_UnitTest_Factory_For_Thing { * * @return int[] Array with the comment ids. */ - function create_post_comments( $post_id, $count = 1, $args = array(), $generation_definitions = null ) { + public function create_post_comments( $post_id, $count = 1, $args = array(), $generation_definitions = null ) { $args['comment_post_ID'] = $post_id; return $this->create_many( $count, $args, $generation_definitions ); } @@ -68,7 +68,7 @@ class WP_UnitTest_Factory_For_Comment extends WP_UnitTest_Factory_For_Thing { * * @return null|WP_Comment WP_Comment when found, null when not found. */ - function get_object_by_id( $comment_id ) { + public function get_object_by_id( $comment_id ) { return get_comment( $comment_id ); } } diff --git a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-network.php b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-network.php index c10faf51dd..419957e0f9 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-network.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-network.php @@ -12,7 +12,7 @@ */ class WP_UnitTest_Factory_For_Network extends WP_UnitTest_Factory_For_Thing { - function __construct( $factory = null ) { + public function __construct( $factory = null ) { parent::__construct( $factory ); $this->default_generation_definitions = array( 'domain' => WP_TESTS_DOMAIN, @@ -23,7 +23,7 @@ class WP_UnitTest_Factory_For_Network extends WP_UnitTest_Factory_For_Thing { ); } - function create_object( $args ) { + public function create_object( $args ) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; if ( ! isset( $args['user'] ) ) { @@ -36,9 +36,9 @@ class WP_UnitTest_Factory_For_Network extends WP_UnitTest_Factory_For_Thing { return $args['network_id']; } - function update_object( $network_id, $fields ) {} + public function update_object( $network_id, $fields ) {} - function get_object_by_id( $network_id ) { + public function get_object_by_id( $network_id ) { return get_network( $network_id ); } } diff --git a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-post.php b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-post.php index e56ca0f191..af71802d5f 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-post.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-post.php @@ -12,7 +12,7 @@ */ class WP_UnitTest_Factory_For_Post extends WP_UnitTest_Factory_For_Thing { - function __construct( $factory = null ) { + public function __construct( $factory = null ) { parent::__construct( $factory ); $this->default_generation_definitions = array( 'post_status' => 'publish', @@ -30,7 +30,7 @@ class WP_UnitTest_Factory_For_Post extends WP_UnitTest_Factory_For_Thing { * * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure. */ - function create_object( $args ) { + public function create_object( $args ) { return wp_insert_post( $args ); } @@ -42,7 +42,7 @@ class WP_UnitTest_Factory_For_Post extends WP_UnitTest_Factory_For_Thing { * * @return int|WP_Error The value 0 or WP_Error on failure. The post ID on success. */ - function update_object( $post_id, $fields ) { + public function update_object( $post_id, $fields ) { $fields['ID'] = $post_id; return wp_update_post( $fields ); } @@ -54,7 +54,7 @@ class WP_UnitTest_Factory_For_Post extends WP_UnitTest_Factory_For_Thing { * * @return null|WP_Post WP_Post on success or null on failure. */ - function get_object_by_id( $post_id ) { + public function get_object_by_id( $post_id ) { return get_post( $post_id ); } } diff --git a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php index 76c1aac14b..1a8720af08 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-term.php @@ -14,7 +14,7 @@ class WP_UnitTest_Factory_For_Term extends WP_UnitTest_Factory_For_Thing { private $taxonomy; const DEFAULT_TAXONOMY = 'post_tag'; - function __construct( $factory = null, $taxonomy = null ) { + public function __construct( $factory = null, $taxonomy = null ) { parent::__construct( $factory ); $this->taxonomy = $taxonomy ? $taxonomy : self::DEFAULT_TAXONOMY; $this->default_generation_definitions = array( @@ -31,7 +31,7 @@ class WP_UnitTest_Factory_For_Term extends WP_UnitTest_Factory_For_Thing { * * @return array|WP_Error */ - function create_object( $args ) { + public function create_object( $args ) { $args = array_merge( array( 'taxonomy' => $this->taxonomy ), $args ); $term_id_pair = wp_insert_term( $args['name'], $args['taxonomy'], $args ); if ( is_wp_error( $term_id_pair ) ) { @@ -48,7 +48,7 @@ class WP_UnitTest_Factory_For_Term extends WP_UnitTest_Factory_For_Thing { * * @return int The term id. */ - function update_object( $term, $fields ) { + public function update_object( $term, $fields ) { $fields = array_merge( array( 'taxonomy' => $this->taxonomy ), $fields ); if ( is_object( $term ) ) { $taxonomy = $term->taxonomy; @@ -71,7 +71,7 @@ class WP_UnitTest_Factory_For_Term extends WP_UnitTest_Factory_For_Thing { * * @return array|false|WP_Error Array of term taxonomy IDs of affected terms. WP_Error or false on failure. */ - function add_post_terms( $post_id, $terms, $taxonomy, $append = true ) { + public function add_post_terms( $post_id, $terms, $taxonomy, $append = true ) { return wp_set_post_terms( $post_id, $terms, $taxonomy, $append ); } @@ -83,7 +83,7 @@ class WP_UnitTest_Factory_For_Term extends WP_UnitTest_Factory_For_Thing { * * @return null|WP_Error|WP_Term WP_Term on success. WP_error if taxonomy does not exist. Null for miscellaneous failure. */ - function create_and_get( $args = array(), $generation_definitions = null ) { + public function create_and_get( $args = array(), $generation_definitions = null ) { $term_id = $this->create( $args, $generation_definitions ); $taxonomy = isset( $args['taxonomy'] ) ? $args['taxonomy'] : $this->taxonomy; return get_term( $term_id, $taxonomy ); @@ -96,7 +96,7 @@ class WP_UnitTest_Factory_For_Term extends WP_UnitTest_Factory_For_Thing { * * @return null|WP_Error|WP_Term WP_Term on success. WP_error if taxonomy does not exist. Null for miscellaneous failure. */ - function get_object_by_id( $term_id ) { + public function get_object_by_id( $term_id ) { return get_term( $term_id, $this->taxonomy ); } } diff --git a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php index 5ae495967d..b526098194 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-thing.php @@ -5,8 +5,8 @@ */ abstract class WP_UnitTest_Factory_For_Thing { - var $default_generation_definitions; - var $factory; + public $default_generation_definitions; + public $factory; /** * Creates a new factory, which will create objects of a specific Thing @@ -16,7 +16,7 @@ abstract class WP_UnitTest_Factory_For_Thing { * can be generators -- an object with next() method. There are some default generators: {@link WP_UnitTest_Generator_Sequence}, * {@link WP_UnitTest_Generator_Locale_Name}, {@link WP_UnitTest_Factory_Callback_After_Create}. */ - function __construct( $factory, $default_generation_definitions = array() ) { + public function __construct( $factory, $default_generation_definitions = array() ) { $this->factory = $factory; $this->default_generation_definitions = $default_generation_definitions; } @@ -28,7 +28,7 @@ abstract class WP_UnitTest_Factory_For_Thing { * * @return mixed The result. Can be anything. */ - abstract function create_object( $args ); + abstract public function create_object( $args ); /** * Updates an existing object. @@ -38,7 +38,7 @@ abstract class WP_UnitTest_Factory_For_Thing { * * @return mixed The result. Can be anything. */ - abstract function update_object( $object, $fields ); + abstract public function update_object( $object, $fields ); /** * Creates an object. @@ -48,7 +48,7 @@ abstract class WP_UnitTest_Factory_For_Thing { * * @return mixed The result. Can be anything. */ - function create( $args = array(), $generation_definitions = null ) { + public function create( $args = array(), $generation_definitions = null ) { if ( is_null( $generation_definitions ) ) { $generation_definitions = $this->default_generation_definitions; } @@ -77,7 +77,7 @@ abstract class WP_UnitTest_Factory_For_Thing { * * @return mixed The created object. Can be anything. */ - function create_and_get( $args = array(), $generation_definitions = null ) { + public function create_and_get( $args = array(), $generation_definitions = null ) { $object_id = $this->create( $args, $generation_definitions ); return $this->get_object_by_id( $object_id ); } @@ -89,7 +89,7 @@ abstract class WP_UnitTest_Factory_For_Thing { * * @return mixed The object. Can be anything. */ - abstract function get_object_by_id( $object_id ); + abstract public function get_object_by_id( $object_id ); /** * Creates multiple objects. @@ -100,7 +100,7 @@ abstract class WP_UnitTest_Factory_For_Thing { * * @return array */ - function create_many( $count, $args = array(), $generation_definitions = null ) { + public function create_many( $count, $args = array(), $generation_definitions = null ) { $results = array(); for ( $i = 0; $i < $count; $i++ ) { $results[] = $this->create( $args, $generation_definitions ); @@ -118,7 +118,7 @@ abstract class WP_UnitTest_Factory_For_Thing { * * @return array|WP_Error Combined array on success. WP_Error when default value is incorrent. */ - function generate_args( $args = array(), $generation_definitions = null, &$callbacks = null ) { + public function generate_args( $args = array(), $generation_definitions = null, &$callbacks = null ) { $callbacks = array(); if ( is_null( $generation_definitions ) ) { $generation_definitions = $this->default_generation_definitions; @@ -155,7 +155,7 @@ abstract class WP_UnitTest_Factory_For_Thing { * * @return array The altered fields. */ - function apply_callbacks( $callbacks, $created ) { + public function apply_callbacks( $callbacks, $created ) { $updated_fields = array(); foreach ( $callbacks as $field_name => $generator ) { @@ -171,7 +171,7 @@ abstract class WP_UnitTest_Factory_For_Thing { * * @return WP_UnitTest_Factory_Callback_After_Create */ - function callback( $function ) { + public function callback( $function ) { return new WP_UnitTest_Factory_Callback_After_Create( $function ); } @@ -182,7 +182,7 @@ abstract class WP_UnitTest_Factory_For_Thing { * * @return array|string The value with the possibly applied slashes. */ - function addslashes_deep( $value ) { + public function addslashes_deep( $value ) { if ( is_array( $value ) ) { $value = array_map( array( $this, 'addslashes_deep' ), $value ); } elseif ( is_object( $value ) ) { diff --git a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-user.php b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-user.php index 2b32a33c09..3a22ba08d7 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-factory-for-user.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-factory-for-user.php @@ -12,7 +12,7 @@ */ class WP_UnitTest_Factory_For_User extends WP_UnitTest_Factory_For_Thing { - function __construct( $factory = null ) { + public function __construct( $factory = null ) { parent::__construct( $factory ); $this->default_generation_definitions = array( 'user_login' => new WP_UnitTest_Generator_Sequence( 'User %s' ), @@ -28,7 +28,7 @@ class WP_UnitTest_Factory_For_User extends WP_UnitTest_Factory_For_Thing { * * @return int|WP_Error */ - function create_object( $args ) { + public function create_object( $args ) { return wp_insert_user( $args ); } @@ -40,7 +40,7 @@ class WP_UnitTest_Factory_For_User extends WP_UnitTest_Factory_For_Thing { * * @return int|WP_Error User id on success. WP_Error on failure. */ - function update_object( $user_id, $fields ) { + public function update_object( $user_id, $fields ) { $fields['ID'] = $user_id; return wp_update_user( $fields ); } @@ -52,7 +52,7 @@ class WP_UnitTest_Factory_For_User extends WP_UnitTest_Factory_For_Thing { * * @return WP_User The user. */ - function get_object_by_id( $user_id ) { + public function get_object_by_id( $user_id ) { return new WP_User( $user_id ); } } diff --git a/tests/phpunit/includes/factory/class-wp-unittest-factory.php b/tests/phpunit/includes/factory/class-wp-unittest-factory.php index 268013d899..3b74092e62 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-factory.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-factory.php @@ -58,7 +58,7 @@ class WP_UnitTest_Factory { */ public $network; - function __construct() { + public function __construct() { $this->post = new WP_UnitTest_Factory_For_Post( $this ); $this->attachment = new WP_UnitTest_Factory_For_Attachment( $this ); $this->comment = new WP_UnitTest_Factory_For_Comment( $this ); diff --git a/tests/phpunit/includes/factory/class-wp-unittest-generator-sequence.php b/tests/phpunit/includes/factory/class-wp-unittest-generator-sequence.php index 5323c610d1..5c0778f3d4 100644 --- a/tests/phpunit/includes/factory/class-wp-unittest-generator-sequence.php +++ b/tests/phpunit/includes/factory/class-wp-unittest-generator-sequence.php @@ -5,7 +5,7 @@ class WP_UnitTest_Generator_Sequence { public $next; public $template_string; - function __construct( $template_string = '%s', $start = null ) { + public function __construct( $template_string = '%s', $start = null ) { if ( $start ) { $this->next = $start; } else { @@ -15,7 +15,7 @@ class WP_UnitTest_Generator_Sequence { $this->template_string = $template_string; } - function next() { + public function next() { $generated = sprintf( $this->template_string, $this->next ); $this->next++; return $generated;