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

Output a success message if no errors or warnings are found. #689

Merged
merged 5 commits into from
Oct 3, 2024
Merged
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
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.' );
pbiron marked this conversation as resolved.
Show resolved Hide resolved

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
Loading