Skip to content

Commit

Permalink
fix(core): Path::getRelativePath() will return correct path when `$…
Browse files Browse the repository at this point in the history
…root` is file.
  • Loading branch information
LastDragon-ru committed May 26, 2024
1 parent 2fdac35 commit 9478b44
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/core/src/Utils/Path.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public static function getPath(string $root, string $path): string {
}

public static function getRelativePath(string $root, string $path): string {
$path = static::isRelative($path)
? static::join(static::getDirname($root), $path)
: $path;
$root = static::getDirname($root);
$path = static::isRelative($path) ? static::join($root, $path) : $path;
$path = SymfonyPath::makeRelative($path, $root);
$path = static::normalize($path);

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/Utils/PathTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use LastDragon_ru\LaraASP\Core\Testing\Package\TestCase;
use PHPUnit\Framework\Attributes\CoversClass;

use function basename;
use function dirname;
use function str_replace;

Expand All @@ -25,6 +26,7 @@ public function testGetPath(): void {
public function testGetRelativePath(): void {
self::assertEquals('../to/file', Path::getRelativePath('/any/path', '/any/path/../to/file'));
self::assertEquals('to/file', Path::getRelativePath('/absolute/path', 'to/./file'));
self::assertEquals(basename(__FILE__), Path::getRelativePath(__FILE__, __FILE__));
}

public function testJoin(): void {
Expand Down

0 comments on commit 9478b44

Please sign in to comment.