Skip to content

Commit 2dd3710

Browse files
authored
Merge branch 'main' into copilot/improve-mariadb-tests
2 parents f7567d5 + 358e2a0 commit 2dd3710

20 files changed

+1266
-44
lines changed

.gitattributes

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/.actrc export-ignore
2+
/.distignore export-ignore
3+
/.editorconfig export-ignore
4+
/.github export-ignore
5+
/.gitignore export-ignore
6+
/.typos.toml export-ignore
7+
/AGENTS.md export-ignore
8+
/behat.yml export-ignore
9+
/features export-ignore
10+
/phpcs.xml.dist export-ignore
11+
/phpstan.neon.dist export-ignore
12+
/phpunit.xml.dist export-ignore
13+
/tests export-ignore
14+
/wp-cli.yml export-ignore

.github/workflows/code-quality.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
branches:
77
- main
88
- master
9+
schedule:
10+
- cron: '17 2 * * *' # Run every day on a seemly random time.
911

1012
jobs:
1113
code-quality:

.github/workflows/copilot-setup-steps.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@ jobs:
2121

2222
- name: Check existence of composer.json file
2323
id: check_composer_file
24-
uses: andstor/file-existence-action@076e0072799f4942c8bc574a82233e1e4d13e9d6 # v3
25-
with:
26-
files: "composer.json"
24+
run: echo "files_exists=$(test -f composer.json && echo true || echo false)" >> "$GITHUB_OUTPUT"
2725

2826
- name: Set up PHP environment
2927
if: steps.check_composer_file.outputs.files_exists == 'true'
30-
uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # v2
28+
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # v2
3129
with:
3230
php-version: 'latest'
3331
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
@@ -38,7 +36,7 @@ jobs:
3836

3937
- name: Install Composer dependencies & cache dependencies
4038
if: steps.check_composer_file.outputs.files_exists == 'true'
41-
uses: ramsey/composer-install@3cf229dc2919194e9e36783941438d17239e8520 # v3
39+
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # v3
4240
env:
4341
COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}
4442
with:

features/db-check.feature

Lines changed: 16 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,12 +14,14 @@ Feature: Check the database
1314
Success: Database checked.
1415
"""
1516

17+
@require-mysql-or-mariadb
1618
Scenario: db check with --quiet flag should only show errors
1719
Given a WP install
1820

1921
When I run `wp db check --quiet`
2022
Then STDOUT should be empty
2123

24+
@require-mysql-or-mariadb
2225
Scenario: db check can explicitly pass --silent to mysqlcheck
2326
Given a WP install
2427

@@ -32,6 +35,7 @@ Feature: Check the database
3235
Success: Database checked.
3336
"""
3437

38+
@require-mysql-or-mariadb
3539
Scenario: Run db check with MySQL defaults to check the database
3640
Given a WP install
3741

@@ -45,6 +49,7 @@ Feature: Check the database
4549
Success: Database checked.
4650
"""
4751

52+
@require-mysql-or-mariadb
4853
Scenario: Run db check with --no-defaults to check the database
4954
Given a WP install
5055

@@ -58,6 +63,7 @@ Feature: Check the database
5863
Success: Database checked.
5964
"""
6065

66+
@require-mysql-or-mariadb
6167
Scenario: Run db check with passed-in options
6268
Given a WP install
6369

@@ -143,6 +149,7 @@ Feature: Check the database
143149
"""
144150
And STDOUT should be empty
145151

152+
@require-mysql-or-mariadb
146153
Scenario: MySQL defaults are available as appropriate with --defaults flag
147154
Given a WP install
148155

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

165+
@require-sqlite
166+
Scenario: SQLite commands that show warnings
167+
Given a WP install
168+
169+
When I try `wp db check`
170+
Then STDERR should contain:
171+
"""
172+
Warning: Database check is not supported for SQLite databases
173+
"""

features/db-cli.feature

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Feature: Open a MySQL console
2+
3+
@require-sqlite
4+
Scenario: SQLite commands that show warnings for cli
5+
Given a WP install
6+
7+
When I try `wp db cli`
8+
Then STDERR should contain:
9+
"""
10+
Warning: Interactive console (cli) is not supported for SQLite databases
11+
"""

features/db-columns.feature

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Feature: Display information about a given table.
22

33
# This requires conditional tags to target different DB versions, as bigint(20) is only bigint on MySQL 8.
4-
@require-wp-4.2 @broken
4+
@broken
55
Scenario: Display information about the wp_posts table
66
Given a WP install
77

@@ -41,6 +41,7 @@ Feature: Display information about a given table.
4141
Couldn't find any tables matching: wp_foobar
4242
"""
4343

44+
@require-mysql-or-mariadb
4445
Scenario: Display information about a non default WordPress table
4546
Given a WP install
4647
And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"`
@@ -50,3 +51,14 @@ Feature: Display information about a given table.
5051
| Field | Type | Null | Key | Default | Extra |
5152
| date | date | NO | PRI | | |
5253
| awesome_stuff | text | YES | | | |
54+
55+
@require-sqlite
56+
Scenario: Display information about a non default WordPress table
57+
Given a WP install
58+
And I run `wp db query "CREATE TABLE not_wp ( date DATE NOT NULL, awesome_stuff TEXT, PRIMARY KEY (date) );;"`
59+
60+
When I try `wp db columns not_wp`
61+
Then STDOUT should be a table containing rows:
62+
| Field | Type | Null | Key | Default |
63+
| date | TEXT | NO | PRI | '' |
64+
| awesome_stuff | TEXT | YES | | |

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-export.feature

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,57 @@ Feature: Export a WordPress database
2020
"""
2121
And the wp_cli_test.sql file should exist
2222

23+
@skip-sqlite
2324
Scenario: Exclude tables when exporting the database
2425
Given a WP install
2526

26-
When I run `wp db export wp_cli_test.sql --exclude_tables=wp_users --porcelain`
27+
When I try `wp db export wp_cli_test.sql --exclude_tables=wp_users --porcelain`
2728
Then the wp_cli_test.sql file should exist
28-
And the wp_cli_test.sql file should not contain:
29-
"""
30-
wp_users
31-
"""
32-
And the wp_cli_test.sql file should contain:
29+
And the contents of the wp_cli_test.sql file should not match /CREATE TABLE ["`]?wp_users["`]?/
30+
And the contents of the wp_cli_test.sql file should match /CREATE TABLE ["`]?wp_options["`]?/
31+
32+
@skip-sqlite
33+
Scenario: Include only specific tables when exporting the database
34+
Given a WP install
35+
36+
When I try `wp db export wp_cli_test.sql --tables=wp_users --porcelain`
37+
Then the wp_cli_test.sql file should exist
38+
And the contents of the wp_cli_test.sql file should match /CREATE TABLE ["`]?wp_users["`]?/
39+
And the contents of the wp_cli_test.sql file should not match /CREATE TABLE ["`]?wp_posts["`]?/
40+
And the contents of the wp_cli_test.sql file should not match /CREATE TABLE ["`]?wp_options["`]?/
41+
42+
@require-sqlite
43+
Scenario: Exclude tables when exporting the database
44+
Given a WP install
45+
46+
When I try `wp db export wp_cli_test.sql --exclude_tables=wp_users --porcelain`
47+
Then the wp_cli_test.sql file should exist
48+
And the contents of the wp_cli_test.sql file should not match /_mysql_data_types_cache/
49+
And the contents of the wp_cli_test.sql file should not match /CREATE TABLE ["`]?wp_users["`]?/
50+
And the contents of the wp_cli_test.sql file should match /CREATE TABLE ["`]?wp_options["`]?/
51+
52+
@require-sqlite
53+
Scenario: Include only specific tables when exporting the database
54+
Given a WP install
55+
56+
When I try `wp db export wp_cli_test.sql --tables=wp_users --porcelain`
57+
Then the wp_cli_test.sql file should exist
58+
And the contents of the wp_cli_test.sql file should not match /_mysql_data_types_cache/
59+
And the contents of the wp_cli_test.sql file should match /CREATE TABLE ["`]?wp_users["`]?/
60+
And the contents of the wp_cli_test.sql file should not match /CREATE TABLE ["`]?wp_posts["`]?/
61+
And the contents of the wp_cli_test.sql file should not match /CREATE TABLE ["`]?wp_options["`]?/
62+
63+
@require-sqlite
64+
Scenario: Export database to STDOUT
65+
Given a WP install
66+
67+
When I run `wp db export -`
68+
Then STDOUT should contain:
3369
"""
34-
wp_options
70+
PRAGMA foreign_keys=OFF
3571
"""
3672

73+
@skip-sqlite
3774
Scenario: Export database to STDOUT
3875
Given a WP install
3976

@@ -42,7 +79,7 @@ Feature: Export a WordPress database
4279
"""
4380
-- Dump completed on
4481
"""
45-
82+
@skip-sqlite
4683
Scenario: Export database with mysql defaults to STDOUT
4784
Given a WP install
4885

@@ -52,6 +89,7 @@ Feature: Export a WordPress database
5289
-- Dump completed on
5390
"""
5491

92+
@skip-sqlite
5593
Scenario: Export database with mysql --no-defaults to STDOUT
5694
Given a WP install
5795

@@ -61,6 +99,7 @@ Feature: Export a WordPress database
6199
-- Dump completed on
62100
"""
63101

102+
@skip-sqlite
64103
Scenario: Export database with passed-in options
65104
Given a WP install
66105

@@ -78,6 +117,25 @@ Feature: Export a WordPress database
78117
"""
79118
And STDOUT should be empty
80119

120+
@require-sqlite
121+
Scenario: Export database with passed-in options
122+
Given a WP install
123+
124+
When I run `wp db export - --skip-comments`
125+
Then STDOUT should not contain:
126+
"""
127+
-- Table structure
128+
"""
129+
130+
# dbpass has no effect on SQLite
131+
When I try `wp db export - --dbpass=no_such_pass`
132+
Then the return code should be 0
133+
And STDERR should not contain:
134+
"""
135+
Access denied
136+
"""
137+
138+
@skip-sqlite
81139
Scenario: MySQL defaults are available as appropriate with --defaults flag
82140
Given a WP install
83141

0 commit comments

Comments
 (0)