Skip to content

Commit 5ac3863

Browse files
Copilotswissspidy
andcommitted
Improve tests to actually verify environment variables are set
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 386d5e5 commit 5ac3863

3 files changed

Lines changed: 97 additions & 24 deletions

File tree

features/package-install.feature

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ Feature: Install WP-CLI packages
12631263
"""
12641264
And STDOUT should be empty
12651265
1266-
Scenario: Install a package with --no-interaction flag
1266+
Scenario: Install a package with --no-interaction flag sets environment variables
12671267
Given an empty directory
12681268
And a composer.json file:
12691269
"""
@@ -1284,11 +1284,25 @@ Feature: Install WP-CLI packages
12841284
"""
12851285
{
12861286
"name": "wp-cli/restful",
1287-
"description": "Test package for no-interaction flag"
1287+
"description": "Test package for no-interaction flag",
1288+
"scripts": {
1289+
"post-install-cmd": [
1290+
"@php -r \"echo 'GIT_TERMINAL_PROMPT=' . getenv('GIT_TERMINAL_PROMPT') . PHP_EOL;\"",
1291+
"@php -r \"echo 'GIT_SSH_COMMAND=' . getenv('GIT_SSH_COMMAND') . PHP_EOL;\""
1292+
]
1293+
}
12881294
}
12891295
"""
12901296
When I run `WP_CLI_PACKAGES_DIR=. wp package install wp-cli/restful --no-interaction`
12911297
Then STDOUT should contain:
1298+
"""
1299+
GIT_TERMINAL_PROMPT=0
1300+
"""
1301+
And STDOUT should contain:
1302+
"""
1303+
GIT_SSH_COMMAND=ssh -o BatchMode=yes
1304+
"""
1305+
And STDOUT should contain:
12921306
"""
12931307
Success: Package installed
12941308
"""

features/package-update.feature

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,22 +195,51 @@ Feature: Update WP-CLI packages
195195
"""
196196
And the return code should be 1
197197

198-
Scenario: Update packages with --no-interaction flag
198+
Scenario: Update packages with --no-interaction flag sets environment variables
199199
Given an empty directory
200-
201-
When I run `wp package install danielbachhuber/wp-cli-reset-post-date-command`
202-
Then STDOUT should contain:
203-
"""
204-
Success: Package installed.
200+
And a composer.json file:
201+
"""
202+
{
203+
"repositories": {
204+
"test" : {
205+
"type": "path",
206+
"url": "./dummy-package/"
207+
},
208+
"wp-cli": {
209+
"type": "composer",
210+
"url": "https://wp-cli.org/package-index/"
211+
}
212+
},
213+
"require": {
214+
"wp-cli/restful": "*"
215+
}
216+
}
217+
"""
218+
And a dummy-package/composer.json file:
219+
"""
220+
{
221+
"name": "wp-cli/restful",
222+
"version": "1.0.0",
223+
"description": "Test package for no-interaction flag",
224+
"scripts": {
225+
"post-update-cmd": [
226+
"@php -r \"echo 'GIT_TERMINAL_PROMPT=' . getenv('GIT_TERMINAL_PROMPT') . PHP_EOL;\"",
227+
"@php -r \"echo 'GIT_SSH_COMMAND=' . getenv('GIT_SSH_COMMAND') . PHP_EOL;\""
228+
]
229+
}
230+
}
231+
"""
232+
233+
When I run `WP_CLI_PACKAGES_DIR=. wp package update --no-interaction`
234+
Then STDOUT should contain:
235+
"""
236+
GIT_TERMINAL_PROMPT=0
205237
"""
206-
207-
When I run `wp package update --no-interaction`
208-
Then STDOUT should contain:
238+
And STDOUT should contain:
209239
"""
210-
Using Composer to update packages...
240+
GIT_SSH_COMMAND=ssh -o BatchMode=yes
211241
"""
212242
And STDOUT should contain:
213243
"""
214244
Packages updated.
215245
"""
216-
And STDERR should be empty

features/package.feature

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,23 +209,53 @@ Feature: Manage WP-CLI packages
209209
{NO_SUCH_PACKAGE_COMPOSER_JSON}
210210
"""
211211

212-
Scenario: Uninstall a package with --no-interaction flag
212+
Scenario: Uninstall a package with --no-interaction flag sets environment variables
213213
Given an empty directory
214+
And a composer.json file:
215+
"""
216+
{
217+
"repositories": {
218+
"test" : {
219+
"type": "path",
220+
"url": "./dummy-package/"
221+
},
222+
"wp-cli": {
223+
"type": "composer",
224+
"url": "https://wp-cli.org/package-index/"
225+
}
226+
},
227+
"require": {
228+
"wp-cli/restful": "*"
229+
}
230+
}
231+
"""
232+
And a dummy-package/composer.json file:
233+
"""
234+
{
235+
"name": "wp-cli/restful",
236+
"version": "1.0.0",
237+
"description": "Test package for no-interaction flag",
238+
"scripts": {
239+
"pre-uninstall-cmd": [
240+
"@php -r \"echo 'GIT_TERMINAL_PROMPT=' . getenv('GIT_TERMINAL_PROMPT') . PHP_EOL;\"",
241+
"@php -r \"echo 'GIT_SSH_COMMAND=' . getenv('GIT_SSH_COMMAND') . PHP_EOL;\""
242+
]
243+
}
244+
}
245+
"""
214246

215-
When I run `wp package install runcommand/hook`
216-
Then STDERR should be empty
217-
218-
When I run `wp package uninstall runcommand/hook --no-interaction`
219-
Then STDERR should be empty
247+
When I run `WP_CLI_PACKAGES_DIR=. wp package uninstall wp-cli/restful --no-interaction`
248+
Then STDOUT should contain:
249+
"""
250+
GIT_TERMINAL_PROMPT=0
251+
"""
220252
And STDOUT should contain:
221253
"""
222-
Success: Uninstalled package.
254+
GIT_SSH_COMMAND=ssh -o BatchMode=yes
223255
"""
224-
225-
When I run `wp package list`
226-
Then STDOUT should not contain:
256+
And STDOUT should contain:
227257
"""
228-
runcommand/hook
258+
Success: Uninstalled package.
229259
"""
230260

231261
Scenario: List packages with --skip-update-check flag

0 commit comments

Comments
 (0)