mirror of
https://hk.gh-proxy.com/https://github.com/wp-cli/profile-command.git
synced 2025-08-21 06:39:02 +08:00
Use an explicit flag to indicate when the total should be displayed
This commit is contained in:
parent
53cb6b8c10
commit
60ae6e4490
5 changed files with 15 additions and 15 deletions
|
@ -48,7 +48,7 @@ Feature: Profile a specific hook
|
|||
When I run `wp profile hook setup_theme --fields=callback`
|
||||
Then STDOUT should be a table containing rows:
|
||||
| callback |
|
||||
| total |
|
||||
| total (0) |
|
||||
And STDERR should be empty
|
||||
|
||||
Scenario: Profile a hook that has actions with output
|
||||
|
@ -78,7 +78,7 @@ Feature: Profile a specific hook
|
|||
| callback | cache_hits | cache_misses |
|
||||
| runcommand_shutdown_hook() | 0 | 1 |
|
||||
| wp_ob_end_flush_all() | 0 | 0 |
|
||||
| total | 0 | 1 |
|
||||
| total (2) | 0 | 1 |
|
||||
And STDERR should be empty
|
||||
|
||||
Scenario: Indicate where a callback is defined with profiling a hook
|
||||
|
@ -97,7 +97,7 @@ Feature: Profile a specific hook
|
|||
Then STDOUT should be a table containing rows:
|
||||
| callback | location | cache_hits | cache_misses |
|
||||
| runcommand_custom_action_hook() | mu-plugins/custom-action.php:2 | 0 | 1 |
|
||||
| total | | 0 | 1 |
|
||||
| total (1) | | 0 | 1 |
|
||||
And STDERR should be empty
|
||||
|
||||
Scenario: Hooks should only be called once
|
||||
|
|
|
@ -29,7 +29,7 @@ Feature: Profile the template render stage
|
|||
| wp_loaded:before |
|
||||
| wp_loaded |
|
||||
| wp_loaded:after |
|
||||
| total |
|
||||
| total (13) |
|
||||
|
||||
When I run `wp profile stage main_query --fields=hook`
|
||||
Then STDOUT should be a table containing rows:
|
||||
|
@ -45,7 +45,7 @@ Feature: Profile the template render stage
|
|||
| wp:before |
|
||||
| wp |
|
||||
| wp:after |
|
||||
| total |
|
||||
| total (11) |
|
||||
|
||||
When I run `wp profile stage template --fields=hook`
|
||||
Then STDOUT should be a table containing rows:
|
||||
|
@ -63,7 +63,7 @@ Feature: Profile the template render stage
|
|||
| wp_footer:before |
|
||||
| wp_footer |
|
||||
| wp_footer:after |
|
||||
| total |
|
||||
| total (13) |
|
||||
|
||||
Scenario: Use --all flag to profile all stages
|
||||
Given a WP install
|
||||
|
@ -106,7 +106,7 @@ Feature: Profile the template render stage
|
|||
| wp_footer:before |
|
||||
| wp_footer |
|
||||
| wp_footer:after |
|
||||
| total |
|
||||
| total (35) |
|
||||
|
||||
Scenario: Invalid stage specified
|
||||
Given a WP install
|
||||
|
|
|
@ -39,7 +39,7 @@ Feature: Basic profile usage
|
|||
When I run `wp profile hook setup_theme --fields=callback,time`
|
||||
Then STDOUT should be a table containing rows:
|
||||
| callback | time |
|
||||
| total | |
|
||||
| total (0) | |
|
||||
And STDERR should be empty
|
||||
|
||||
Scenario: Trailingslash provided URL to avoid canonical redirect
|
||||
|
@ -49,7 +49,7 @@ Feature: Basic profile usage
|
|||
Then STDERR should be empty
|
||||
And STDOUT should be a table containing rows:
|
||||
| callback | time |
|
||||
| total | |
|
||||
| total (0) | |
|
||||
|
||||
Scenario: Don't include 'total' cell when the name column is omitted
|
||||
Given a WP install
|
||||
|
|
|
@ -218,7 +218,7 @@ class Command {
|
|||
'request_count',
|
||||
);
|
||||
$formatter = new Formatter( $assoc_args, $fields );
|
||||
$formatter->display_items( array( $logger ) );
|
||||
$formatter->display_items( array( $logger ), false );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -276,7 +276,7 @@ class Command {
|
|||
'request_count',
|
||||
);
|
||||
$formatter = new Formatter( $assoc_args, $fields );
|
||||
$formatter->display_items( array( $logger ) );
|
||||
$formatter->display_items( array( $logger ), false );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,9 +42,9 @@ class Formatter {
|
|||
*
|
||||
* @param array $items
|
||||
*/
|
||||
public function display_items( $items ) {
|
||||
public function display_items( $items, $include_total = true ) {
|
||||
if ( 'table' === $this->args['format'] && empty( $this->args['field'] ) ) {
|
||||
$this->show_table( $items, $this->args['fields'] );
|
||||
$this->show_table( $items, $this->args['fields'], $include_total );
|
||||
} else {
|
||||
$this->formatter->display_items( $items );
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class Formatter {
|
|||
* @param array $items
|
||||
* @param array $fields
|
||||
*/
|
||||
private function show_table( $items, $fields ) {
|
||||
private function show_table( $items, $fields, $include_total ) {
|
||||
$table = new \cli\Table();
|
||||
|
||||
$enabled = \cli\Colors::shouldColorize();
|
||||
|
@ -103,7 +103,7 @@ class Formatter {
|
|||
}
|
||||
$table->addRow( $values );
|
||||
}
|
||||
if ( count( $items ) > 1 ) {
|
||||
if ( $include_total ) {
|
||||
foreach( $totals as $i => $value ) {
|
||||
if ( null === $value ) {
|
||||
continue;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue