Skip to content

Commit 19f6813

Browse files
committed
Some test improvements
1 parent a89fe31 commit 19f6813

7 files changed

Lines changed: 182 additions & 101 deletions

File tree

features/db-check.feature

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Feature: Check the database
22

3+
@require-mysql-or-mariadb
34
Scenario: Run db check to check the database
45
Given a WP install
56

@@ -13,6 +14,7 @@ Feature: Check the database
1314
Success: Database checked.
1415
"""
1516

17+
@require-mysql-or-mariadb
1618
Scenario: Run db check with MySQL defaults to check the database
1719
Given a WP install
1820

@@ -26,6 +28,7 @@ Feature: Check the database
2628
Success: Database checked.
2729
"""
2830

31+
@require-mysql-or-mariadb
2932
Scenario: Run db check with --no-defaults to check the database
3033
Given a WP install
3134

@@ -39,6 +42,7 @@ Feature: Check the database
3942
Success: Database checked.
4043
"""
4144

45+
@require-mysql-or-mariadb
4246
Scenario: Run db check with passed-in options
4347
Given a WP install
4448

@@ -124,6 +128,7 @@ Feature: Check the database
124128
"""
125129
And STDOUT should be empty
126130

131+
@require-mysql-or-mariadb
127132
Scenario: MySQL defaults are available as appropriate with --defaults flag
128133
Given a WP install
129134

@@ -136,3 +141,12 @@ Feature: Check the database
136141
When I try `wp db check --no-defaults --debug`
137142
Then STDERR should match #Debug \(db\): Running shell command: /usr/bin/env (mysqlcheck|mariadb-check) --no-defaults %s#
138143

144+
@require-sqlite
145+
Scenario: SQLite commands that show warnings
146+
Given a WP install
147+
148+
When I run `wp db check`
149+
Then STDOUT should contain:
150+
"""
151+
Warning: Database check is not supported for SQLite databases
152+
"""

features/db-cli.feature

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Feature: Open a MySQL console
2+
3+
@require-mysql-or-mariadb
4+
Scenario: Run db cli to open a MySQL console
5+
Given a WP install
6+
7+
When I run `wp db cli`
8+
Then STDOUT should contain:
9+
"""
10+
mysql>
11+
"""
12+
13+
@require-sqlite
14+
Scenario: SQLite commands that show warnings for cli
15+
Given a WP install
16+
17+
When I run `wp db cli`
18+
Then STDOUT should contain:
19+
"""
20+
Warning: Interactive console (cli) is not supported for SQLite databases
21+
"""

features/db-create.feature

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Feature: Create a new database
2+
3+
@require-mysql-or-mariadb
4+
Scenario: Create a new database
5+
Given an empty directory
6+
And WP files
7+
And wp-config.php
8+
9+
When I run `wp db create`
10+
Then STDOUT should contain:
11+
"""
12+
Success: Database created.
13+
"""
14+
15+
@require-sqlite
16+
Scenario: SQLite DB create operation should fail if already existing
17+
Given a WP install
18+
19+
When I try `wp db create`
20+
Then the return code should be 1
21+
And STDERR should contain:
22+
"""
23+
Database already exists
24+
"""

features/db-optimize.feature

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Feature: Optimize the database
2+
3+
@require-mysql-or-mariadb
4+
Scenario: Run db optimize to optimize the database
5+
Given a WP install
6+
7+
When I run `wp db optimize`
8+
Then STDOUT should contain:
9+
"""
10+
Success: Database optimized.
11+
"""
12+
13+
@require-sqlite
14+
Scenario: SQLite commands that show warnings for optimize
15+
Given a WP install
16+
17+
When I run `wp db optimize`
18+
Then STDOUT should contain:
19+
"""
20+
Warning: Database optimization is not supported for SQLite databases
21+
"""

features/db-repair.feature

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Feature: Repair the database
2+
3+
@require-mysql-or-mariadb
4+
Scenario: Run db repair to repair the database
5+
Given a WP install
6+
7+
When I run `wp db repair`
8+
Then STDOUT should contain:
9+
"""
10+
Success: Database repaired.
11+
"""
12+
13+
@require-sqlite
14+
Scenario: SQLite commands that show warnings for repair
15+
Given a WP install
16+
17+
When I run `wp db repair`
18+
Then STDOUT should contain:
19+
"""
20+
Warning: Database repair is not supported for SQLite databases
21+
"""

features/db-sqlite.feature

Lines changed: 0 additions & 100 deletions
This file was deleted.

features/db.feature

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Feature: Perform database operations
22

3+
@require-mysql-or-mariadb
34
Scenario: DB CRUD
45
Given an empty directory
56
And WP files
@@ -52,6 +53,7 @@ Feature: Perform database operations
5253
Are you sure you want to reset the 'wp_cli_test' database? [y/n] Success: Database reset.
5354
"""
5455
56+
@require-mysql-or-mariadb
5557
Scenario: DB CRUD with passed-in dbuser/dbpass
5658
Given an empty directory
5759
And WP files
@@ -107,6 +109,7 @@ Feature: Perform database operations
107109
"""
108110
And STDOUT should be empty
109111
112+
@require-mysql-or-mariadb
110113
Scenario: Clean up a WordPress install without dropping its database entirely but tables with prefix.
111114
Given a WP install
112115
@@ -138,6 +141,7 @@ Feature: Perform database operations
138141
"""
139142
And the return code should be 0
140143
144+
@require-mysql-or-mariadb
141145
Scenario: DB Operations
142146
Given a WP install
143147
@@ -147,6 +151,7 @@ Feature: Perform database operations
147151
When I run `wp db repair`
148152
Then STDOUT should not be empty
149153
154+
@require-mysql-or-mariadb
150155
Scenario: DB Operations with passed-in options
151156
Given a WP install
152157
@@ -185,6 +190,7 @@ Feature: Perform database operations
185190
"""
186191
And STDOUT should not be empty
187192
193+
@require-mysql-or-mariadb
188194
Scenario: DB Query
189195
Given a WP install
190196
@@ -214,6 +220,7 @@ Feature: Perform database operations
214220
home
215221
"""
216222
223+
@require-mysql-or-mariadb
217224
Scenario: DB export/import
218225
Given a WP install
219226
@@ -262,6 +269,7 @@ Feature: Perform database operations
262269
1
263270
"""
264271
272+
@require-mysql-or-mariadb
265273
Scenario: DB export no charset
266274
Given an empty directory
267275
And WP files
@@ -327,14 +335,15 @@ Feature: Perform database operations
327335
latin1_spanish_ci
328336
"""
329337
338+
@require-mysql-or-mariadb
330339
Scenario: Row modifying queries should return the number of affected rows
331340
Given a WP install
332341
When I run `wp db query "UPDATE wp_users SET user_status = 1 WHERE ID = 1"`
333342
Then STDOUT should contain:
334343
"""
335344
Query succeeded. Rows affected: 1
336345
"""
337-
346+
338347
When I run `wp db query "SELECT * FROM wp_users WHERE ID = 1"`
339348
Then STDOUT should not contain:
340349
"""
@@ -346,3 +355,74 @@ Feature: Perform database operations
346355
"""
347356
Query succeeded. Rows affected: 1
348357
"""
358+
359+
@require-sqlite
360+
Scenario: SQLite DB CRUD operations
361+
Given a WP install
362+
And a session_yes file:
363+
"""
364+
y
365+
"""
366+
367+
When I try `wp db create`
368+
Then the return code should be 1
369+
And STDERR should contain:
370+
"""
371+
Database already exists
372+
"""
373+
374+
When I run `wp db drop < session_yes`
375+
Then STDOUT should contain:
376+
"""
377+
Success: Database dropped.
378+
"""
379+
380+
When I run `wp db reset < session_yes`
381+
Then STDOUT should contain:
382+
"""
383+
Success: Database reset
384+
"""
385+
386+
@require-sqlite
387+
Scenario: SQLite DB query
388+
Given a WP install
389+
390+
When I run `wp db query 'SELECT COUNT(*) as total FROM wp_posts'`
391+
Then STDOUT should contain:
392+
"""
393+
total
394+
"""
395+
396+
@require-sqlite
397+
Scenario: SQLite DB export/import
398+
Given a WP install
399+
400+
When I run `wp post list --format=count`
401+
Then STDOUT should contain:
402+
"""
403+
1
404+
"""
405+
406+
When I run `wp db export /tmp/wp-cli-sqlite-behat.sql`
407+
Then STDOUT should contain:
408+
"""
409+
Success: Exported
410+
"""
411+
412+
When I run `wp db reset < session_yes`
413+
Then STDOUT should contain:
414+
"""
415+
Success: Database reset
416+
"""
417+
418+
When I run `wp db import /tmp/wp-cli-sqlite-behat.sql`
419+
Then STDOUT should contain:
420+
"""
421+
Success: Imported
422+
"""
423+
424+
When I run `wp post list --format=count`
425+
Then STDOUT should contain:
426+
"""
427+
1
428+
"""

0 commit comments

Comments
 (0)