mirror of
https://gh.wpcy.net/https://github.com/wp-cli/profile-command.git
synced 2026-04-17 14:32:21 +08:00
53 lines
1.5 KiB
Gherkin
53 lines
1.5 KiB
Gherkin
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
|
|
"""
|
|
And that HTTP requests to https://www.example.com/ will respond with:
|
|
"""
|
|
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)
|
|
"""
|
|
|
|
Scenario: Profile shows no requests when none are made
|
|
Given a WP install
|
|
And a wp-content/mu-plugins/no-requests.php file:
|
|
"""
|
|
<?php
|
|
// Don't make any HTTP requests
|
|
add_filter( 'pre_http_request', function() {
|
|
return new WP_Error( 'http_requests_disabled', 'HTTP requests are disabled during this test.' );
|
|
}, 1 );
|
|
"""
|
|
|
|
When I run `wp profile requests --fields=method,url`
|
|
Then STDOUT should contain:
|
|
"""
|
|
total (0)
|
|
"""
|