Skip to content

Commit ce06b52

Browse files
authored
fix(support): fix psr-4 namespace path generation with dots and slashes in the composer path (#1166)
1 parent 6b84639 commit ce06b52

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/Tempest/Support/src/Namespace/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function to_psr4_namespace(Psr4Namespace|array $namespaces, Stringable|string $p
5252
->finish('/');
5353

5454
foreach (wrap($namespaces) as $namespace) {
55-
$namespacePath = to_relative_path($root, $namespace->path);
55+
$namespacePath = ltrim(to_relative_path($root, $namespace->path), './');
5656

5757
if ($relativePath->startsWith($namespacePath)) {
5858
return (string) $relativePath

src/Tempest/Support/tests/Namespace/FunctionsTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ public function test_to_namespace(string $path, ?string $root, string $expected)
3131
#[TestWith(['src/Tempest/Auth/src/SomeDirectory', 'Tempest\\Auth\\SomeDirectory'])]
3232
#[TestWith(['/foo/bar/src/Tempest/Auth/src/SomeDirectory', 'Tempest\\Auth\\SomeDirectory', '/foo/bar'])]
3333
public function test_to_composer_namespace(string $path, string $expected, ?string $root = null): void
34+
{
35+
$namespace = new Psr4Namespace('Tempest\\Auth\\', './src/Tempest/Auth/src');
36+
37+
$this->assertSame($expected, to_psr4_namespace([$namespace], $path, $root));
38+
}
39+
40+
#[TestWith(['src/Tempest/Auth/src/SomeNewClass.php', 'Tempest\\Auth'])]
41+
#[TestWith(['src/Tempest/Auth/src/SomeDirectory', 'Tempest\\Auth\\SomeDirectory'])]
42+
#[TestWith(['/foo/bar/src/Tempest/Auth/src/SomeDirectory', 'Tempest\\Auth\\SomeDirectory', '/foo/bar'])]
43+
public function test_to_composer_namespace_without_leading_slashed(string $path, string $expected, ?string $root = null): void
3444
{
3545
$namespace = new Psr4Namespace('Tempest\\Auth\\', 'src/Tempest/Auth/src');
3646

0 commit comments

Comments
 (0)