Skip to content
28 changes: 28 additions & 0 deletions features/db-import.feature
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,34 @@ Feature: Import a WordPress database
Success: Imported from 'wp_cli_test.sql'.
"""

@require-mysql-or-mariadb
Scenario: Database import falls back to wpdb when mysql binary is unavailable
Given a WP install
And a fake-bin/mysql file:
"""
#!/bin/sh
exit 127
"""
And a fake-bin/mariadb file:
"""
#!/bin/sh
exit 127
"""

When I run `wp db export wp_cli_test.sql`
Then the wp_cli_test.sql file should exist

When I run `chmod +x fake-bin/mysql fake-bin/mariadb`
And I run `env PATH={RUN_DIR}/fake-bin:$PATH wp db import wp_cli_test.sql --debug`
Then STDOUT should be:
"""
Success: Imported from 'wp_cli_test.sql'.
"""
And STDERR should contain:
"""
MySQL/MariaDB binary not available, falling back to wpdb for import.
"""

# SQLite doesn't support the --dbuser flag.
@require-mysql-or-mariadb
Scenario: Import from database name path by default with passed-in dbuser/dbpass
Expand Down
26 changes: 26 additions & 0 deletions features/db-query.feature
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,29 @@ Feature: Query the database with WordPress' MySQL config
"""
ANSI
"""

@require-mysql-or-mariadb
Scenario: Database querying falls back to wpdb when mysql binary is unavailable
Given a WP install
And a fake-bin/mysql file:
"""
#!/bin/sh
exit 127
"""
And a fake-bin/mariadb file:
"""
#!/bin/sh
exit 127
"""

When I run `chmod +x fake-bin/mysql fake-bin/mariadb`
And I try `env PATH={RUN_DIR}/fake-bin:$PATH wp db query "SELECT COUNT(ID) FROM wp_users;" --debug`
Then STDOUT should be:
"""
COUNT(ID)
1
"""
And STDERR should contain:
"""
MySQL/MariaDB binary not available, falling back to wpdb.
"""
52 changes: 51 additions & 1 deletion features/db.feature
Original file line number Diff line number Diff line change
Expand Up @@ -383,8 +383,58 @@ Feature: Perform database operations
Query succeeded. Rows affected: 1
"""

@require-sqlite @skip-windows
@require-mysql-or-mariadb
Scenario: Database drop falls back to wpdb when mysql binary is unavailable
Given a WP install
And a fake-bin/mysql file:
"""
#!/bin/sh
exit 127
"""
And a fake-bin/mariadb file:
"""
#!/bin/sh
exit 127
"""

When I run `chmod +x fake-bin/mysql fake-bin/mariadb`
And I try `env PATH={RUN_DIR}/fake-bin:$PATH wp db drop --yes --debug`
Then STDOUT should contain:
"""
Success: Database dropped.
"""
And STDERR should contain:
"""
Query via wpdb:
"""

@require-mysql-or-mariadb
Scenario: Database reset falls back to wpdb when mysql binary is unavailable
Given a WP install
And a fake-bin/mysql file:
"""
#!/bin/sh
exit 127
"""
And a fake-bin/mariadb file:
"""
#!/bin/sh
exit 127
"""

When I run `chmod +x fake-bin/mysql fake-bin/mariadb`
And I try `env PATH={RUN_DIR}/fake-bin:$PATH wp db reset --yes --debug`
Then STDOUT should contain:
"""
Success: Database reset.
"""
And STDERR should contain:
"""
Query via wpdb:
"""

# Skipped on Windows due to persistent file locking issues when run via Behat.
@require-sqlite @skip-windows
Scenario: SQLite DB CRUD operations
Given a WP install
And a session_yes file:
Expand Down
Loading
Loading