Skip to content

Commit

Permalink
Test realpath
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Sep 9, 2024
1 parent 9d72214 commit 14f4100
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions includes/Plugin_Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public function __construct( $main_file ) {
);
}

$this->main_file = realpath( $this->main_file );

if ( false === strpos( $this->main_file, '.php' ) ) {
$files = glob( $this->main_file . '/*.php' );
foreach ( $files as $file ) {
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 trailingslashit( realpath( $this->main_file ) ) . ltrim( $relative_path, '/' );

Check warning on line 106 in includes/Plugin_Context.php

View check run for this annotation

Codecov / codecov/patch

includes/Plugin_Context.php#L106

Added line #L106 was not covered by tests
} else {
return plugin_dir_path( $this->main_file ) . ltrim( $relative_path, '/' );
return plugin_dir_path( trailingslashit( realpath( $this->main_file ) ) ) . ltrim( $relative_path, '/' );
}
}

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

0 comments on commit 14f4100

Please sign in to comment.