Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions features/plugin-activate.feature
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,26 @@ Feature: Activate WordPress plugins
Success:
"""
And the return code should be 0

Scenario: Activating a plugin that generates unexpected output shows the output in debug mode
Given a wp-content/plugins/output-plugin.php file:
"""
<?php
/**
* Plugin Name: Output Plugin
* Description: This plugin generates unexpected output during activation
* Author: WP-CLI tests
*/
echo "Unexpected output from plugin activation";
"""

When I try `wp plugin activate output-plugin --debug`
Then STDERR should contain:
"""
Warning: Failed to activate plugin. The plugin generated unexpected output.
"""
And STDERR should contain:
"""
Debug (plugin): Unexpected output: Unexpected output from plugin activation
"""
And the return code should be 1
8 changes: 8 additions & 0 deletions src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,14 @@
$message = wp_strip_all_tags( $message );
$message = str_replace( 'Error: ', '', $message );
WP_CLI::warning( "Failed to activate plugin. {$message}" );

Check failure on line 404 in src/Plugin_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

Whitespace found at end of line

Check failure on line 404 in src/Plugin_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

Whitespace found at end of line
// If the error is due to unexpected output, display it for debugging
if ( 'unexpected_output' === $result->get_error_code() ) {
$output = $result->get_error_data();
if ( ! empty( $output ) ) {
WP_CLI::debug( "Unexpected output: {$output}", 'plugin' );

Check failure on line 409 in src/Plugin_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPStan

Part $output (mixed) of encapsed string cannot be cast to string.

Check failure on line 409 in src/Plugin_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPStan

Part $output (mixed) of encapsed string cannot be cast to string.
}
}
++$errors;
} else {
$this->active_output( $plugin->name, $plugin->file, $network_wide, 'activate' );
Expand Down
Loading