11Feature : Profile a specific hook
22
3- @require-wp-4.0
43 Scenario : Profile all hooks when a specific hook isn't specified
54 Given a WP install
65
@@ -20,21 +19,6 @@ Feature: Profile a specific hook
2019 | callback | cache_hits | cache_misses |
2120 | sanitize_comment_cookies () | 0 | 0 |
2221
23- @less-than-php-7 @require-wp-4.0
24- Scenario : Profile an intermediate stage hook
25- Given a WP install
26-
27- When I run `wp profile hook wp_head:before --fields=callback,cache_hits,cache_misses`
28- Then STDOUT should be a table containing rows:
29- | callback | cache_hits | cache_misses |
30- | parse_blocks () | 0 | 0 |
31- | _get_wptexturize_split_regex () | 0 | 0 |
32- And STDOUT should not contain:
33- """
34- WP_CLI\Profile\Profiler->wp_tick_profile_begin()
35- """
36-
37- @require-wp-4.0
3822 Scenario : Profile a hook before the template is loaded
3923 Given a WP install
4024
@@ -43,7 +27,6 @@ Feature: Profile a specific hook
4327 | callback |
4428 And STDERR should be empty
4529
46- @require-wp-4.0
4730 Scenario : Profile a hook without any callbacks
4831 Given a WP install
4932
@@ -65,7 +48,7 @@ Feature: Profile a specific hook
6548 <meta name="generator"
6649 """
6750
68- @require-wp-4.0 @ less-than-wp-6.9
51+ @less-than-wp-6.9
6952 Scenario : Profile the shutdown hook
7053 Given a WP install
7154 And a wp-content/mu-plugins/shutdown.php file:
@@ -107,7 +90,6 @@ Feature: Profile a specific hook
10790 | total (3 ) | 0 | 1 |
10891 And STDERR should be empty
10992
110- @require-wp-4.0
11193 Scenario : Indicate where a callback is defined with profiling a hook
11294 Given a WP install
11395 And a wp-content/mu-plugins/custom-action.php file:
@@ -127,63 +109,67 @@ Feature: Profile a specific hook
127109 | total (1 ) | | 0 | 1 |
128110 And STDERR should be empty
129111
130- Scenario : Hooks should only be called once
112+ Scenario : Search for callbacks by name pattern on a specific hook
131113 Given a WP install
132- And a wp-content/mu-plugins/action -test.php file:
114+ And a wp-content/mu-plugins/search -test.php file:
133115 """
134116 <?php
135- add_action( 'init', function(){
136- static $i;
137- if ( ! isset( $i ) ) {
138- $i = 0;
139- }
140- $i++;
141- WP_CLI::warning( 'Called ' . $i );
142- });
117+ function wp_cli_search_hook_one() {}
118+ function wp_cli_search_hook_two() {}
119+ function unrelated_callback() {}
120+ add_action( 'init', 'wp_cli_search_hook_one' );
121+ add_action( 'init', 'wp_cli_search_hook_two' );
122+ add_action( 'init', 'unrelated_callback' );
143123 """
144124
145- When I try `wp profile hook init`
146- Then STDERR should be :
125+ When I run `wp profile hook init --fields=callback --search=wp_cli_search_hook `
126+ Then STDOUT should contain :
147127 """
148- Warning: Called 1
128+ wp_cli_search_hook_one()
149129 """
150-
151- @less-than-php-7 @require-wp-4.0
152- Scenario : Profile the mu_plugins:before hook
153- Given a WP install
154- And a wp-content/mu-plugins/awesome-file.php file:
130+ And STDOUT should contain:
155131 """
156- <?php
157- function awesome_func() {
158- // does nothing
159- }
160- awesome_func();
132+ wp_cli_search_hook_two()
161133 """
162-
163- When I run `wp profile hook muplugins_loaded:before --fields=callback`
164- Then STDOUT should contain:
134+ And STDOUT should not contain:
165135 """
166- wp-content/mu-plugins/awesome-file.php
136+ unrelated_callback()
167137 """
138+ And STDERR should be empty
168139
169- @less-than-php-7 @require-wp-4.0
170- Scenario : Profile the :after hooks
140+ Scenario : Search for callbacks by name pattern across all hooks
171141 Given a WP install
142+ And a wp-content/mu-plugins/search-all-test.php file:
143+ """
144+ <?php
145+ function wp_cli_search_all_hook() {}
146+ add_action( 'init', 'wp_cli_search_all_hook' );
147+ """
172148
173- When I run `wp profile hook wp_loaded:after `
149+ When I run `wp profile hook --all --fields=callback --search=wp_cli_search_all_hook `
174150 Then STDOUT should contain:
175151 """
176- do_action ()
152+ wp_cli_search_all_hook ()
177153 """
154+ And STDERR should be empty
178155
179- When I run `wp profile hook wp:after`
180- Then STDOUT should contain:
156+ Scenario : Hooks should only be called once
157+ Given a WP install
158+ And a wp-content/mu-plugins/action-test.php file:
181159 """
182- do_action_ref_array()
160+ <?php
161+ add_action( 'init', function(){
162+ static $i;
163+ if ( ! isset( $i ) ) {
164+ $i = 0;
165+ }
166+ $i++;
167+ WP_CLI::warning( 'Called ' . $i );
168+ });
183169 """
184170
185- When I run `wp profile hook wp_footer:after `
186- Then STDOUT should contain :
171+ When I try `wp profile hook init `
172+ Then STDERR should be :
187173 """
188- do_action()
174+ Warning: Called 1
189175 """
0 commit comments