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

Fix path in CLI output #615

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from
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
14 changes: 11 additions & 3 deletions includes/Checker/Abstract_Check_Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ private function get_check_exclude_slugs() {
* @since 1.0.0
*
* @return string The plugin basename to check.
*
* @throws Exception Thrown if an plugin basename could not be set.
*/
final public function get_plugin_basename() {
if ( null === $this->plugin_basename ) {
Expand All @@ -550,10 +552,16 @@ final public function get_plugin_basename() {
$this->plugin_basename = Plugin_Request_Utility::download_plugin( $plugin );

$this->delete_plugin_folder = true;
} elseif ( Plugin_Request_Utility::is_directory_valid_plugin( $plugin ) ) {
$this->plugin_basename = $plugin;
} else {
$this->plugin_basename = Plugin_Request_Utility::get_plugin_basename_from_input( $plugin );
try {
$this->plugin_basename = Plugin_Request_Utility::get_plugin_basename_from_input( $plugin );
} catch ( Exception $exception ) {
if ( Plugin_Request_Utility::is_directory_valid_plugin( $plugin ) ) {
$this->plugin_basename = $plugin;
} else {
throw $exception;
}
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions includes/Plugin_Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public function __construct( $main_file ) {
}
}
}

$this->main_file = $this->main_file;
Comment on lines +70 to +71
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debugging leftover?

}

/**
Expand Down Expand Up @@ -101,9 +103,9 @@ public function main_file() {
*/
public function path( $relative_path = '/' ) {
if ( is_dir( $this->main_file ) ) {
return trailingslashit( $this->main_file ) . ltrim( $relative_path, '/' );
return realpath( trailingslashit( $this->main_file ) . ltrim( $relative_path, '/' ) );
} else {
return plugin_dir_path( $this->main_file ) . ltrim( $relative_path, '/' );
return realpath( plugin_dir_path( $this->main_file ) . ltrim( $relative_path, '/' ) );
}
}

Expand Down
3 changes: 1 addition & 2 deletions includes/Traits/Amend_Check_Result.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ trait Amend_Check_Result {
* @param int $severity Severity level. Default is 5.
*/
protected function add_result_message_for_file( Check_Result $result, $error, $message, $code, $file, $line = 0, $column = 0, string $docs = '', $severity = 5 ) {

$result->add_message(
(bool) $error,
$message,
array(
'code' => $code,
'file' => str_replace( $result->plugin()->path(), '', $file ),
'file' => str_replace( trailingslashit( $result->plugin()->path() ), '', $file ),
'line' => $line,
'column' => $column,
'link' => $this->get_file_editor_url( $result, $file, $line ),
Expand Down
4 changes: 4 additions & 0 deletions tests/behat/features/plugin-check-remote.feature
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Feature: Test that the WP-CLI plugin check command works with remote ZIP url.
Scenario: Test with valid ZIP
When I run the WP-CLI command `plugin check https://github.com/WordPress/plugin-check/raw/trunk/tests/behat/testdata/foo-bar-wp.zip --fields=code,type --format=csv`
Then STDOUT should contain:
"""
FILE: foo-bar-wp.php
"""
And STDOUT should contain:
"""
WordPress.WP.AlternativeFunctions.rand_mt_rand,ERROR
"""
Expand Down
4 changes: 4 additions & 0 deletions tests/behat/features/plugin-check-severity.feature
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Feature: Test that the severity level in plugin check works.

When I run the WP-CLI command `plugin check foo-bar-wp --format=csv --fields=code,type,severity`
Then STDOUT should contain:
"""
FILE: foo-bar-wp.php
"""
And STDOUT should contain:
"""
allow_unfiltered_uploads_detected,ERROR,7
"""
Expand Down
Loading