mirror of
https://hk.gh-proxy.com/https://github.com/wp-cli/profile-command.git
synced 2025-08-21 06:39:01 +08:00
Merge pull request #71 from runcommand/fill-total-row
Fix bottom of the table when there aren't any items displayed
This commit is contained in:
commit
3a0b093984
2 changed files with 15 additions and 4 deletions
|
@ -28,3 +28,12 @@ Feature: Basic profile usage
|
|||
"""
|
||||
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
|
||||
|
|
|
@ -60,16 +60,15 @@ class Formatter {
|
|||
|
||||
$table->setHeaders( $fields );
|
||||
|
||||
$totals = array(
|
||||
'total',
|
||||
);
|
||||
$totals = array_fill( 0, count( $fields ), null );
|
||||
$totals[0] = 'total';
|
||||
foreach ( $items as $item ) {
|
||||
$values = array_values( \WP_CLI\Utils\pick_fields( $item, $fields ) );
|
||||
foreach( $values as $i => $value ) {
|
||||
if ( 0 === $i ) {
|
||||
continue;
|
||||
}
|
||||
if ( ! isset( $totals[ $i ] ) ) {
|
||||
if ( null === $totals[ $i ] ) {
|
||||
if ( stripos( $fields[ $i ], '_ratio' ) ) {
|
||||
$totals[ $i ] = array();
|
||||
} else {
|
||||
|
@ -90,6 +89,9 @@ class Formatter {
|
|||
$table->addRow( $values );
|
||||
}
|
||||
foreach( $totals as $i => $value ) {
|
||||
if ( null === $value ) {
|
||||
continue;
|
||||
}
|
||||
if ( stripos( $fields[ $i ], '_time' ) || 'time' === $fields[ $i ] ) {
|
||||
$totals[ $i ] = round( $value, 4 ) . 's';
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue