Skip to content

Commit

Permalink
Merge pull request #689 from pbiron/cli-success-message
Browse files Browse the repository at this point in the history
Output a success message if no errors or warnings are found.
  • Loading branch information
davidperezgar authored Oct 3, 2024
2 parents 3be27d8 + b95c51e commit 083cd22
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
6 changes: 6 additions & 0 deletions includes/CLI/Plugin_Check_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,12 @@ static function ( $dirs ) use ( $excluded_files ) {
$warnings = $result->get_warnings();
}

if ( empty( $errors ) && empty( $warnings ) ) {
WP_CLI::success( __( 'Checks complete. No errors found.', 'plugin-check' ) );

return;
}

// Default fields.
$default_fields = $this->get_check_default_fields( $assoc_args );

Expand Down
35 changes: 34 additions & 1 deletion tests/behat/features/plugin-check.feature
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ Feature: Test that the WP-CLI command works.
"""

When I run the WP-CLI command `plugin check foo-single.php --ignore-errors`
Then STDOUT should be empty
Then STDOUT should contain:
"""
Success: Checks complete. No errors found.
"""

When I run the WP-CLI command `plugin check foo-single.php --ignore-warnings`
Then STDOUT should not be empty
Expand Down Expand Up @@ -598,3 +601,33 @@ Feature: Test that the WP-CLI command works.
# """
# ExampleRuntimeCheck.ForbiddenScript,WARNING
# """

Scenario: Check custom single file plugin that has no errors or warnings
Given a WP install with the Plugin Check plugin
And a wp-content/plugins/foo-single.php file:
"""
<?php
/**
* Plugin Name: Foo Single
* Plugin URI: https://foo-single.com
* Description: Custom plugin.
* Version: 0.1.0
* Author: WordPress Performance Team
* Author URI: https://make.wordpress.org/performance/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
add_action(
'init',
function () {
echo esc_html( 'this is a test.' );
}
);
"""

When I run the WP-CLI command `plugin check foo-single.php`
Then STDOUT should contain:
"""
Success: Checks complete. No errors found.
"""
3 changes: 3 additions & 0 deletions tests/phpstan/stubs/wp-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ public static function error( $text ) {

public static function warning( $text ) {
}

public static function success( $text ) {
}
}
}

Expand Down

0 comments on commit 083cd22

Please sign in to comment.