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
This commit is contained in:
Sergey Biryukov 2019-03-15 12:15:08 +00:00
parent 981ed3fbc6
commit 1bfa9370f7
11 changed files with 48 additions and 48 deletions

View File

@ -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 );
}
}

View File

@ -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 );

View File

@ -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 );
}
}

View File

@ -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 );
}
}

View File

@ -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 );
}
}

View File

@ -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 );
}
}

View File

@ -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 );
}
}

View File

@ -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 ) ) {

View File

@ -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 );
}
}

View File

@ -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 );

View File

@ -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;