2016-09-08 05:43:42 -07:00
|
|
|
Feature: Profile a specific hook
|
|
|
|
|
2021-04-19 17:28:42 +01:00
|
|
|
@require-wp-4.0
|
2016-10-08 07:27:46 -07:00
|
|
|
Scenario: Profile all hooks when a specific hook isn't specified
|
|
|
|
Given a WP install
|
|
|
|
|
2018-08-21 18:52:40 +02:00
|
|
|
When I run `wp profile hook --fields=hook`
|
2016-10-08 07:27:46 -07:00
|
|
|
Then STDOUT should be a table containing rows:
|
2018-08-21 18:52:40 +02:00
|
|
|
| hook |
|
|
|
|
| plugins_loaded |
|
|
|
|
| init |
|
|
|
|
| template_redirect |
|
2016-10-08 07:27:46 -07:00
|
|
|
And STDERR should be empty
|
|
|
|
|
2021-04-19 17:28:42 +01:00
|
|
|
@require-wp-4.4
|
2016-10-08 16:18:48 -07:00
|
|
|
Scenario: Profile all callbacks when --all flag is used
|
|
|
|
Given a WP install
|
|
|
|
|
|
|
|
When I run `wp profile hook --all --fields=callback,cache_hits,cache_misses`
|
|
|
|
Then STDOUT should be a table containing rows:
|
2022-01-06 17:41:31 -06:00
|
|
|
| callback | cache_hits | cache_misses |
|
|
|
|
| sanitize_comment_cookies() | 0 | 0 |
|
2016-10-08 16:18:48 -07:00
|
|
|
|
2021-04-19 17:28:42 +01:00
|
|
|
@less-than-php-7 @require-wp-4.0
|
2016-10-09 15:43:02 -07:00
|
|
|
Scenario: Profile an intermediate stage hook
|
|
|
|
Given a WP install
|
|
|
|
|
|
|
|
When I run `wp profile hook wp_head:before --fields=callback,cache_hits,cache_misses`
|
|
|
|
Then STDOUT should be a table containing rows:
|
2022-01-06 17:41:31 -06:00
|
|
|
| callback | cache_hits | cache_misses |
|
|
|
|
| parse_blocks() | 0 | 0 |
|
|
|
|
| _get_wptexturize_split_regex() | 0 | 0 |
|
2016-10-09 16:15:16 -07:00
|
|
|
And STDOUT should not contain:
|
|
|
|
"""
|
2021-04-19 17:48:21 +01:00
|
|
|
WP_CLI\Profile\Profiler->wp_tick_profile_begin()
|
2016-10-09 16:15:16 -07:00
|
|
|
"""
|
2016-10-09 15:43:02 -07:00
|
|
|
|
2021-04-19 17:28:42 +01:00
|
|
|
@require-wp-4.0
|
2016-09-23 06:33:30 -07:00
|
|
|
Scenario: Profile a hook before the template is loaded
|
|
|
|
Given a WP install
|
|
|
|
|
2016-10-04 06:47:01 -07:00
|
|
|
When I run `wp profile hook plugins_loaded --fields=callback`
|
2016-09-23 06:33:30 -07:00
|
|
|
Then STDOUT should be a table containing rows:
|
|
|
|
| callback |
|
|
|
|
And STDERR should be empty
|
|
|
|
|
2021-04-19 17:28:42 +01:00
|
|
|
@require-wp-4.0
|
2016-09-08 05:43:42 -07:00
|
|
|
Scenario: Profile a hook without any callbacks
|
|
|
|
Given a WP install
|
|
|
|
|
2020-11-13 09:09:39 +01:00
|
|
|
When I run `wp profile hook get_search_form --fields=callback`
|
2016-09-08 05:49:18 -07:00
|
|
|
Then STDOUT should be a table containing rows:
|
|
|
|
| callback |
|
2016-10-26 06:38:17 -07:00
|
|
|
| total (0) |
|
2016-09-08 05:43:42 -07:00
|
|
|
And STDERR should be empty
|
2016-09-08 06:02:48 -07:00
|
|
|
|
2021-04-19 17:28:42 +01:00
|
|
|
@require-wp-4.0
|
2016-09-08 06:02:48 -07:00
|
|
|
Scenario: Profile a hook that has actions with output
|
|
|
|
Given a WP install
|
|
|
|
|
2016-10-04 06:47:01 -07:00
|
|
|
When I run `wp profile hook wp_head --fields=callback`
|
2016-09-08 06:02:48 -07:00
|
|
|
Then STDOUT should be a table containing rows:
|
|
|
|
| callback |
|
|
|
|
And STDOUT should not contain:
|
|
|
|
"""
|
|
|
|
<meta name="generator"
|
|
|
|
"""
|
2016-10-04 14:10:27 -07:00
|
|
|
|
2021-04-19 17:28:42 +01:00
|
|
|
@require-wp-4.0
|
2016-10-04 14:10:27 -07:00
|
|
|
Scenario: Profile the shutdown hook
|
|
|
|
Given a WP install
|
|
|
|
And a wp-content/mu-plugins/shutdown.php file:
|
|
|
|
"""
|
|
|
|
<?php
|
2021-04-19 17:48:21 +01:00
|
|
|
function wp_cli_shutdown_hook() {
|
2016-10-04 14:10:27 -07:00
|
|
|
wp_cache_get( 'foo' );
|
|
|
|
}
|
2021-04-19 17:48:21 +01:00
|
|
|
add_action( 'shutdown', 'wp_cli_shutdown_hook' );
|
2016-10-04 14:10:27 -07:00
|
|
|
"""
|
|
|
|
|
|
|
|
When I run `wp profile hook shutdown --fields=callback,cache_hits,cache_misses`
|
|
|
|
Then STDOUT should be a table containing rows:
|
2021-04-19 17:48:21 +01:00
|
|
|
| callback | cache_hits | cache_misses |
|
|
|
|
| wp_cli_shutdown_hook() | 0 | 1 |
|
|
|
|
| wp_ob_end_flush_all() | 0 | 0 |
|
|
|
|
| total (2) | 0 | 1 |
|
2016-10-07 15:27:29 -07:00
|
|
|
And STDERR should be empty
|
2016-10-07 14:20:08 -07:00
|
|
|
|
2021-04-19 17:28:42 +01:00
|
|
|
@require-wp-4.0
|
2016-10-07 14:20:08 -07:00
|
|
|
Scenario: Indicate where a callback is defined with profiling a hook
|
|
|
|
Given a WP install
|
|
|
|
And a wp-content/mu-plugins/custom-action.php file:
|
|
|
|
"""
|
|
|
|
<?php
|
2021-04-19 17:48:21 +01:00
|
|
|
function wp_cli_custom_action_hook() {
|
2016-10-07 14:20:08 -07:00
|
|
|
wp_cache_get( 'foo' );
|
|
|
|
}
|
2021-04-19 17:48:21 +01:00
|
|
|
add_action( 'wp_cli_custom_action', 'wp_cli_custom_action_hook' );
|
|
|
|
do_action( 'wp_cli_custom_action' );
|
2016-10-07 14:20:08 -07:00
|
|
|
"""
|
|
|
|
|
2021-04-19 17:48:21 +01:00
|
|
|
When I run `wp profile hook wp_cli_custom_action --fields=callback,location,cache_hits,cache_misses`
|
2016-10-07 14:20:08 -07:00
|
|
|
Then STDOUT should be a table containing rows:
|
2021-04-19 17:48:21 +01:00
|
|
|
| callback | location | cache_hits | cache_misses |
|
|
|
|
| wp_cli_custom_action_hook() | mu-plugins/custom-action.php:2 | 0 | 1 |
|
|
|
|
| total (1) | | 0 | 1 |
|
2016-10-07 15:27:29 -07:00
|
|
|
And STDERR should be empty
|
2016-10-07 14:45:13 -07:00
|
|
|
|
2021-04-19 17:28:42 +01:00
|
|
|
@require-wp-4.4
|
2016-10-07 14:45:13 -07:00
|
|
|
Scenario: Hooks should only be called once
|
|
|
|
Given a WP install
|
|
|
|
And a wp-content/mu-plugins/action-test.php file:
|
|
|
|
"""
|
|
|
|
<?php
|
|
|
|
add_action( 'init', function(){
|
|
|
|
static $i;
|
|
|
|
if ( ! isset( $i ) ) {
|
|
|
|
$i = 0;
|
|
|
|
}
|
|
|
|
$i++;
|
|
|
|
WP_CLI::warning( 'Called ' . $i );
|
|
|
|
});
|
|
|
|
"""
|
|
|
|
|
2018-08-21 18:53:54 +02:00
|
|
|
When I try `wp profile hook init`
|
2016-10-07 14:45:13 -07:00
|
|
|
Then STDERR should be:
|
|
|
|
"""
|
|
|
|
Warning: Called 1
|
|
|
|
"""
|
2016-10-19 04:54:58 -07:00
|
|
|
|
2021-04-19 17:28:42 +01:00
|
|
|
@less-than-php-7 @require-wp-4.0
|
2016-10-19 04:54:58 -07:00
|
|
|
Scenario: Profile the mu_plugins:before hook
|
|
|
|
Given a WP install
|
|
|
|
And a wp-content/mu-plugins/awesome-file.php file:
|
|
|
|
"""
|
|
|
|
<?php
|
|
|
|
function awesome_func() {
|
|
|
|
// does nothing
|
|
|
|
}
|
|
|
|
awesome_func();
|
|
|
|
"""
|
|
|
|
|
|
|
|
When I run `wp profile hook muplugins_loaded:before --fields=callback`
|
|
|
|
Then STDOUT should contain:
|
|
|
|
"""
|
|
|
|
wp-content/mu-plugins/awesome-file.php
|
|
|
|
"""
|
2016-10-26 06:54:43 -07:00
|
|
|
|
2021-04-19 17:28:42 +01:00
|
|
|
@less-than-php-7 @require-wp-4.0
|
2016-10-26 06:54:43 -07:00
|
|
|
Scenario: Profile the :after hooks
|
|
|
|
Given a WP install
|
|
|
|
|
|
|
|
When I run `wp profile hook wp_loaded:after`
|
|
|
|
Then STDOUT should contain:
|
|
|
|
"""
|
|
|
|
do_action()
|
|
|
|
"""
|
|
|
|
|
|
|
|
When I run `wp profile hook wp:after`
|
|
|
|
Then STDOUT should contain:
|
|
|
|
"""
|
|
|
|
do_action_ref_array()
|
|
|
|
"""
|
|
|
|
|
|
|
|
When I run `wp profile hook wp_footer:after`
|
|
|
|
Then STDOUT should contain:
|
|
|
|
"""
|
|
|
|
do_action()
|
|
|
|
"""
|