Skip to content

Commit 01ea3f4

Browse files
committed
Fixed errors from Behat. Modified the default unit on test.
1 parent f777f32 commit 01ea3f4

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

features/db-size.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Feature: Display database size
1313

1414
And STDOUT should contain:
1515
"""
16-
KB
16+
B
1717
"""
1818

1919
Scenario: Display only table sizes for a WordPress install
@@ -22,7 +22,7 @@ Feature: Display database size
2222
When I run `wp db size --tables`
2323
Then STDOUT should contain:
2424
"""
25-
wp_posts 80 KB
25+
wp_posts 81920 B
2626
"""
2727

2828
But STDOUT should not contain:

src/DB_Command.php

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,8 @@ public function size( $args, $assoc_args ) {
596596
$rows = array();
597597
$fields = array( 'Name', 'Size' );
598598

599+
$default_unit = ( empty( $size_format ) ) ? ' B' : '';
600+
599601
if ( $tables ) {
600602

601603
// Add all of the table sizes
@@ -612,7 +614,7 @@ public function size( $args, $assoc_args ) {
612614
// Add the table size to the list.
613615
$rows[] = array(
614616
'Name' => $table_name,
615-
'Size' => strtoupper( $table_bytes ) . " " . 'B',
617+
'Size' => strtoupper( $table_bytes ) . $default_unit,
616618
);
617619
}
618620
} else {
@@ -627,7 +629,7 @@ public function size( $args, $assoc_args ) {
627629
// Add the database size to the list.
628630
$rows[] = array(
629631
'Name' => DB_NAME,
630-
'Size' => strtoupper( $db_bytes ) . " " . 'B',
632+
'Size' => strtoupper( $db_bytes ) . $default_unit,
631633
);
632634
}
633635

@@ -657,17 +659,21 @@ public function size( $args, $assoc_args ) {
657659
break;
658660
}
659661

660-
$rows[ $index ]['Size'] = $row['Size'] / $divisor . " " . ucfirst( $size_format );
662+
$rows[ $index ]['Size'] = ceil( $row['Size'] / $divisor ) . " " . strtoupper( $size_format );
661663
}
662664
}
663665

664-
// Display the rows.
665-
$args = array(
666-
'format' => $format,
667-
);
666+
if ( ! empty( $size_format) && ! $tables ) {
667+
WP_CLI::Line( filter_var( $rows[0]['Size'], FILTER_SANITIZE_NUMBER_INT ) );
668+
} else {
669+
// Display the rows.
670+
$args = array(
671+
'format' => $format,
672+
);
668673

669-
$formatter = new \WP_CLI\Formatter( $args, $fields );
670-
$formatter->display_items( $rows );
674+
$formatter = new \WP_CLI\Formatter( $args, $fields );
675+
$formatter->display_items( $rows );
676+
}
671677
}
672678

673679
/**

0 commit comments

Comments
 (0)