Permalink
Browse files

Merge pull request #260 from Ocramius/hotfix/issue-#259

Hotfix/issue #259
  • Loading branch information...
2 parents e211821 + b5bbc74 commit 0dc4fe01f056596697c5a91d7201209e8ccbfd58 @guilhermeblanco guilhermeblanco committed Mar 7, 2013
@@ -772,6 +772,8 @@ private function generateMethods(ClassMetadata $class)
$parameterString .= '\\' . $paramClass->getName() . ' ';
} elseif ($param->isArray()) {
$parameterString .= 'array ';
+ } elseif (method_exists($param, 'isCallable') && $param->isCallable()) {
+ $parameterString .= 'callable ';
}
if ($param->isPassedByReference()) {
@@ -0,0 +1,16 @@
+<?php
+
+namespace Doctrine\Tests\Common\Proxy;
+
+/**
+ * Test asset class
+ */
+class CallableTypeHintClass
+{
+ /**
+ * @param callable $foo
+ */
+ public function call(callable $foo)
+ {
+ }
+}
@@ -122,6 +122,30 @@ public function testClassWithSleepProxyGeneration()
$this->assertEquals(1, substr_count($classCode, 'parent::__sleep()'));
}
+ public function testClassWithCallableTypeHintOnProxiedMethod()
+ {
+ if (PHP_VERSION_ID < 50400) {
+ $this->markTestSkipped('`callable` is only supported in PHP >=5.4.0');
+ }
+
+ if (!class_exists('Doctrine\Tests\Common\ProxyProxy\__CG__\CallableTypeHintClass', false)) {
+ $metadata = $this->getMock('Doctrine\Common\Persistence\Mapping\ClassMetadata');
+ $reflClass = new ReflectionClass('Doctrine\Tests\Common\Proxy\CallableTypeHintClass');
+ $proxyGenerator = new ProxyGenerator(__DIR__ . '/generated', __NAMESPACE__ . 'Proxy', true);
+
+ $metadata->expects($this->any())->method('getReflectionClass')->will($this->returnValue($reflClass));
+ $metadata->expects($this->any())->method('getIdentifierFieldNames')->will($this->returnValue(array('id')));
+ $metadata->expects($this->any())->method('getName')->will($this->returnValue($reflClass->getName()));
+
+ $proxyGenerator->generateProxyClass($metadata);
+ require_once $proxyGenerator->getProxyFileName($metadata->getName());
+ }
+
+ $classCode = file_get_contents(__DIR__ . '/generated/__CG__DoctrineTestsCommonProxyCallableTypeHintClass.php');
+
+ $this->assertEquals(1, substr_count($classCode, 'call(callable $foo)'));
+ }
+
public function testClassWithInvalidTypeHintOnProxiedMethod()
{
$className = 'Doctrine\Tests\Common\Proxy\InvalidTypeHintClass';

0 comments on commit 0dc4fe0

Please sign in to comment.