From 5953df52c2951f7fcc02645db3076985940f3db4 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 8 Sep 2016 05:43:42 -0700 Subject: [PATCH 1/2] Bail early when there aren't any hook callbacks to run --- features/profile-hook-feature.feature | 8 ++++++++ inc/class-command.php | 4 ++++ 2 files changed, 12 insertions(+) create mode 100644 features/profile-hook-feature.feature diff --git a/features/profile-hook-feature.feature b/features/profile-hook-feature.feature new file mode 100644 index 0000000..37fed3d --- /dev/null +++ b/features/profile-hook-feature.feature @@ -0,0 +1,8 @@ +Feature: Profile a specific hook + + Scenario: Profile a hook without any callbacks + Given a WP install + + When I run `wp profile --hook=setup_theme` + Then STDOUT should be empty + And STDERR should be empty diff --git a/inc/class-command.php b/inc/class-command.php index 1cf6d27..6afdc6f 100644 --- a/inc/class-command.php +++ b/inc/class-command.php @@ -164,6 +164,10 @@ class Command { else ++$wp_actions[$tag]; + if ( empty( $wp_filter[ $tag ] ) ) { + return; + } + if ( !isset($wp_filter['all']) ) $wp_current_filter[] = $tag; From 757b3bf38a383d2fdcb959ce6600bcb7e4ef6718 Mon Sep 17 00:00:00 2001 From: Daniel Bachhuber Date: Thu, 8 Sep 2016 05:49:18 -0700 Subject: [PATCH 2/2] Update test for true output representation --- features/profile-hook-feature.feature | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/features/profile-hook-feature.feature b/features/profile-hook-feature.feature index 37fed3d..56e5863 100644 --- a/features/profile-hook-feature.feature +++ b/features/profile-hook-feature.feature @@ -3,6 +3,8 @@ Feature: Profile a specific hook Scenario: Profile a hook without any callbacks Given a WP install - When I run `wp profile --hook=setup_theme` - Then STDOUT should be empty + When I run `wp profile --hook=setup_theme --fields=callback` + Then STDOUT should be a table containing rows: + | callback | + | total | And STDERR should be empty