Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/4990' into develop
Browse files Browse the repository at this point in the history
Forward port #4990
  • Loading branch information
weierophinney committed Aug 21, 2013
2 parents 8fcbe7b + 4c31950 commit 7be43e3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
4 changes: 2 additions & 2 deletions library/Zend/Code/Generator/ClassGenerator.php
Expand Up @@ -490,7 +490,7 @@ public function addUse($use, $useAlias = null)
$use .= ' as ' . $useAlias;
}

$this->uses[] = $use;
$this->uses[$use] = $use;
return $this;
}

Expand Down Expand Up @@ -524,7 +524,7 @@ public function getProperty($propertyName)
*/
public function getUses()
{
return $this->uses;
return array_values($this->uses);
}

/**
Expand Down
32 changes: 32 additions & 0 deletions tests/ZendTest/Code/Generator/ClassGeneratorTest.php
Expand Up @@ -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(
Expand Down

0 comments on commit 7be43e3

Please sign in to comment.