Compare commits

..

No commits in common. "64c64266804489f8b31229a9d7fb57fefc8c6ba8" and "8418ad2d970dc069d5cd57f54762db6989669c4c" have entirely different histories.

2 changed files with 14 additions and 33 deletions

View file

@ -2,37 +2,23 @@ Feature: Profile HTTP requests

Scenario: Profile HTTP requests during WordPress load
Given a WP install
And that HTTP requests to https://www.apple.com/ will respond with:
"""
HTTP/1.1 200
Content-Type: text/plain

Hello world
When I run `wp profile requests --fields=method,url,status,time`
Then STDOUT should contain:
"""
And that HTTP requests to https://www.example.com/ will respond with:
method
"""
HTTP/1.1 201
Content-Type: application/json

{"status":"created"}
"""
And a wp-content/mu-plugins/http-requests.php file:
"""
<?php
add_action( 'muplugins_loaded', function() {
wp_remote_get( 'https://www.apple.com/' );
wp_remote_post( 'https://www.example.com/', array( 'body' => 'test' ) );
});
"""

When I run `wp profile requests --fields=method,url`
Then STDOUT should be a table containing rows:
| method | url |
| GET | https://www.apple.com/ |
| POST | https://www.example.com/ |
And STDOUT should contain:
"""
total (2)
url
"""
And STDOUT should contain:
"""
status
"""
And STDOUT should contain:
"""
time
"""

Scenario: Profile shows no requests when none are made

View file

@ -391,15 +391,10 @@ class Profiler {

// For request profiling, capture details of each HTTP request
if ( 'request' === $this->type ) {
// Reset properties first to handle cases where previous request was preempted
$this->request_start_time = null;
$this->request_args = null;

// Now capture the new request details
$this->request_start_time = microtime( true );
$this->request_args = array(
'url' => $url,
'method' => ( is_array( $parsed_args ) && isset( $parsed_args['method'] ) ) ? $parsed_args['method'] : 'GET',
'method' => isset( $parsed_args['method'] ) ? $parsed_args['method'] : 'GET',
);
}

@ -426,7 +421,7 @@ class Profiler {
$status = $response['response']['code'];
}

$logger = new Logger(
$logger = new Logger(
array(
'method' => $this->request_args['method'],
'url' => $this->request_args['url'],