Skip to content

Commit 9fd76dd

Browse files
authored
Merge branch 'main' into feature/wp-version-resolve
2 parents 2faa3d1 + 4865fa1 commit 9fd76dd

22 files changed

+1977
-288
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: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,60 @@ if [ -n "${WP_CLI_TEST_DBPASS}" ]; then
6060
TEST_PASSWORD="${WP_CLI_TEST_DBPASS}"
6161
fi
6262

63-
echo 'Checking if MySQL is ready...'
64-
while ! mysql ${HOST_STRING} --user="${USER}" "${PASSWORD_STRING}" --execute="SHOW DATABASES;" | grep 'information_schema' >/dev/null;
65-
do
66-
echo 'Waiting for MySQL...'
67-
sleep 5
68-
i=$((i+1))
69-
if [ $i -gt 36 ]; then
70-
echo 'MySQL failed to start. Aborting.'
71-
exit 1
72-
fi
73-
done
63+
echo "Detecting database version..."
64+
65+
TYPE="MySQL"
66+
CLIENT_VERSION=$(mysql --version 2>/dev/null)
67+
68+
case "${CLIENT_VERSION}" in
69+
*"MariaDB"*)
70+
TYPE="MariaDB"
71+
;;
72+
esac
73+
74+
if [ "${TYPE}" = "MySQL" ]; then
75+
SERVER_VERSION=$(mysql -e "SELECT VERSION()" --skip-column-names ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}")
76+
else
77+
SERVER_VERSION=$(mariadb -e "SELECT VERSION()" --skip-column-names ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}")
78+
fi
79+
80+
VERSION=$(echo "${SERVER_VERSION}" | grep -o '^[^-]*')
81+
MAJOR=$(echo "${VERSION}" | cut -d. -f1)
82+
MINOR=$(echo "${VERSION}" | cut -d. -f2)
83+
84+
echo "Detected ${TYPE} at version ${MAJOR}.${MINOR}"
85+
86+
echo 'Checking if database is ready...'
87+
88+
if [ "${TYPE}" = "MySQL" ]; then
89+
while ! mysql ${HOST_STRING} --user="${USER}" "${PASSWORD_STRING}" --execute="SHOW DATABASES;" | grep 'information_schema' >/dev/null;
90+
do
91+
echo 'Waiting for database...'
92+
sleep 5
93+
i=$((i+1))
94+
if [ $i -gt 36 ]; then
95+
echo 'Database failed to start. Aborting.'
96+
exit 1
97+
fi
98+
done
99+
else
100+
while ! mariadb ${HOST_STRING} --user="${USER}" "${PASSWORD_STRING}" --execute="SHOW DATABASES;" | grep 'information_schema' >/dev/null;
101+
do
102+
echo 'Waiting for database...'
103+
sleep 5
104+
i=$((i+1))
105+
if [ $i -gt 36 ]; then
106+
echo 'Database failed to start. Aborting.'
107+
exit 1
108+
fi
109+
done
110+
fi
74111

75112
# Prepare the database for running the tests with a MySQL version 8.0 or higher.
76113
install_mysql_db_8_0_plus() {
77114
set -ex
78115
mysql -e "CREATE DATABASE IF NOT EXISTS \`${TEST_DB}\`;" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
79-
mysql -e "CREATE USER IF NOT EXISTS \`${TEST_USER}\`@'%' IDENTIFIED WITH mysql_native_password BY '${TEST_PASSWORD}'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
116+
mysql -e "CREATE USER IF NOT EXISTS \`${TEST_USER}\`@'%' IDENTIFIED WITH caching_sha2_password BY '${TEST_PASSWORD}'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
80117
mysql -e "GRANT ALL PRIVILEGES ON \`${TEST_DB}\`.* TO '${TEST_USER}'@'%'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
81118
mysql -e "GRANT ALL PRIVILEGES ON \`${TEST_DB}_scaffold\`.* TO '${TEST_USER}'@'%'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
82119
}
@@ -89,21 +126,18 @@ install_mysql_db_lower_than_8_0() {
89126
mysql -e "GRANT ALL ON \`${TEST_DB}_scaffold\`.* TO '${TEST_USER}'@'%' IDENTIFIED BY '${TEST_PASSWORD}'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
90127
}
91128

92-
VERSION_STRING=$(mysql -e "SELECT VERSION()" --skip-column-names ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}")
93-
VERSION=$(echo "${VERSION_STRING}" | grep -o '^[^-]*')
94-
MAJOR=$(echo "${VERSION}" | cut -d. -f1)
95-
MINOR=$(echo "${VERSION}" | cut -d. -f2)
96-
TYPE="MySQL"
97-
case "${VERSION_STRING}" in
98-
*"MariaDB"*)
99-
TYPE="MariaDB"
100-
;;
101-
esac
102-
103-
echo "Detected ${TYPE} at version ${MAJOR}.${MINOR}"
104-
129+
# Prepare the database for running the tests with MariaDB
130+
install_mariadb() {
131+
set -ex
132+
mariadb -e "CREATE DATABASE IF NOT EXISTS \`${TEST_DB}\`;" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
133+
mariadb -e "CREATE USER IF NOT EXISTS \`${TEST_USER}\`@'%' IDENTIFIED BY '${TEST_PASSWORD}'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
134+
mariadb -e "GRANT ALL PRIVILEGES ON \`${TEST_DB}\`.* TO '${TEST_USER}'@'%'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
135+
mariadb -e "GRANT ALL PRIVILEGES ON \`${TEST_DB}_scaffold\`.* TO '${TEST_USER}'@'%'" ${HOST_STRING} -u"${USER}" "${PASSWORD_STRING}"
136+
}
105137

106-
if [ "${TYPE}" != "MariaDB" ] && [ "${MAJOR}" -ge 8 ]; then
138+
if [ "${TYPE}" = "MariaDB" ]; then
139+
install_mariadb
140+
elif [ "${MAJOR}" -ge 8 ]; then
107141
install_mysql_db_8_0_plus
108142
else
109143
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,17 +9,20 @@
99
"license": "MIT",
1010
"type": "phpcodesniffer-standard",
1111
"require": {
12-
"php": ">=5.6",
12+
"php": ">=7.2.24",
1313
"behat/behat": "^3.7",
1414
"composer/semver": "^3.4",
1515
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.3 || ^0.5 || ^0.6.2 || ^0.7.1 || ^1.0.0",
1616
"php-parallel-lint/php-console-highlighter": "^1.0",
1717
"php-parallel-lint/php-parallel-lint": "^1.3.1",
18-
"phpcompatibility/php-compatibility": "^9.3.5",
18+
"phpcompatibility/php-compatibility": "dev-develop",
19+
"phpstan/extension-installer": "^1.4.3",
20+
"phpstan/phpstan": "^1.12.26",
21+
"szepeviktor/phpstan-wordpress": "^v1.3.5",
1922
"wp-cli/config-command": "^1 || ^2",
2023
"wp-cli/core-command": "^1 || ^2",
2124
"wp-cli/eval-command": "^1 || ^2",
22-
"wp-cli/wp-cli": "^2.5.1",
25+
"wp-cli/wp-cli": "^2.12",
2326
"wp-coding-standards/wpcs": "^3",
2427
"yoast/phpunit-polyfills": "^1.0.3 || ^2.0.1"
2528
},
@@ -29,9 +32,11 @@
2932
"config": {
3033
"allow-plugins": {
3134
"dealerdirect/phpcodesniffer-composer-installer": true,
32-
"johnpbloch/wordpress-core-installer": true
35+
"johnpbloch/wordpress-core-installer": true,
36+
"phpstan/extension-installer": true
3337
},
34-
"sort-packages": true
38+
"sort-packages": true,
39+
"lock": false
3540
},
3641
"extra": {
3742
"branch-alias": {
@@ -63,19 +68,22 @@
6368
"bin/run-linter-tests",
6469
"bin/run-php-unit-tests",
6570
"bin/run-phpcs-tests",
66-
"bin/run-phpcbf-cleanup"
71+
"bin/run-phpcbf-cleanup",
72+
"bin/run-phpstan-tests"
6773
],
6874
"scripts": {
6975
"behat": "run-behat-tests",
7076
"behat-rerun": "rerun-behat-tests",
7177
"lint": "run-linter-tests",
7278
"phpcs": "run-phpcs-tests",
7379
"phpcbf": "run-phpcbf-cleanup",
80+
"phpstan": "run-phpstan-tests",
7481
"phpunit": "run-php-unit-tests",
7582
"prepare-tests": "install-package-tests",
7683
"test": [
7784
"@lint",
7885
"@phpcs",
86+
"@phpstan",
7987
"@phpunit",
8088
"@behat"
8189
]

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)