Skip to content

Commit

Permalink
ClassName::fromString(): trim leading namespace separator
Browse files Browse the repository at this point in the history
  • Loading branch information
__ committed Jan 24, 2024
1 parent 290dabd commit 9cd3b19
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Domain/ClassName.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __toString()
public static function fromString(string $string): self
{
$new = new self();
$new->fullyQualifiedName = $string;
$new->fullyQualifiedName = ltrim($string, self::DEFAULT_NAMESPACE_SEPARATOR);

return $new;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/Integration/Simple/SimpleClassToFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ public function testClassToFile(): void
]), $candidates);
}

public function testAbsoluteClassNameToFile(): void
{
$candidates = $this->classToFile->classToFileCandidates(ClassName::fromString('\\Acme\\Foobar'));

$this->assertEquals(FilePathCandidates::fromFilePaths([
FilePath::fromString(__DIR__ . '/../../Workspace/lib/Foobar.php')
]), $candidates);
}

public function testClassToFileInvalid(): void
{
$candidates = $this->classToFile->classToFileCandidates(
Expand Down
5 changes: 5 additions & 0 deletions tests/Unit/ClassNameTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public function provideBeginsWith()
'Foobar',
true,
],
[
'\\Foobar\\BarFoo',
'Foobar\\BarFoo',
true,
],
[
'Foobar\\BarFoo',
'Foobar\\BarFoo',
Expand Down

0 comments on commit 9cd3b19

Please sign in to comment.