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/3352'
Browse files Browse the repository at this point in the history
Close #3352
  • Loading branch information
weierophinney committed Jan 14, 2013
2 parents bd03272 + aa49008 commit 2529b98
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
6 changes: 6 additions & 0 deletions library/Zend/Stdlib/Hydrator/ClassMethods.php
Expand Up @@ -10,6 +10,7 @@

namespace Zend\Stdlib\Hydrator;

use ReflectionMethod;
use Zend\Stdlib\Exception;

/**
Expand Down Expand Up @@ -64,6 +65,11 @@ public function extract($object)
continue;
}

$reflectionMethod = new ReflectionMethod(get_class($object) . '::' . $method);
if ($reflectionMethod->getNumberOfParameters() > 0) {
continue;
}

$attribute = $method;
if (preg_match('/^get/', $method)) {
$attribute = substr($method, 3);
Expand Down
17 changes: 17 additions & 0 deletions tests/ZendTest/Stdlib/HydratorTest.php
Expand Up @@ -15,6 +15,7 @@
use ZendTest\Stdlib\TestAsset\ClassMethodsCamelCase;
use ZendTest\Stdlib\TestAsset\ClassMethodsUnderscore;
use ZendTest\Stdlib\TestAsset\ClassMethodsCamelCaseMissing;
use ZendTest\Stdlib\TestAsset\ClassMethodsInvalidParameter;
use ZendTest\Stdlib\TestAsset\Reflection as ReflectionAsset;

/**
Expand All @@ -41,6 +42,11 @@ class HydratorTest extends \PHPUnit_Framework_TestCase
*/
protected $classMethodsUnderscore;

/**
* @var ClassMethodsInvalidParameter
*/
protected $classMethodsInvalidParameter;

/**
* @var ReflectionAsset
*/
Expand All @@ -51,6 +57,7 @@ public function setUp()
$this->classMethodsCamelCase = new ClassMethodsCamelCase();
$this->classMethodsCamelCaseMissing = new ClassMethodsCamelCaseMissing();
$this->classMethodsUnderscore = new ClassMethodsUnderscore();
$this->classMethodsInvalidParameter = new ClassMethodsInvalidParameter();
$this->reflection = new ReflectionAsset;
}

Expand Down Expand Up @@ -203,4 +210,14 @@ public function testHydratorClassMethodsCamelCaseWithSetterMissing()
$this->assertEquals($test->getFooBar(), 'foo');
$this->assertEquals($test->getFooBarBaz(), '2');
}

public function testHydratorClassMethodsWithServiceManager()
{
$hydrator = new ClassMethods(false);
$datas = $hydrator->extract($this->classMethodsInvalidParameter);

$this->assertTrue($datas['hasBar']);
$this->assertEquals('Bar', $datas['foo']);
$this->assertFalse($datas['isBla']);
}
}
43 changes: 43 additions & 0 deletions tests/ZendTest/Stdlib/TestAsset/ClassMethodsInvalidParameter.php
@@ -0,0 +1,43 @@
<?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
* @package Zend_Stdlib
*/
namespace ZendTest\Stdlib\TestAsset;

class ClassMethodsInvalidParameter
{
public function hasAlias($alias)
{
return $alias;
}

public function getTest($foo)
{
return $foo;
}

public function isTest($bar)
{
return $bar;
}

public function hasBar()
{
return true;
}

public function getFoo()
{
return "Bar";
}

public function isBla()
{
return false;
}
}

0 comments on commit 2529b98

Please sign in to comment.