Skip to content
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

Add --config-file argument to process custom configuration files #104

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 34 additions & 2 deletions features/config-create.feature
Expand Up @@ -23,6 +23,7 @@ Feature: Create a wp-config file
"""
define( 'WP_DEBUG_LOG', true );
"""

When I run `wp core config {CORE_CONFIG_SETTINGS} --extra-php < wp-config-extra.php`
Then the wp-config.php file should contain:
"""
Expand All @@ -37,6 +38,25 @@ Feature: Create a wp-config file
Then the return code should be 1
And STDERR should not be empty

Given a wp-config-extra.php file:
"""
define( 'WP_DEBUG_LOG', true );
"""

When I run `wp core config {CORE_CONFIG_SETTINGS} --config-file='wp-custom-config.php' --extra-php < wp-config-extra.php`
Then the wp-custom-config.php file should contain:
"""
'AUTH_SALT',
"""
And the wp-custom-config.php file should contain:
"""
define( 'WP_DEBUG_LOG', true );
"""

When I try the previous command again
Then the return code should be 1
And STDERR should not be empty

When I run `wp db create`
Then STDOUT should not be empty

Expand All @@ -50,10 +70,11 @@ Feature: Create a wp-config file
Scenario: No wp-config.php and WPLANG
Given an empty directory
And WP files
Given a wp-config-extra.php file:
And a wp-config-extra.php file:
"""
define( 'WP_DEBUG_LOG', true );
"""

When I run `wp core config {CORE_CONFIG_SETTINGS} --extra-php < wp-config-extra.php`
Then the wp-config.php file should not contain:
"""
Expand Down Expand Up @@ -93,7 +114,7 @@ Feature: Create a wp-config file
When I run `wp core config {CORE_CONFIG_SETTINGS}`
Then the wp-config.php file should contain:
"""
define('AUTH_SALT',
define( 'AUTH_SALT',
"""

Scenario: Define WPLANG when running WP < 4.0
Expand Down Expand Up @@ -123,3 +144,14 @@ Feature: Create a wp-config file
"""
define( 'WPLANG', 'ja' );
"""

When I run `wp core config {CORE_CONFIG_SETTINGS} --config-file=wp-custom-config.php --locale=ja --force`
Then the return code should be 0
And STDOUT should contain:
"""
Success: Generated 'wp-custom-config.php' file.
"""
And the wp-custom-config.php file should contain:
"""
define( 'WPLANG', 'ja' );
"""
124 changes: 120 additions & 4 deletions features/config-delete.feature
@@ -1,9 +1,8 @@
Feature: Delete a constant or variable from the wp-config.php file

Background:
Scenario: Delete an existing wp-config.php constant
Given a WP install
pmbaldha marked this conversation as resolved.
Show resolved Hide resolved

Scenario: Delete an existing wp-config.php constant
When I run `wp config delete DB_PASSWORD`
Then STDOUT should be:
"""
Expand Down Expand Up @@ -43,7 +42,58 @@ Feature: Delete a constant or variable from the wp-config.php file
"""
And STDOUT should be empty

Scenario: Delete a non-existent constant or variable
@custom-config-file
Scenario: Delete an existing wp-custom-config.php constant
Given an empty directory
And WP files

When I run `wp core config {CORE_CONFIG_SETTINGS} --config-file='wp-custom-config.php'`
Then STDOUT should contain:
"""
Generated 'wp-custom-config.php' file.
"""

When I run `wp config delete DB_PASSWORD --config-file='wp-custom-config.php'`
Then STDOUT should be:
"""
Success: Deleted the constant 'DB_PASSWORD' from the 'wp-custom-config.php' file.
"""

When I try `wp config get DB_PASSWORD --config-file='wp-custom-config.php'`
Then STDERR should be:
"""
Error: The constant or variable 'DB_PASSWORD' is not defined in the 'wp-custom-config.php' file.
"""
And STDOUT should be empty

When I run `wp config delete DB_HOST --type=constant --config-file='wp-custom-config.php'`
Then STDOUT should be:
"""
Success: Deleted the constant 'DB_HOST' from the 'wp-custom-config.php' file.
"""

When I try `wp config get DB_HOST --type=constant --config-file='wp-custom-config.php'`
Then STDERR should be:
"""
Error: The constant 'DB_HOST' is not defined in the 'wp-custom-config.php' file.
"""
And STDOUT should be empty

When I run `wp config delete table_prefix --type=variable --config-file='wp-custom-config.php'`
Then STDOUT should be:
"""
Success: Deleted the variable 'table_prefix' from the 'wp-custom-config.php' file.
"""

When I try `wp config get table_prefix --type=variable --config-file='wp-custom-config.php'`
Then STDERR should be:
"""
Error: The variable 'table_prefix' is not defined in the 'wp-custom-config.php' file.
"""
And STDOUT should be empty

Scenario: Delete a non-existent wp-config.php constant or variable
Given a WP install
When I try `wp config delete NEW_CONSTANT`
Then STDERR should be:
"""
Expand All @@ -62,7 +112,38 @@ Feature: Delete a constant or variable from the wp-config.php file
Error: The variable 'NEW_CONSTANT' is not defined in the 'wp-config.php' file.
"""

Scenario: Ambiguous delete requests throw errors
@custom-config-file
Scenario: Delete a non-existent wp-custom-config.php constant or variable
Given an empty directory
And WP files

When I run `wp core config {CORE_CONFIG_SETTINGS} --config-file='wp-custom-config.php'`
Then STDOUT should contain:
"""
Generated 'wp-custom-config.php' file.
"""

When I try `wp config delete NEW_CONSTANT --config-file='wp-custom-config.php'`
Then STDERR should be:
"""
Error: The constant or variable 'NEW_CONSTANT' is not defined in the 'wp-custom-config.php' file.
"""

When I try `wp config delete NEW_CONSTANT --type=constant --config-file='wp-custom-config.php'`
Then STDERR should be:
"""
Error: The constant 'NEW_CONSTANT' is not defined in the 'wp-custom-config.php' file.
"""

When I try `wp config delete NEW_CONSTANT --type=variable --config-file='wp-custom-config.php'`
Then STDERR should be:
"""
Error: The variable 'NEW_CONSTANT' is not defined in the 'wp-custom-config.php' file.
"""

Scenario: Ambiguous delete requests for wp-config.php throw errors
Given a WP install

When I run `wp config set SOME_NAME some_value --type=constant`
Then STDOUT should be:
"""
Expand All @@ -86,3 +167,38 @@ Feature: Delete a constant or variable from the wp-config.php file
"""
Error: Found both a constant and a variable 'SOME_NAME' in the 'wp-config.php' file. Use --type=<type> to disambiguate.
"""

@custom-config-file
Scenario: Ambiguous delete requests for wp-custom-config.php throw errors
Given an empty directory
And WP files

When I run `wp core config {CORE_CONFIG_SETTINGS} --config-file='wp-custom-config.php'`
Then STDOUT should contain:
"""
Generated 'wp-custom-config.php' file.
"""

When I run `wp config set SOME_NAME some_value --type=constant --config-file='wp-custom-config.php'`
Then STDOUT should be:
"""
Success: Added the constant 'SOME_NAME' to the 'wp-custom-config.php' file with the value 'some_value'.
"""

When I run `wp config set SOME_NAME some_value --type=variable --config-file='wp-custom-config.php'`
Then STDOUT should be:
"""
Success: Added the variable 'SOME_NAME' to the 'wp-custom-config.php' file with the value 'some_value'.
"""

When I run `wp config list --fields=name,type SOME_NAME --strict --config-file='wp-custom-config.php'`
Then STDOUT should be a table containing rows:
| name | type |
| SOME_NAME | constant |
| SOME_NAME | variable |

When I try `wp config delete SOME_NAME --config-file='wp-custom-config.php'`
Then STDERR should be:
"""
Error: Found both a constant and a variable 'SOME_NAME' in the 'wp-custom-config.php' file. Use --type=<type> to disambiguate.
"""
29 changes: 29 additions & 0 deletions features/config-edit.feature
@@ -0,0 +1,29 @@
Feature: Edit a wp-config file

Scenario: Edit a wp-config.php file
Given a WP install

When I try `EDITOR='ex -i NONE -c q!' wp config edit;`
Then STDERR should contain:
"""
Warning: No changes made to wp-config.php, aborted.
"""
And the return code should be 0

@custom-config-file
Scenario: Edit a wp-custom-config.php file
Given an empty directory
And WP files

When I run `wp core config {CORE_CONFIG_SETTINGS} --config-file='wp-custom-config.php'`
Then STDOUT should contain:
"""
Generated 'wp-custom-config.php' file.
"""

When I try `EDITOR='ex -i NONE -c q!' wp config edit --config-file=wp-custom-config.php`
Then STDERR should contain:
"""
No changes made to wp-custom-config.php, aborted.
"""
And the return code should be 0