|
| 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 run `wp cli check-update` |
| 81 | + Then STDOUT should be a table containing rows: |
| 82 | + | version | update_type | package_url | |
| 83 | + | 999.9.9 | major | https://github.com/wp-cli/wp-cli/releases/download/v999.9.9/wp-cli-999.9.9.phar | |
| 84 | + |
| 85 | + Scenario: Mock HTTP request in WordPress |
| 86 | + Given a WP install |
| 87 | + And that HTTP requests to https://api.wordpress.org/core/version-check/1.7/ will respond with: |
| 88 | + """ |
| 89 | + HTTP/1.1 200 |
| 90 | + Content-Type: application/json |
| 91 | +
|
| 92 | + { |
| 93 | + "offers": [ |
| 94 | + { |
| 95 | + "response": "latest", |
| 96 | + "download": "https:\/\/downloads.wordpress.org\/release\/wordpress-999.9.9.zip", |
| 97 | + "locale": "en_US", |
| 98 | + "packages": { |
| 99 | + "full": "https:\/\/downloads.wordpress.org\/release\/wordpress-999.9.9.zip", |
| 100 | + "no_content": "https:\/\/downloads.wordpress.org\/release\/wordpress-999.9.9-no-content.zip", |
| 101 | + "new_bundled": "https:\/\/downloads.wordpress.org\/release\/wordpress-999.9.9-new-bundled.zip", |
| 102 | + "partial": false, |
| 103 | + "rollback": false |
| 104 | + }, |
| 105 | + "current": "999.9.9", |
| 106 | + "version": "999.9.9", |
| 107 | + "php_version": "7.2.24", |
| 108 | + "mysql_version": "5.5.5", |
| 109 | + "new_bundled": "6.7", |
| 110 | + "partial_version": false |
| 111 | + } |
| 112 | + ], |
| 113 | + "translations": [] |
| 114 | + } |
| 115 | + """ |
| 116 | + |
| 117 | + When I run `wp core check-update` |
| 118 | + Then STDOUT should be a table containing rows: |
| 119 | + | version | update_type | package_url | |
| 120 | + | 999.9.9 | major | https://downloads.wordpress.org/release/wordpress-999.9.9.zip | |
0 commit comments