Permalink
Browse files

Merge branch 'hotfix/4990'

Close #4990
  • Loading branch information...
2 parents 5d83f6f + 4c31950 commit fdf7e16b17654597b368b997afbea46c27f82327 @weierophinney weierophinney committed Aug 21, 2013
@@ -490,7 +490,7 @@ public function addUse($use, $useAlias = null)
$use .= ' as ' . $useAlias;
}
- $this->uses[] = $use;
+ $this->uses[$use] = $use;
return $this;
}
@@ -524,7 +524,7 @@ public function getProperty($propertyName)
*/
public function getUses()
{
- return $this->uses;
+ return array_values($this->uses);
}
/**
@@ -378,6 +378,38 @@ public function testAddUses()
$this->assertContains('use My\Second\Use\Class as MyAlias;', $generated);
}
+ /**
+ * @group gh-4990
+ */
+ public function testAddOneUseTwiceOnlyAddsOne()
+ {
+ $classGenerator = new ClassGenerator();
+ $classGenerator->setName('My\Class');
+ $classGenerator->addUse('My\First\Use\Class');
+ $classGenerator->addUse('My\First\Use\Class');
+ $generated = $classGenerator->generate();
+
+ $this->assertCount(1, $classGenerator->getUses());
+
+ $this->assertContains('use My\First\Use\Class;', $generated);
+ }
+
+ /**
+ * @group gh-4990
+ */
+ public function testAddOneUseWithAliasTwiceOnlyAddsOne()
+ {
+ $classGenerator = new ClassGenerator();
+ $classGenerator->setName('My\Class');
+ $classGenerator->addUse('My\First\Use\Class', 'MyAlias');
+ $classGenerator->addUse('My\First\Use\Class', 'MyAlias');
+ $generated = $classGenerator->generate();
+
+ $this->assertCount(1, $classGenerator->getUses());
+
+ $this->assertContains('use My\First\Use\Class as MyAlias;', $generated);
+ }
+
public function testCreateFromArrayWithDocBlockFromArray()
{
$classGenerator = ClassGenerator::fromArray(array(

0 comments on commit fdf7e16

Please sign in to comment.