Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
10 changes: 10 additions & 0 deletions src/Plugin_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,16 @@
$message = wp_strip_all_tags( $message );
$message = str_replace( 'Error: ', '', $message );
WP_CLI::warning( "Failed to activate plugin. {$message}" );
// If the error is due to unexpected output, display it for debugging
if ( 'unexpected_output' === $result->get_error_code() ) {
/**
* @var string $output
*/

Check failure on line 408 in src/Plugin_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

Whitespace found at end of line
$output = $result->get_error_data();
if ( ! empty( $output ) ) {
WP_CLI::debug( "Unexpected output: {$output}", 'plugin' );
}
}
++$errors;
} else {
$this->active_output( $plugin->name, $plugin->file, $network_wide, 'activate' );
Expand Down
Loading