Skip to content

Commit

Permalink
Class renamer visitor should put original class in newly instantiated…
Browse files Browse the repository at this point in the history
… namespaces
  • Loading branch information
Ocramius committed Jul 19, 2013
1 parent ee153ca commit 5d841cd
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/CodeGenerationUtils/Visitor/ClassRenamerVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function leaveNode(PHPParser_Node $node)
// @todo too simplistic (assumes single class per namespace right now)
if ($this->currentNamespace) {
$this->replacedInNamespace = $node;
$this->currentNamespace->stmts = array($node);
} elseif ($this->newNamespace) {
// wrap in namespace if no previous namespace exists
return new PHPParser_Node_Stmt_Namespace(new PHPParser_Node_Name($this->newNamespace), array($node));
Expand All @@ -105,7 +106,7 @@ public function leaveNode(PHPParser_Node $node)
private function namespaceMatches()
{
$currentNamespace = ($this->currentNamespace && is_array($this->currentNamespace->name->parts))
? implode('\\', $this->currentNamespace->name->parts)
? $this->currentNamespace->name->toString()
: '';

return $currentNamespace === $this->reflectedClass->getNamespaceName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function testRenamesNodesOnMatchingClass()

$this->assertSame('Baz', $class->name);
$this->assertSame(array('Foo', 'Bar'), $namespace->name->parts);
$this->assertSame(array($class), $namespace->stmts);
}

public function testIgnoresNodesOnNonMatchingClass()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ private function generateProxy($instance)
$config = new Configuration();
$inflector = $this->getMock('CodeGenerationUtils\\Inflector\\ClassNameInflectorInterface');

$inflector->expects($this->any())->method('getProxyClassName')->will($this->returnValue($generatedClassName));
$inflector->expects($this->any())->method('getProxyClassName')->with($parentClassName)->will($this->returnValue($generatedClassName));
$inflector->expects($this->any())->method('getUserClassName')->with($parentClassName)->will($this->returnValue($parentClassName));
$config->setClassNameInflector($inflector);
$config->setGeneratorStrategy(new EvaluatingGeneratorStrategy());

Expand Down

0 comments on commit 5d841cd

Please sign in to comment.