Skip to content
Browse files

Merge branch 'hotfix/3352' into develop

Forward port #3352
  • Loading branch information...
2 parents 611d447 + 7a87702 commit ff9fe67168de10d7ef61604bd19acb9d8dafbdbe @weierophinney weierophinney committed
View
6 library/Zend/Stdlib/Hydrator/ClassMethods.php
@@ -10,6 +10,7 @@
namespace Zend\Stdlib\Hydrator;
+use ReflectionMethod;
use Zend\Stdlib\Exception;
/**
@@ -103,6 +104,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);
View
17 tests/ZendTest/Stdlib/HydratorTest.php
@@ -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;
use Zend\Stdlib\Hydrator\Strategy\DefaultStrategy;
use Zend\Stdlib\Hydrator\Strategy\SerializableStrategy;
@@ -44,6 +45,11 @@ class HydratorTest extends \PHPUnit_Framework_TestCase
protected $classMethodsUnderscore;
/**
+ * @var ClassMethodsInvalidParameter
+ */
+ protected $classMethodsInvalidParameter;
+
+ /**
* @var ReflectionAsset
*/
protected $reflection;
@@ -53,6 +59,7 @@ public function setUp()
$this->classMethodsCamelCase = new ClassMethodsCamelCase();
$this->classMethodsCamelCaseMissing = new ClassMethodsCamelCaseMissing();
$this->classMethodsUnderscore = new ClassMethodsUnderscore();
+ $this->classMethodsInvalidParameter = new ClassMethodsInvalidParameter();
$this->reflection = new ReflectionAsset;
}
@@ -248,4 +255,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']);
+ }
}
View
43 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 ff9fe67

Please sign in to comment.
Something went wrong with that request. Please try again.