Permalink
Browse files

Merge pull request #4990 from Danez/patch-2

[Zend-Code] Make sure that a use is only added once in ClassGenerator
  • Loading branch information...
2 parents 5d83f6f + f1247a3 commit 4c31950b0bc45d9127678ed837d94ff9abb3beb6 @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 4c31950

Please sign in to comment.