Skip to content

Commit 1e18f03

Browse files
committed
Merge branch 'main' into janw-me/main
2 parents 928405c + 4865fa1 commit 1e18f03

22 files changed

+1985
-293
lines changed

.github/workflows/testing.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
name: Testing
22

33
on:
4+
workflow_dispatch:
45
pull_request:
56
push:
67
branches:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ phpunit.xml
1212
phpcs.xml
1313
.phpcs.xml
1414
.phpunit.result.cache
15+
build/logs

bin/install-package-tests

Lines changed: 68 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,16 @@ else
8585
echo "Using default test password: ${C_BLUE}${TEST_PASSWORD}${NO_FORMAT}"
8686
fi
8787

88-
echo 'Checking if MySQL is ready...'
88+
echo "Detecting database version..."
89+
90+
TYPE="MySQL"
91+
CLIENT_VERSION=$(mysql --version 2>/dev/null)
92+
93+
case "${CLIENT_VERSION}" in
94+
*"MariaDB"*)
95+
TYPE="MariaDB"
96+
;;
97+
esac
8998

9099
if [ -z "$PS1" ]; then
91100
# These vars are because github actions gave problems in the past.
@@ -96,27 +105,59 @@ else
96105
MYSQL_WAIT=0
97106
fi
98107

99-
while ! mysql ${HOST_STRING} --user="${USER}" "${PASSWORD_STRING}" --execute="SHOW DATABASES;" | grep 'information_schema' >/dev/null;
100-
do
101-
i=$((i+1))
102-
if [ "${MYSQL_TRIES}" -gt 1 ]; then
103-
echo "Waiting for MySQL(${i}/${MYSQL_TRIES})..."
104-
sleep ${MYSQL_WAIT}
105-
fi
108+
if [ "${TYPE}" = "MySQL" ]; then
109+
SERVER_VERSION=$(mysql -e "SELECT VERSION()" --skip-column-names ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}")
110+
else
111+
SERVER_VERSION=$(mariadb -e "SELECT VERSION()" --skip-column-names ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}")
112+
fi
106113

107-
if [ $i -ge $MYSQL_TRIES ]; then
108-
echo "${C_RED}MySQL failed to start. Aborting.${NO_FORMAT}"
109-
echo "Cannot connect to mysql server. For all available variables, check the documentation at:"
110-
echo " ${C_BLUE}https://github.com/wp-cli/wp-cli-tests?tab=readme-ov-file#the-database-credentials${NO_FORMAT}"
111-
exit 1
112-
fi
113-
done
114+
VERSION=$(echo "${SERVER_VERSION}" | grep -o '^[^-]*')
115+
MAJOR=$(echo "${VERSION}" | cut -d. -f1)
116+
MINOR=$(echo "${VERSION}" | cut -d. -f2)
117+
118+
echo "Detected ${TYPE} at version ${MAJOR}.${MINOR}"
119+
120+
echo 'Checking if database is ready...'
121+
122+
if [ "${TYPE}" = "MySQL" ]; then
123+
while ! mysql ${HOST_STRING} --user="${USER}" "${PASSWORD_STRING}" --execute="SHOW DATABASES;" | grep 'information_schema' >/dev/null;
124+
do
125+
i=$((i+1))
126+
if [ "${MYSQL_TRIES}" -gt 1 ]; then
127+
echo "Waiting for MySQL(${i}/${MYSQL_TRIES})..."
128+
sleep ${MYSQL_WAIT}
129+
fi
130+
131+
if [ $i -ge $MYSQL_TRIES ]; then
132+
echo "${C_RED}MySQL failed to start. Aborting.${NO_FORMAT}"
133+
echo "Cannot connect to MySQL server. For all available variables, check the documentation at:"
134+
echo " ${C_BLUE}https://github.com/wp-cli/wp-cli-tests?tab=readme-ov-file#the-database-credentials${NO_FORMAT}"
135+
exit 1
136+
fi
137+
done
138+
else
139+
while ! mariadb ${HOST_STRING} --user="${USER}" "${PASSWORD_STRING}" --execute="SHOW DATABASES;" | grep 'information_schema' >/dev/null;
140+
do
141+
i=$((i+1))
142+
if [ "${MYSQL_TRIES}" -gt 1 ]; then
143+
echo "Waiting for MariaDB(${i}/${MYSQL_TRIES})..."
144+
sleep ${MYSQL_WAIT}
145+
fi
146+
147+
if [ $i -ge $MYSQL_TRIES ]; then
148+
echo "${C_RED}MariaDB failed to start. Aborting.${NO_FORMAT}"
149+
echo "Cannot connect to MariaDB server. For all available variables, check the documentation at:"
150+
echo " ${C_BLUE}https://github.com/wp-cli/wp-cli-tests?tab=readme-ov-file#the-database-credentials${NO_FORMAT}"
151+
exit 1
152+
fi
153+
done
154+
fi
114155

115156
# Prepare the database for running the tests with a MySQL version 8.0 or higher.
116157
install_mysql_db_8_0_plus() {
117158
set -ex # print all the commands.
118159
mysql -e "CREATE DATABASE IF NOT EXISTS \`${TEST_DB}\`;" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
119-
mysql -e "CREATE USER IF NOT EXISTS \`${TEST_USER}\`@'%' IDENTIFIED WITH mysql_native_password BY '${TEST_PASSWORD}'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
160+
mysql -e "CREATE USER IF NOT EXISTS \`${TEST_USER}\`@'%' IDENTIFIED WITH caching_sha2_password BY '${TEST_PASSWORD}'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
120161
mysql -e "GRANT ALL PRIVILEGES ON \`${TEST_DB}\`.* TO '${TEST_USER}'@'%'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
121162
mysql -e "GRANT ALL PRIVILEGES ON \`${TEST_DB}_scaffold\`.* TO '${TEST_USER}'@'%'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
122163
{ set +ex; } 2> /dev/null # stop printing the commands
@@ -131,20 +172,18 @@ install_mysql_db_lower_than_8_0() {
131172
{ set +ex; } 2> /dev/null # stop printing the commands
132173
}
133174

134-
VERSION_STRING=$(mysql -e "SELECT VERSION()" --skip-column-names ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}")
135-
VERSION=$(echo "${VERSION_STRING}" | grep -o '^[^-]*')
136-
MAJOR=$(echo "${VERSION}" | cut -d. -f1)
137-
MINOR=$(echo "${VERSION}" | cut -d. -f2)
138-
TYPE="MySQL"
139-
case "${VERSION_STRING}" in
140-
*"MariaDB"*)
141-
TYPE="MariaDB"
142-
;;
143-
esac
144-
145-
echo "Detected ${TYPE} at version ${MAJOR}.${MINOR}"
175+
# Prepare the database for running the tests with MariaDB
176+
install_mariadb() {
177+
set -ex
178+
mariadb -e "CREATE DATABASE IF NOT EXISTS \`${TEST_DB}\`;" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
179+
mariadb -e "CREATE USER IF NOT EXISTS \`${TEST_USER}\`@'%' IDENTIFIED BY '${TEST_PASSWORD}'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
180+
mariadb -e "GRANT ALL PRIVILEGES ON \`${TEST_DB}\`.* TO '${TEST_USER}'@'%'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
181+
mariadb -e "GRANT ALL PRIVILEGES ON \`${TEST_DB}_scaffold\`.* TO '${TEST_USER}'@'%'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
182+
}
146183

147-
if [ "${TYPE}" != "MariaDB" ] && [ "${MAJOR}" -ge 8 ]; then
184+
if [ "${TYPE}" = "MariaDB" ]; then
185+
install_mariadb
186+
elif [ "${MAJOR}" -ge 8 ]; then
148187
install_mysql_db_8_0_plus
149188
else
150189
install_mysql_db_lower_than_8_0

bin/run-php-unit-tests

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,16 @@
33
# Run the unit tests, if they exist
44
if [ -f "phpunit.xml" ] || [ -f "phpunit.xml.dist" ] || [ -f ".phpunit.xml" ] || [ -f ".phpunit.xml.dist" ]
55
then
6+
PHPUNIT_VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')
7+
EXTRA_ARGS=""
8+
9+
if [ "${PHPUNIT_VERSION#11}" != "$PHPUNIT_VERSION" ] || [ "${PHPUNIT_VERSION#10}" != "$PHPUNIT_VERSION" ]; then
10+
EXTRA_ARGS="--display-warnings --fail-on-warning --display-notices --fail-on-notice --display-deprecations --fail-on-deprecation"
11+
fi
12+
613
if [ -f "./vendor/wp-cli/wp-cli-tests/tests/bootstrap.php" ]; then
7-
vendor/bin/phpunit --color=always "$@" --bootstrap ./vendor/wp-cli/wp-cli-tests/tests/bootstrap.php
14+
vendor/bin/phpunit --color=always "$@" $EXTRA_ARGS --bootstrap ./vendor/wp-cli/wp-cli-tests/tests/bootstrap.php
815
else
9-
vendor/bin/phpunit --color=always "$@"
16+
vendor/bin/phpunit --color=always "$@" $EXTRA_ARGS
1017
fi
1118
fi

bin/run-phpstan-tests

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
# Run the code style check only if a configuration file exists.
4+
if [ -f "phpstan.dist.neon" ] || [ -f "phpstan.neon.dist" ] || [ -f "phpstan.neon" ]
5+
then
6+
vendor/bin/phpstan --memory-limit=2048M analyse "$@"
7+
fi

composer.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,19 @@
99
"license": "MIT",
1010
"type": "phpcodesniffer-standard",
1111
"require": {
12-
"php": ">=5.6",
12+
"php": ">=7.2.24",
1313
"behat/behat": "^3.7",
1414
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || ^0.5 || ^0.6.2 || ^0.7.1 || ^1.0.0",
1515
"php-parallel-lint/php-console-highlighter": "^1.0",
1616
"php-parallel-lint/php-parallel-lint": "^1.3.1",
17-
"phpcompatibility/php-compatibility": "^9.3.5",
17+
"phpcompatibility/php-compatibility": "dev-develop",
18+
"phpstan/extension-installer": "^1.4.3",
19+
"phpstan/phpstan": "^1.12.26",
20+
"szepeviktor/phpstan-wordpress": "^v1.3.5",
1821
"wp-cli/config-command": "^1 || ^2",
1922
"wp-cli/core-command": "^1 || ^2",
2023
"wp-cli/eval-command": "^1 || ^2",
21-
"wp-cli/wp-cli": "^2.5.1",
24+
"wp-cli/wp-cli": "^2.12",
2225
"wp-coding-standards/wpcs": "^3",
2326
"yoast/phpunit-polyfills": "^1.0.3 || ^2.0.1"
2427
},
@@ -28,9 +31,11 @@
2831
"config": {
2932
"allow-plugins": {
3033
"dealerdirect/phpcodesniffer-composer-installer": true,
31-
"johnpbloch/wordpress-core-installer": true
34+
"johnpbloch/wordpress-core-installer": true,
35+
"phpstan/extension-installer": true
3236
},
33-
"sort-packages": true
37+
"sort-packages": true,
38+
"lock": false
3439
},
3540
"extra": {
3641
"branch-alias": {
@@ -62,19 +67,22 @@
6267
"bin/run-linter-tests",
6368
"bin/run-php-unit-tests",
6469
"bin/run-phpcs-tests",
65-
"bin/run-phpcbf-cleanup"
70+
"bin/run-phpcbf-cleanup",
71+
"bin/run-phpstan-tests"
6672
],
6773
"scripts": {
6874
"behat": "run-behat-tests",
6975
"behat-rerun": "rerun-behat-tests",
7076
"lint": "run-linter-tests",
7177
"phpcs": "run-phpcs-tests",
7278
"phpcbf": "run-phpcbf-cleanup",
79+
"phpstan": "run-phpstan-tests",
7380
"phpunit": "run-php-unit-tests",
7481
"prepare-tests": "install-package-tests",
7582
"test": [
7683
"@lint",
7784
"@phpcs",
85+
"@phpstan",
7886
"@phpunit",
7987
"@behat"
8088
]

features/http-mocking.feature

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
Feature: HTTP request mocking
2+
3+
Scenario: Mock HTTP request in WP-CLI
4+
Given that HTTP requests to https://api.github.com/repos/wp-cli/wp-cli/releases?per_page=100 will respond with:
5+
"""
6+
HTTP/1.1 200
7+
Content-Type: application/json
8+
9+
[
10+
{
11+
"url": "https://api.github.com/repos/wp-cli/wp-cli/releases/169243978",
12+
"assets_url": "https://api.github.com/repos/wp-cli/wp-cli/releases/169243978/assets",
13+
"upload_url": "https://uploads.github.com/repos/wp-cli/wp-cli/releases/169243978/assets{?name,label}",
14+
"html_url": "https://github.com/wp-cli/wp-cli/releases/tag/v999.9.9",
15+
"id": 169243978,
16+
"author": {
17+
"login": "schlessera",
18+
"id": 83631,
19+
"node_id": "MDQ6VXNlcjgzNjMx",
20+
"avatar_url": "https://avatars.githubusercontent.com/u/83631?v=4",
21+
"gravatar_id": "",
22+
"url": "https://api.github.com/users/schlessera",
23+
"html_url": "https://github.com/schlessera",
24+
"followers_url": "https://api.github.com/users/schlessera/followers",
25+
"following_url": "https://api.github.com/users/schlessera/following{/other_user}",
26+
"gists_url": "https://api.github.com/users/schlessera/gists{/gist_id}",
27+
"starred_url": "https://api.github.com/users/schlessera/starred{/owner}{/repo}",
28+
"subscriptions_url": "https://api.github.com/users/schlessera/subscriptions",
29+
"organizations_url": "https://api.github.com/users/schlessera/orgs",
30+
"repos_url": "https://api.github.com/users/schlessera/repos",
31+
"events_url": "https://api.github.com/users/schlessera/events{/privacy}",
32+
"received_events_url": "https://api.github.com/users/schlessera/received_events",
33+
"type": "User",
34+
"user_view_type": "public",
35+
"site_admin": false
36+
},
37+
"node_id": "RE_kwDOACQFs84KFnVK",
38+
"tag_name": "v999.9.9",
39+
"target_commitish": "main",
40+
"name": "Version 999.9.9",
41+
"draft": false,
42+
"prerelease": false,
43+
"created_at": "2024-08-08T03:04:55Z",
44+
"published_at": "2024-08-08T03:51:13Z",
45+
"assets": [
46+
{
47+
"url": "https://api.github.com/repos/wp-cli/wp-cli/releases/assets/184590231",
48+
"id": 184590231,
49+
"node_id": "RA_kwDOACQFs84LAJ-X",
50+
"name": "wp-cli-999.9.9.phar",
51+
"label": null,
52+
"content_type": "application/octet-stream",
53+
"state": "uploaded",
54+
"size": 7048108,
55+
"download_count": 722639,
56+
"created_at": "2024-08-08T03:51:05Z",
57+
"updated_at": "2024-08-08T03:51:08Z",
58+
"browser_download_url": "https://github.com/wp-cli/wp-cli/releases/download/v999.9.9/wp-cli-999.9.9.phar"
59+
}
60+
],
61+
"tarball_url": "https://api.github.com/repos/wp-cli/wp-cli/tarball/v999.9.9",
62+
"zipball_url": "https://api.github.com/repos/wp-cli/wp-cli/zipball/v999.9.9",
63+
"body": "- Allow manually dispatching tests workflow [[#5965](https://github.com/wp-cli/wp-cli/pull/5965)]\r\n- Add fish shell completion [[#5954](https://github.com/wp-cli/wp-cli/pull/5954)]\r\n- Add defaults and accepted values for runcommand() options in doc [[#5953](https://github.com/wp-cli/wp-cli/pull/5953)]\r\n- Address warnings with filenames ending in fullstop on Windows [[#5951](https://github.com/wp-cli/wp-cli/pull/5951)]\r\n- Fix unit tests [[#5950](https://github.com/wp-cli/wp-cli/pull/5950)]\r\n- Update copyright year in license [[#5942](https://github.com/wp-cli/wp-cli/pull/5942)]\r\n- Fix breaking multi-line CSV values on reading [[#5939](https://github.com/wp-cli/wp-cli/pull/5939)]\r\n- Fix broken Gutenberg test [[#5938](https://github.com/wp-cli/wp-cli/pull/5938)]\r\n- Update docker runner to resolve docker path using `/usr/bin/env` [[#5936](https://github.com/wp-cli/wp-cli/pull/5936)]\r\n- Fix `inherit` path in nested directory [[#5930](https://github.com/wp-cli/wp-cli/pull/5930)]\r\n- Minor docblock improvements [[#5929](https://github.com/wp-cli/wp-cli/pull/5929)]\r\n- Add Signup fetcher [[#5926](https://github.com/wp-cli/wp-cli/pull/5926)]\r\n- Ensure the alias has the leading `@` symbol when added [[#5924](https://github.com/wp-cli/wp-cli/pull/5924)]\r\n- Include any non default hook information in CompositeCommand [[#5921](https://github.com/wp-cli/wp-cli/pull/5921)]\r\n- Correct completion case when ends in = [[#5913](https://github.com/wp-cli/wp-cli/pull/5913)]\r\n- Docs: Fixes for inline comments [[#5912](https://github.com/wp-cli/wp-cli/pull/5912)]\r\n- Update Inline comments [[#5910](https://github.com/wp-cli/wp-cli/pull/5910)]\r\n- Add a real-world example for `wp cli has-command` [[#5908](https://github.com/wp-cli/wp-cli/pull/5908)]\r\n- Fix typos [[#5901](https://github.com/wp-cli/wp-cli/pull/5901)]\r\n- Avoid PHP deprecation notices in PHP 8.1.x [[#5899](https://github.com/wp-cli/wp-cli/pull/5899)]",
64+
"reactions": {
65+
"url": "https://api.github.com/repos/wp-cli/wp-cli/releases/169243978/reactions",
66+
"total_count": 9,
67+
"+1": 4,
68+
"-1": 0,
69+
"laugh": 0,
70+
"hooray": 1,
71+
"confused": 0,
72+
"heart": 0,
73+
"rocket": 4,
74+
"eyes": 0
75+
}
76+
}
77+
]
78+
"""
79+
80+
When I try `wp cli check-update --format=csv`
81+
Then STDOUT should contain:
82+
"""
83+
999.9.9,major,https://github.com/wp-cli/wp-cli/releases/download/v999.9.9/wp-cli-999.9.9.phar,available
84+
"""
85+
86+
Scenario: Mock HTTP request in WordPress
87+
Given a WP install
88+
And that HTTP requests to https://api.wordpress.org/core/version-check/1.7/ will respond with:
89+
"""
90+
HTTP/1.1 200
91+
Content-Type: application/json
92+
93+
{
94+
"offers": [
95+
{
96+
"response": "latest",
97+
"download": "https:\/\/downloads.wordpress.org\/release\/wordpress-999.9.9.zip",
98+
"locale": "en_US",
99+
"packages": {
100+
"full": "https:\/\/downloads.wordpress.org\/release\/wordpress-999.9.9.zip",
101+
"no_content": "https:\/\/downloads.wordpress.org\/release\/wordpress-999.9.9-no-content.zip",
102+
"new_bundled": "https:\/\/downloads.wordpress.org\/release\/wordpress-999.9.9-new-bundled.zip",
103+
"partial": false,
104+
"rollback": false
105+
},
106+
"current": "999.9.9",
107+
"version": "999.9.9",
108+
"php_version": "7.2.24",
109+
"mysql_version": "5.5.5",
110+
"new_bundled": "6.7",
111+
"partial_version": false
112+
}
113+
],
114+
"translations": []
115+
}
116+
"""
117+
118+
When I run `wp core check-update`
119+
Then STDOUT should be a table containing rows:
120+
| version | update_type | package_url |
121+
| 999.9.9 | major | https://downloads.wordpress.org/release/wordpress-999.9.9.zip |

0 commit comments

Comments
 (0)