Skip to content

Commit 1e232ab

Browse files
committed
Ensure class names are unqiue
1 parent fd360d8 commit 1e232ab

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lib/Domain/ClassNameCandidates.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static function fromClassNames(array $classNames)
2020

2121
public function getIterator()
2222
{
23-
return new \ArrayIterator($this->classNames);
23+
return new \ArrayIterator(array_values($this->classNames));
2424
}
2525

2626
public function noneFound(): bool
@@ -41,6 +41,6 @@ public function best(): ClassName
4141

4242
private function add(ClassName $className)
4343
{
44-
$this->classNames[] = $className;
44+
$this->classNames[$className->__toString()] = $className;
4545
}
4646
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace Phpactor\ClassFileConverter\Tests\Unit\Domain;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Phpactor\ClassFileConverter\Domain\ClassName;
7+
use Phpactor\ClassFileConverter\Domain\ClassNameCandidates;
8+
9+
class ClassNameCandidatesTest extends TestCase
10+
{
11+
public function testEnsuresClassNamesAreUnique()
12+
{
13+
$candidates = ClassNameCandidates::fromClassNames([
14+
ClassName::fromString('Foobar'),
15+
ClassName::fromString('Foobar'),
16+
ClassName::fromString('Barfoo'),
17+
]);
18+
19+
self::assertCount(2, $candidates);
20+
}
21+
}

0 commit comments

Comments
 (0)