Skip to content

Commit a4e1e24

Browse files
committed
Fix: Improve table existence check and test coverage
1 parent 3f3826e commit a4e1e24

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

features/core.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Feature: Manage WordPress installation
2727
"""
2828
WordPress is not installed. Missing tables:
2929
"""
30+
And STDERR should contain: wp_
3031

3132
When I try `wp core is-installed --network`
3233
Then the return code should be 1

src/Core_Command.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,17 +403,26 @@ public function is_installed( $args, $assoc_args ) {
403403
// Check if all core tables exist
404404
foreach ( $tables as $table ) {
405405
$table_name = $wpdb->prefix . $table;
406-
$result = $wpdb->get_var( $wpdb->prepare(
407-
"SHOW TABLES LIKE %s", $table_name
408-
) );
406+
$result = $wpdb->get_var(
407+
$wpdb->prepare(
408+
'SHOW TABLES LIKE %s',
409+
$table_name
410+
)
411+
);
409412

410413
if ( $result !== $table_name ) {
411414
$missing_tables[] = $table_name;
412415
}
413416
}
414417

415418
if ( ! empty( $missing_tables ) ) {
416-
WP_CLI::error( "WordPress is not installed. Missing tables: " . implode( ', ', $missing_tables ), 1 );
419+
WP_CLI::error(
420+
sprintf(
421+
'WordPress is not installed. Missing tables: %s',
422+
implode( ', ', $missing_tables )
423+
),
424+
1
425+
);
417426
}
418427

419428
WP_CLI::halt( 0 );

0 commit comments

Comments
 (0)