Skip to content

Commit 1105c5e

Browse files
committed
Improve some tests
1 parent 63f7865 commit 1105c5e

File tree

8 files changed

+56
-15
lines changed

8 files changed

+56
-15
lines changed

features/db-check.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ Feature: Check the database
145145
Scenario: SQLite commands that show warnings
146146
Given a WP install
147147

148-
When I run `wp db check`
149-
Then STDOUT should contain:
148+
When I try `wp db check`
149+
Then STDERR should contain:
150150
"""
151151
Warning: Database check is not supported for SQLite databases
152152
"""

features/db-cli.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ Feature: Open a MySQL console
44
Scenario: SQLite commands that show warnings for cli
55
Given a WP install
66

7-
When I run `wp db cli`
8-
Then STDOUT should contain:
7+
When I try `wp db cli`
8+
Then STDERR should contain:
99
"""
1010
Warning: Interactive console (cli) is not supported for SQLite databases
1111
"""

features/db-export.feature

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,19 @@ Feature: Export a WordPress database
2727
Then the wp_cli_test.sql file should exist
2828
And the wp_cli_test.sql file should not contain:
2929
"""
30-
wp_users
30+
CREATE TABLE wp_users
3131
"""
3232
And the wp_cli_test.sql file should contain:
3333
"""
34-
wp_options
34+
CREATE TABLE wp_options
35+
"""
36+
And the wp_cli_test.sql file should not contain:
37+
"""
38+
CREATE TABLE "wp_users"
39+
"""
40+
And the wp_cli_test.sql file should contain:
41+
"""
42+
CREATE TABLE "wp_options"
3543
"""
3644

3745
Scenario: Export database to STDOUT

features/db-optimize.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Feature: Optimize the database
1414
Scenario: SQLite commands that show warnings for optimize
1515
Given a WP install
1616

17-
When I run `wp db optimize`
18-
Then STDOUT should contain:
17+
When I try `wp db optimize`
18+
Then STDERR should contain:
1919
"""
2020
Warning: Database optimization is not supported for SQLite databases
2121
"""

features/db-repair.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ Feature: Repair the database
1414
Scenario: SQLite commands that show warnings for repair
1515
Given a WP install
1616

17-
When I run `wp db repair`
18-
Then STDOUT should contain:
17+
When I try `wp db repair`
18+
Then STDERR should contain:
1919
"""
2020
Warning: Database repair is not supported for SQLite databases
2121
"""

features/db-size.feature

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
Feature: Display database size
44

5+
@require-mysql-or-mariadb
56
Scenario: Display only database size for a WordPress install
67
Given a WP install
78

@@ -16,6 +17,21 @@ Feature: Display database size
1617
B
1718
"""
1819

20+
@require-sqlite
21+
Scenario: Display only database size for a WordPress install
22+
Given a WP install
23+
24+
When I run `wp db size`
25+
Then STDOUT should contain:
26+
"""
27+
.ht.sqlite
28+
"""
29+
30+
And STDOUT should contain:
31+
"""
32+
B
33+
"""
34+
1935
Scenario: Display only table sizes for a WordPress install
2036
Given a WP install
2137

@@ -27,6 +43,7 @@ Feature: Display database size
2743
wp_cli_test
2844
"""
2945

46+
@require-mysql-or-mariadb
3047
Scenario: Display only database size in a human readable format for a WordPress install
3148
Given a WP install
3249

@@ -49,6 +66,21 @@ Feature: Display database size
4966
"""
5067
And STDOUT should be empty
5168

69+
@require-sqlite
70+
Scenario: Display only database size in a human readable format for a WordPress install
71+
Given a WP install
72+
73+
When I run `wp db size --human-readable`
74+
Then STDOUT should contain:
75+
"""
76+
.ht.sqlite
77+
"""
78+
79+
And STDOUT should contain:
80+
"""
81+
KB
82+
"""
83+
5284
Scenario: Display only table sizes in a human readable format for a WordPress install
5385
Given a WP install
5486

src/DB_Command.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -708,8 +708,7 @@ public function export( $args, $assoc_args ) {
708708
} else {
709709
// phpcs:ignore WordPress.WP.AlternativeFunctions.rand_mt_rand -- WordPress is not loaded.
710710
$hash = substr( md5( (string) mt_rand() ), 0, 7 );
711-
$db_name = $this->is_sqlite() ? 'sqlite-db' : DB_NAME;
712-
$result_file = sprintf( '%s-%s-%s.sql', $db_name, date( 'Y-m-d' ), $hash ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
711+
$result_file = sprintf( '%s-%s-%s.sql', DB_NAME, date( 'Y-m-d' ), $hash ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
713712

714713
}
715714

@@ -884,7 +883,7 @@ public function import( $args, $assoc_args ) {
884883
if ( ! empty( $args[0] ) ) {
885884
$result_file = $args[0];
886885
} else {
887-
$result_file = $this->is_sqlite() ? 'sqlite-db.sql' : sprintf( '%s.sql', DB_NAME );
886+
$result_file = sprintf( '%s.sql', DB_NAME );
888887
}
889888

890889
if ( $this->is_sqlite() ) {
@@ -1614,8 +1613,8 @@ public function search( $args, $assoc_args ) {
16141613
if ( ! $text_columns ) {
16151614
if ( $stats ) {
16161615
$skipped[] = $table;
1617-
// Don't bother warning for term relationships (which is just 3 int columns).
1618-
} elseif ( ! preg_match( '/_term_relationships$/', $table ) ) {
1616+
// Don't bother warning for term relationships (which is just 3 int columns) or SQLite.
1617+
} elseif ( ! preg_match( '/_term_relationships$/', $table ) && ! $this->is_sqlite() ) {
16191618
WP_CLI::warning( $primary_keys ? "No text columns for table '$table' - skipped." : "No primary key or text columns for table '$table' - skipped." );
16201619
}
16211620
continue;

src/DB_Command_SQLite.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ protected function sqlite_export( $file, $assoc_args ) {
371371

372372
fwrite( $output, "\n" );
373373
}
374+
375+
fwrite( $output, '-- Dump completed on ' . date( 'Y-m-d H:i:s' ) . "\n\n" );
374376
} catch ( PDOException $e ) {
375377
fclose( $output );
376378
WP_CLI::error( 'Export failed: ' . $e->getMessage() );

0 commit comments

Comments
 (0)