Make WordPress Core


Ignore:
Timestamp:
01/05/2023 10:21:19 AM (4 years ago)
Author:
SergeyBiryukov
Message:

Tests: Bring some consistency to mocking HTTP requests in unit tests.

Includes:

  • Renaming the $preempt parameter to $response in the pre_http_request filter to better match the context used in callbacks (returning the original value if the conditions are not met rather than preempting the request).
  • Synchronizing parameter names and types in various pre_http_request callbacks in unit tests.

Follow-up to [34509], [37907], [40628], [40629], [45667], [46175], [48242], [48462], [49904], [51021], [51973], [52146], [52382], [54043], [54968].

See #56793, #56792.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/admin/includesFile.php

    r52760 r55029  
    6969        }
    7070
    71         public function _fake_download_url_non_200_response_code( $response, $args, $url ) {
     71        public function _fake_download_url_non_200_response_code( $response, $parsed_args, $url ) {
    7272                file_put_contents( $args['filename'], 'This is an unexpected error message from your favorite server.' );
    7373                return array(
     
    151151         * @return array
    152152         */
    153         public function filter_content_disposition_header_with_filename( $response, $args, $url ) {
     153        public function filter_content_disposition_header_with_filename( $response, $parsed_args, $url ) {
    154154                return array(
    155155                        'response' => array(
     
    169169         * @return array
    170170         */
    171         public function filter_content_disposition_header_with_filename_with_path_traversal( $response, $args, $url ) {
     171        public function filter_content_disposition_header_with_filename_with_path_traversal( $response, $parsed_args, $url ) {
    172172                return array(
    173173                        'response' => array(
     
    187187         * @return array
    188188         */
    189         public function filter_content_disposition_header_with_filename_without_quotes( $response, $args, $url ) {
     189        public function filter_content_disposition_header_with_filename_without_quotes( $response, $parsed_args, $url ) {
    190190                return array(
    191191                        'response' => array(
     
    236236         * @return array
    237237         */
    238         public function filter_content_disposition_header_with_filename_without_context( $response, $args, $url ) {
     238        public function filter_content_disposition_header_with_filename_without_context( $response, $parsed_args, $url ) {
    239239                return array(
    240240                        'response' => array(
     
    254254         * @return array
    255255         */
    256         public function filter_content_disposition_header_with_filename_with_inline_context( $response, $args, $url ) {
     256        public function filter_content_disposition_header_with_filename_with_inline_context( $response, $parsed_args, $url ) {
    257257                return array(
    258258                        'response' => array(
     
    272272         * @return array
    273273         */
    274         public function filter_content_disposition_header_with_filename_with_form_data_context( $response, $args, $url ) {
     274        public function filter_content_disposition_header_with_filename_with_form_data_context( $response, $parsed_args, $url ) {
    275275                return array(
    276276                        'response' => array(
     
    366366         * Mock the HTTP request response.
    367367         *
    368          * @param bool   $false     False.
    369          * @param array  $arguments Request arguments.
    370          * @param string $url       Request URL.
    371          * @return array|bool
    372          */
    373         public function mock_http_request( $false, $arguments, $url ) {
     368         * @param false|array|WP_Error $response    A preemptive return value of an HTTP request. Default false.
     369         * @param array                $parsed_args HTTP request arguments.
     370         * @param string               $url         The request URL.
     371         * @return false|array|WP_Error Response data.
     372         */
     373        public function mock_http_request( $response, $parsed_args, $url ) {
    374374                if ( 'https://example.com' === $url ) {
    375375                        return array(
     
    380380                }
    381381
    382                 return $false;
     382                return $response;
    383383        }
    384384}
Note: See TracChangeset for help on using the changeset viewer.