Add --all flag for plugin uninstall command#84
Conversation
|
I think the test is not failing because of my changes. It's showing error from |
src/Plugin_Command.php
Outdated
| * will be run. | ||
| * | ||
| * [--all] | ||
| * : If set, all deactive plugins will be uninstalled. |
There was a problem hiding this comment.
Don't need deactive, as the --deactivate option covers that.
features/plugin-uninstall.feature
Outdated
| Then STDOUT should be: | ||
| """ | ||
| Uninstalled and deleted 'akismet' plugin. | ||
| Uninstalled and deleted 'hello.php' plugin. |
There was a problem hiding this comment.
This will change to 'hello' - see below re using check_optional_args_and_all().
There was a problem hiding this comment.
It's giving me error in testing if I make it hello.
features/plugin-uninstall.feature
Outdated
| """ | ||
| And the return code should be 0 | ||
|
|
||
| Scenario: Uninstall all installed plugin |
There was a problem hiding this comment.
Typo 'plugin' -> 'plugins'.
| Uninstalled and deleted 'hello.php' plugin. | ||
| Success: Uninstalled 2 of 2 plugins. | ||
| """ | ||
| And the return code should be 0 |
There was a problem hiding this comment.
Also should maybe do When I run the previous command again step here with STDOUT Success: No plugins installed..
Also add scenario Uninstall all installed plugins when one or more activated with one plugin activated and run without and with --deactivate flag.
There was a problem hiding this comment.
@gitlost I am having some problem with this test. Can you please check.
src/Plugin_Command.php
Outdated
| $plugins = $this->fetcher->get_many( $args ); | ||
|
|
||
| // If get all parameter from command, then uninstall all deactive plugins. | ||
| if ( $all ) { |
src/Plugin_Command.php
Outdated
| } | ||
| if ( ! $this->chained_command ) { | ||
| Utils\report_batch_operation_results( 'plugin', 'uninstall', count( $args ), $successes, $errors ); | ||
| Utils\report_batch_operation_results( 'plugin', 'uninstall', count( $plugins ), $successes, $errors ); |
There was a problem hiding this comment.
And this change isn't needed (if the if ( count( $plugins ) < count( $args ) ) { logic above is put in).
| $successes = $errors = 0; | ||
|
|
||
| $all = Utils\get_flag_value( $assoc_args, 'all', false ); | ||
|
|
There was a problem hiding this comment.
Could you do
if ( ! ( $args = $this->check_optional_args_and_all( $args, $all ) ) ) {
return;
}
here. This will mean the if ( $all ) { block isn't needed.
src/Plugin_Command.php
Outdated
| $all = Utils\get_flag_value( $assoc_args, 'all', false ); | ||
|
|
||
| $plugins = $this->fetcher->get_many( $args ); | ||
|
|
There was a problem hiding this comment.
Hmm, the other --all commands do this logic after fetching:
if ( count( $plugins ) < count( $args ) ) {
$errors = count( $args ) - count( $plugins );
}
which looks like it should be done here too but causes for instance features/plugin-uninstall.feature:28 to fail with Error: No plugins uninstalled. instead of succeeding with Success: Plugin already uninstalled.. And also the final step of features/plugin.feature:3. So this would be a BC break. But maybe the right thing to do anyway...
|
Ah, so you have to do your review comments in code order, not very second-thoughts friendly... |
|
@gitlost See this. |
|
@BhargavBhandari90 When you run a test that expects an error to be thrown, like it is the case here, you need to use |
src/Plugin_Command.php
Outdated
| } | ||
|
|
||
| // If get all parameter from command, then uninstall all deactive plugins. | ||
| if ( $all ) { |
There was a problem hiding this comment.
This block should be removed as it isn't needed after setting the args with check_optional_args_and_all().
This will then change the name of hello.php to hello.
features/plugin-uninstall.feature
Outdated
| """ | ||
| Success: Activated 2 of 2 plugins. | ||
| """ | ||
| And I run `wp plugin uninstall --all` |
There was a problem hiding this comment.
As @schlessera mentioned need this to be When I try as it will fail without the --deactivate flag. Then have another successful step with the --deactivate flag.
|
The other failures happening are due to the BC break and are mentioned here #84 (comment). So those tests will have to be adjusted (assuming everyone's ok with the BC break). |
features/plugin-uninstall.feature
Outdated
|
|
||
| Scenario: Attempting to uninstall a plugin that doesn't exist | ||
| When I try `wp plugin uninstall edit-flow` | ||
| And STDERR should be: |
features/plugin-uninstall.feature
Outdated
| When I run the previous command again | ||
| Then STDOUT should be: | ||
| """ | ||
| Success: No plugins installed. |
There was a problem hiding this comment.
No plugins installed => No plugins uninstalled
There was a problem hiding this comment.
This will require a change to the check_args_and_all() method, as the installed is currently hardcoded in there.
There was a problem hiding this comment.
@schlessera I did little different for this. Let me know if this solution is good or not.
features/plugin-uninstall.feature
Outdated
| """ | ||
|
|
||
| Scenario: Uninstall all installed plugins when one or more activated | ||
| And I run `wp plugin activate --all` |
features/plugin-uninstall.feature
Outdated
| """ | ||
| Success: Activated 2 of 2 plugins. | ||
| """ | ||
| And I try `wp plugin uninstall --all` |
features/plugin-uninstall.feature
Outdated
| Success: Activated 2 of 2 plugins. | ||
| """ | ||
| And I try `wp plugin uninstall --all` | ||
| And STDERR should be: |
features/plugin-uninstall.feature
Outdated
| Error: No plugins uninstalled. | ||
| """ | ||
| And the return code should be 1 | ||
| And I run `wp plugin uninstall --deactivate --all` |
|
@BhargavBhandari90 I've added a few change requests. For the basic tests setup, it should always read like normal sentences: |
|
@schlessera, Done with the changes. Please review. |
|
Thanks for the PR, @BhargavBhandari90 ! |

for #75