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/4988'
Browse files Browse the repository at this point in the history
Close #4988
  • Loading branch information
weierophinney committed Aug 21, 2013
2 parents 3163aa2 + 71d2c39 commit 85829ec
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 9 deletions.
3 changes: 2 additions & 1 deletion library/Zend/Code/Generator/ClassGenerator.php
Expand Up @@ -118,7 +118,8 @@ public static function fromReflection(ClassReflection $classReflection)

$methods = array();
foreach ($classReflection->getMethods() as $reflectionMethod) {
if ($reflectionMethod->getDeclaringClass()->getName() == $cg->getNamespaceName() . "\\" . $cg->getName()) {
$className = ($cg->getNamespaceName())? $cg->getNamespaceName() . "\\" . $cg->getName() : $cg->getName();
if ($reflectionMethod->getDeclaringClass()->getName() == $className) {
$methods[] = MethodGenerator::fromReflection($reflectionMethod);
}
}
Expand Down
8 changes: 6 additions & 2 deletions library/Zend/Code/Generator/ParameterGenerator.php
Expand Up @@ -64,8 +64,12 @@ public static function fromReflection(ParameterReflection $reflectionParameter)
$parameterType = $typeClass->getName();
$currentNamespace = $reflectionParameter->getDeclaringClass()->getNamespaceName();

if (substr($parameterType, 0, strlen($currentNamespace)) == $currentNamespace) {
$parameterType = substr($parameterType, strlen($currentNamespace)+1);
if (!empty($currentNamespace)) {
if (substr($parameterType, 0, strlen($currentNamespace)) == $currentNamespace) {
$parameterType = substr($parameterType, strlen($currentNamespace) + 1);
}
} else {
$parameterType = '\\' . trim($parameterType, '\\');
}

$param->setType($parameterType);
Expand Down
18 changes: 14 additions & 4 deletions tests/ZendTest/Code/Generator/ClassGeneratorTest.php
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Code
*/

namespace ZendTest\Code\Generator;
Expand All @@ -18,7 +17,6 @@

/**
* @category Zend
* @package Zend_Code_Generator
* @subpackage UnitTests
*
* @group Zend_Code_Generator
Expand Down Expand Up @@ -266,6 +264,18 @@ public function testClassFromReflectionDiscardParentImplementedInterfaces()
$this->assertContains($expectedClassDef, $code);
}

/**
* @group 4988
*/
public function testNonNamespaceClassReturnsAllMethods()
{
require_once __DIR__ . '/../TestAsset/NonNamespaceClass.php';

$reflClass = new ClassReflection('ZendTest_Code_NsTest_BarClass');
$classGenerator = ClassGenerator::fromReflection($reflClass);
$this->assertCount(1, $classGenerator->getMethods());
}

/**
* @group ZF-9602
*/
Expand Down Expand Up @@ -379,7 +389,7 @@ public function testAddUses()
}

/**
* @group gh-4990
* @group 4990
*/
public function testAddOneUseTwiceOnlyAddsOne()
{
Expand All @@ -395,7 +405,7 @@ public function testAddOneUseTwiceOnlyAddsOne()
}

/**
* @group gh-4990
* @group 4990
*/
public function testAddOneUseWithAliasTwiceOnlyAddsOne()
{
Expand Down
17 changes: 15 additions & 2 deletions tests/ZendTest/Code/Generator/ParameterGeneratorTest.php
Expand Up @@ -5,7 +5,6 @@
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_Code
*/

namespace ZendTest\Code\Generator;
Expand All @@ -16,7 +15,6 @@

/**
* @category Zend
* @package Zend_Code_Generator
* @subpackage UnitTests
*
* @group Zend_Code_Generator
Expand Down Expand Up @@ -202,4 +200,19 @@ public function testCreateFromArray()
$this->assertEquals('foo', $parameterGenerator->getSourceContent());
$this->assertEquals('-', $parameterGenerator->getIndentation());
}

/**
* @group 4988
*/
public function testParameterGeneratorReturnsCorrectTypeForNonNamespaceClasses()
{
require_once __DIR__ . '/../TestAsset/NonNamespaceClass.php';

$reflClass = new \Zend\Code\Reflection\ClassReflection('ZendTest_Code_NsTest_BarClass');
$params = $reflClass->getMethod('fooMethod')->getParameters();

$param = ParameterGenerator::fromReflection($params[0]);

$this->assertEquals('\ZendTest_Code_NsTest_BarClass', $param->getType());
}
}
15 changes: 15 additions & 0 deletions tests/ZendTest/Code/TestAsset/NonNamespaceClass.php
@@ -0,0 +1,15 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

class ZendTest_Code_NsTest_BarClass
{
public function fooMethod(ZendTest_Code_NsTest_BarClass $parameter)
{
}
}

0 comments on commit 85829ec

Please sign in to comment.