Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'hotfix/4990' into develop

Forward port #4990
  • Loading branch information...
commit 7be43e3fca6dd767df5d7f4bcf69e800e88411cc 2 parents 8fcbe7b + 4c31950
@weierophinney weierophinney authored
View
4 library/Zend/Code/Generator/ClassGenerator.php
@@ -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);
}
/**
View
32 tests/ZendTest/Code/Generator/ClassGeneratorTest.php
@@ -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(
Please sign in to comment.
Something went wrong with that request. Please try again.