Fix bottom of the table when there aren't any items displayed

The cells need to be filled in appropriately
This commit is contained in:
Daniel Bachhuber 2016-09-08 06:15:10 -07:00
parent e0af87e156
commit a789b3ce34
2 changed files with 15 additions and 4 deletions

View file

@ -28,3 +28,12 @@ Feature: Basic profile usage
""" """
Error: 'SAVEQUERIES' is defined as false, and must be true. Please check your wp-config.php Error: 'SAVEQUERIES' is defined as false, and must be true. Please check your wp-config.php
""" """
Scenario: Profile a hook without any callbacks
Given a WP install
When I run `wp profile --hook=setup_theme --fields=callback,time`
Then STDOUT should be a table containing rows:
| callback | time |
| total | |
And STDERR should be empty

View file

@ -60,16 +60,15 @@ class Formatter {
$table->setHeaders( $fields ); $table->setHeaders( $fields );
$totals = array( $totals = array_fill( 0, count( $fields ), null );
'total', $totals[0] = 'total';
);
foreach ( $items as $item ) { foreach ( $items as $item ) {
$values = array_values( \WP_CLI\Utils\pick_fields( $item, $fields ) ); $values = array_values( \WP_CLI\Utils\pick_fields( $item, $fields ) );
foreach( $values as $i => $value ) { foreach( $values as $i => $value ) {
if ( 0 === $i ) { if ( 0 === $i ) {
continue; continue;
} }
if ( ! isset( $totals[ $i ] ) ) { if ( null === $totals[ $i ] ) {
if ( stripos( $fields[ $i ], '_ratio' ) ) { if ( stripos( $fields[ $i ], '_ratio' ) ) {
$totals[ $i ] = array(); $totals[ $i ] = array();
} else { } else {
@ -90,6 +89,9 @@ class Formatter {
$table->addRow( $values ); $table->addRow( $values );
} }
foreach( $totals as $i => $value ) { foreach( $totals as $i => $value ) {
if ( null === $value ) {
continue;
}
if ( stripos( $fields[ $i ], '_time' ) || 'time' === $fields[ $i ] ) { if ( stripos( $fields[ $i ], '_time' ) || 'time' === $fields[ $i ] ) {
$totals[ $i ] = round( $value, 4 ) . 's'; $totals[ $i ] = round( $value, 4 ) . 's';
} }