Skip to content

Commit

Permalink
Merge pull request #260 from Ocramius/hotfix/issue-#259
Browse files Browse the repository at this point in the history
Hotfix/issue #259
  • Loading branch information
guilhermeblanco committed Mar 7, 2013
2 parents e211821 + b5bbc74 commit 0dc4fe0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/Doctrine/Common/Proxy/ProxyGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
16 changes: 16 additions & 0 deletions tests/Doctrine/Tests/Common/Proxy/CallableTypeHintClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Doctrine\Tests\Common\Proxy;

/**
* Test asset class
*/
class CallableTypeHintClass
{
/**
* @param callable $foo
*/
public function call(callable $foo)
{
}
}
24 changes: 24 additions & 0 deletions tests/Doctrine/Tests/Common/Proxy/ProxyClassGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit 0dc4fe0

Please sign in to comment.