-
Notifications
You must be signed in to change notification settings - Fork 39
Add wp config add and wp config update commands
#206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4dcb348
Initial plan
Copilot e4db282
Add config add and config update commands with tests
Copilot a233ae9
Add examples for config add and config update in main docblock
Copilot 537ddf8
Fix code review issues: add default type and break statement
Copilot dd07f44
Address PR feedback: fix test assertions and code alignment
Copilot aaace25
Merge branch 'main' into copilot/add-config-add-and-update-commands
swissspidy d3aa0c4
Refactor: Extract option parsing logic into helper method
Copilot 782a901
Merge branch 'main' into copilot/add-config-add-and-update-commands
swissspidy 8056655
PHPStan fix
swissspidy 17e2b4b
PHPStan fixes
swissspidy c98bbae
Merge branch 'main' into copilot/add-config-add-and-update-commands
swissspidy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| Feature: Add a constant or variable to wp-config.php file | ||
|
|
||
| Scenario: Add a new constant to wp-config.php | ||
| Given a WP install | ||
|
|
||
| When I run `wp config add NEW_CONSTANT constant_value` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Added the constant 'NEW_CONSTANT' to the 'wp-config.php' file with the value 'constant_value'. | ||
| """ | ||
|
|
||
| When I run `wp config get NEW_CONSTANT` | ||
| Then STDOUT should be: | ||
| """ | ||
| constant_value | ||
| """ | ||
|
|
||
| Scenario: Add a new variable to wp-config.php | ||
| Given a WP install | ||
|
|
||
| When I run `wp config add new_variable variable_value --type=variable` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Added the variable 'new_variable' to the 'wp-config.php' file with the value 'variable_value'. | ||
| """ | ||
|
|
||
| When I run `wp config get new_variable` | ||
| Then STDOUT should be: | ||
| """ | ||
| variable_value | ||
| """ | ||
|
|
||
| Scenario: Add a raw constant to wp-config.php | ||
| Given a WP install | ||
|
|
||
| When I run `wp config add WP_DEBUG true --raw` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Added the constant 'WP_DEBUG' to the 'wp-config.php' file with the raw value 'true'. | ||
| """ | ||
|
|
||
| When I run `wp config list WP_DEBUG --strict --format=json` | ||
| Then STDOUT should contain: | ||
| """ | ||
| {"name":"WP_DEBUG","value":true,"type":"constant"} | ||
| """ | ||
|
|
||
| Scenario: Fail when trying to add an existing constant | ||
| Given a WP install | ||
|
|
||
| When I run `wp config add TEST_CONSTANT test_value` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Added the constant 'TEST_CONSTANT' to the 'wp-config.php' file with the value 'test_value'. | ||
| """ | ||
|
|
||
| When I try `wp config add TEST_CONSTANT another_value` | ||
| Then STDERR should be: | ||
| """ | ||
| Error: The constant 'TEST_CONSTANT' already exists in the 'wp-config.php' file. | ||
| """ | ||
|
|
||
| Scenario: Fail when trying to add an existing variable | ||
| Given a WP install | ||
|
|
||
| When I run `wp config add test_variable test_value --type=variable` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Added the variable 'test_variable' to the 'wp-config.php' file with the value 'test_value'. | ||
| """ | ||
|
|
||
| When I try `wp config add test_variable another_value --type=variable` | ||
| Then STDERR should be: | ||
| """ | ||
| Error: The variable 'test_variable' already exists in the 'wp-config.php' file. | ||
| """ | ||
|
|
||
| @custom-config-file | ||
| Scenario: Add a new constant to wp-custom-config.php | ||
| Given an empty directory | ||
| And WP files | ||
|
|
||
| When I run `wp config create {CORE_CONFIG_SETTINGS} --skip-check --config-file='wp-custom-config.php'` | ||
| Then STDOUT should contain: | ||
| """ | ||
| Generated 'wp-custom-config.php' file. | ||
| """ | ||
|
|
||
| When I run `wp config add NEW_CONSTANT constant_value --config-file='wp-custom-config.php'` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Added the constant 'NEW_CONSTANT' to the 'wp-custom-config.php' file with the value 'constant_value'. | ||
| """ | ||
|
|
||
| When I run `wp config get NEW_CONSTANT --config-file='wp-custom-config.php'` | ||
| Then STDOUT should be: | ||
| """ | ||
| constant_value | ||
| """ | ||
|
|
||
| Scenario: Additions can be properly placed in wp-config.php | ||
| Given a WP install | ||
| And a wp-config.php file: | ||
| """ | ||
| define( 'CONST_A', 'val-a' ); | ||
| /** ANCHOR */ | ||
| define( 'CONST_B', 'val-b' ); | ||
| require_once( ABSPATH . 'wp-settings.php' ); | ||
| """ | ||
|
|
||
| When I run `wp config add SOME_NAME some_value --anchor="/** ANCHOR */" --placement=before --separator="\n"` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Added the constant 'SOME_NAME' to the 'wp-config.php' file with the value 'some_value'. | ||
| """ | ||
| And the wp-config.php file should be: | ||
| """ | ||
| define( 'CONST_A', 'val-a' ); | ||
| define( 'SOME_NAME', 'some_value' ); | ||
| /** ANCHOR */ | ||
| define( 'CONST_B', 'val-b' ); | ||
| require_once( ABSPATH . 'wp-settings.php' ); | ||
| """ | ||
|
|
||
| When I run `wp config add ANOTHER_NAME another_value --anchor="/** ANCHOR */" --placement=after --separator="\n"` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Added the constant 'ANOTHER_NAME' to the 'wp-config.php' file with the value 'another_value'. | ||
| """ | ||
| And the wp-config.php file should be: | ||
| """ | ||
| define( 'CONST_A', 'val-a' ); | ||
| define( 'SOME_NAME', 'some_value' ); | ||
| /** ANCHOR */ | ||
| define( 'ANOTHER_NAME', 'another_value' ); | ||
| define( 'CONST_B', 'val-b' ); | ||
| require_once( ABSPATH . 'wp-settings.php' ); | ||
| """ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,188 @@ | ||
| Feature: Update or add a constant or variable in wp-config.php file | ||
|
|
||
| Scenario: Update an existing constant in wp-config.php | ||
| Given a WP install | ||
|
|
||
| When I run `wp config update DB_HOST db.example.com` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Updated the constant 'DB_HOST' in the 'wp-config.php' file with the value 'db.example.com'. | ||
| """ | ||
|
|
||
| When I run `wp config get DB_HOST` | ||
| Then STDOUT should be: | ||
| """ | ||
| db.example.com | ||
| """ | ||
|
|
||
| Scenario: Add a new constant when it doesn't exist | ||
| Given a WP install | ||
|
|
||
| When I run `wp config update NEW_CONSTANT constant_value` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Added the constant 'NEW_CONSTANT' to the 'wp-config.php' file with the value 'constant_value'. | ||
| """ | ||
|
|
||
| When I run `wp config get NEW_CONSTANT` | ||
| Then STDOUT should be: | ||
| """ | ||
| constant_value | ||
| """ | ||
|
|
||
| Scenario: Update an existing constant then add it again | ||
| Given a WP install | ||
|
|
||
| When I run `wp config update TEST_CONSTANT first_value` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Added the constant 'TEST_CONSTANT' to the 'wp-config.php' file with the value 'first_value'. | ||
| """ | ||
|
|
||
| When I run `wp config update TEST_CONSTANT second_value` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Updated the constant 'TEST_CONSTANT' in the 'wp-config.php' file with the value 'second_value'. | ||
| """ | ||
|
|
||
| When I run `wp config get TEST_CONSTANT` | ||
| Then STDOUT should be: | ||
| """ | ||
| second_value | ||
| """ | ||
|
|
||
| Scenario: Update a variable with --type=variable | ||
| Given a WP install | ||
|
|
||
| When I run `wp config update new_variable variable_value --type=variable` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Added the variable 'new_variable' to the 'wp-config.php' file with the value 'variable_value'. | ||
| """ | ||
|
|
||
| When I run `wp config update new_variable updated_value --type=variable` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Updated the variable 'new_variable' in the 'wp-config.php' file with the value 'updated_value'. | ||
| """ | ||
|
|
||
| When I run `wp config get new_variable` | ||
| Then STDOUT should be: | ||
| """ | ||
| updated_value | ||
| """ | ||
|
|
||
| Scenario: Update raw values in wp-config.php | ||
| Given a WP install | ||
|
|
||
| When I run `wp config update WP_DEBUG true --raw` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Added the constant 'WP_DEBUG' to the 'wp-config.php' file with the raw value 'true'. | ||
|
swissspidy marked this conversation as resolved.
Outdated
|
||
| """ | ||
|
|
||
| When I run `wp config list WP_DEBUG --strict --format=json` | ||
| Then STDOUT should contain: | ||
| """ | ||
| {"name":"WP_DEBUG","value":true,"type":"constant"} | ||
| """ | ||
|
|
||
| When I run `wp config update WP_DEBUG false --raw` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Updated the constant 'WP_DEBUG' in the 'wp-config.php' file with the raw value 'false'. | ||
| """ | ||
|
|
||
| When I run `wp config list WP_DEBUG --strict --format=json` | ||
| Then STDOUT should contain: | ||
| """ | ||
| {"name":"WP_DEBUG","value":false,"type":"constant"} | ||
| """ | ||
|
|
||
| @custom-config-file | ||
| Scenario: Update a constant in wp-custom-config.php | ||
| Given an empty directory | ||
| And WP files | ||
|
|
||
| When I run `wp config create {CORE_CONFIG_SETTINGS} --skip-check --config-file='wp-custom-config.php'` | ||
| Then STDOUT should contain: | ||
| """ | ||
| Generated 'wp-custom-config.php' file. | ||
| """ | ||
|
|
||
| When I run `wp config update DB_HOST db.example.com --config-file='wp-custom-config.php'` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Updated the constant 'DB_HOST' in the 'wp-custom-config.php' file with the value 'db.example.com'. | ||
| """ | ||
|
|
||
| When I run `wp config get DB_HOST --config-file='wp-custom-config.php'` | ||
| Then STDOUT should be: | ||
| """ | ||
| db.example.com | ||
| """ | ||
|
|
||
| Scenario: Ambiguous update requests throw errors | ||
| Given a WP install | ||
|
|
||
| When I run `wp config update SOME_NAME some_value --type=constant` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Added the constant 'SOME_NAME' to the 'wp-config.php' file with the value 'some_value'. | ||
| """ | ||
|
|
||
| When I run `wp config update SOME_NAME some_value --type=variable` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Added the variable 'SOME_NAME' to the 'wp-config.php' file with the value 'some_value'. | ||
| """ | ||
|
|
||
| When I run `wp config list --fields=name,type SOME_NAME --strict` | ||
| Then STDOUT should be a table containing rows: | ||
| | name | type | | ||
| | SOME_NAME | constant | | ||
| | SOME_NAME | variable | | ||
|
|
||
| When I try `wp config update SOME_NAME some_value` | ||
| Then STDERR should be: | ||
| """ | ||
| Error: Found both a constant and a variable 'SOME_NAME' in the 'wp-config.php' file. Use --type=<type> to disambiguate. | ||
| """ | ||
|
|
||
| Scenario: Update with placement options for new constants | ||
| Given a WP install | ||
| And a wp-config.php file: | ||
| """ | ||
| define( 'CONST_A', 'val-a' ); | ||
| /** ANCHOR */ | ||
| define( 'CONST_B', 'val-b' ); | ||
| require_once( ABSPATH . 'wp-settings.php' ); | ||
| """ | ||
|
|
||
| When I run `wp config update SOME_NAME some_value --anchor="/** ANCHOR */" --placement=before --separator="\n"` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Added the constant 'SOME_NAME' to the 'wp-config.php' file with the value 'some_value'. | ||
| """ | ||
| And the wp-config.php file should be: | ||
| """ | ||
| define( 'CONST_A', 'val-a' ); | ||
| define( 'SOME_NAME', 'some_value' ); | ||
| /** ANCHOR */ | ||
| define( 'CONST_B', 'val-b' ); | ||
| require_once( ABSPATH . 'wp-settings.php' ); | ||
| """ | ||
|
|
||
| When I run `wp config update SOME_NAME updated_value --anchor="/** ANCHOR */" --placement=before --separator="\n"` | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: Updated the constant 'SOME_NAME' in the 'wp-config.php' file with the value 'updated_value'. | ||
| """ | ||
| And the wp-config.php file should be: | ||
| """ | ||
| define( 'CONST_A', 'val-a' ); | ||
| define( 'SOME_NAME', 'updated_value' ); | ||
| /** ANCHOR */ | ||
| define( 'CONST_B', 'val-b' ); | ||
| require_once( ABSPATH . 'wp-settings.php' ); | ||
| """ | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.