File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -176,7 +176,7 @@ Feature: Profile the template render stage
176176 Scenario : Admin URL runs as a backend request and skips frontend stages
177177 Given a WP install
178178
179- When I run `wp profile stage --url=example.com/wp-admin/ --fields=stage`
179+ When I run `wp profile stage --url=example.com/wp-admin/ --context=admin -- fields=stage`
180180 Then STDOUT should be a table containing rows:
181181 | stage |
182182 | bootstrap |
@@ -189,3 +189,14 @@ Feature: Profile the template render stage
189189 template
190190 """
191191 And STDERR should be empty
192+
193+ @require-wp-4.0
194+ Scenario : Admin URL without --context=admin emits an error
195+ Given a WP install
196+
197+ When I try `wp profile stage --url=example.com/wp-admin/ --fields=stage`
198+ Then STDERR should contain:
199+ """
200+ Profiling an admin URL requires --context=admin.
201+ """
202+ And the return code should be 1
Original file line number Diff line number Diff line change @@ -82,6 +82,10 @@ public function run() {
8282 $ url = WP_CLI ::get_runner ()->config ['url ' ];
8383 $ this ->is_admin_request = ! empty ( $ url ) && (bool ) preg_match ( '#/wp-admin(/|$)#i ' , $ url );
8484
85+ if ( $ this ->is_admin_request && 'admin ' !== WP_CLI ::get_runner ()->config ['context ' ] ) {
86+ WP_CLI ::error ( 'Profiling an admin URL requires --context=admin. ' );
87+ }
88+
8589 WP_CLI ::add_wp_hook (
8690 'muplugins_loaded ' ,
8791 function () {
You can’t perform that action at this time.
0 commit comments