Skip to content

Commit

Permalink
Merge pull request #252 from elliotchance/1.7.1/251-callable
Browse files Browse the repository at this point in the history
testCallableHint
  • Loading branch information
elliotchance committed Mar 9, 2015
2 parents 55aeddf + 16f0f2f commit ea6095f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Concise/Mock/PrototypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ protected function getTypeHint(ReflectionParameter $p)
{
if ($p->getClass()) {
return '\\' . $p->getClass()->name . ' ';
} elseif (method_exists($p, 'isCallable') && $p->isCallable()) {
return 'callable ';
} elseif ($p->isArray()) {
return 'array ';
}
Expand Down
19 changes: 18 additions & 1 deletion tests/Concise/Mock/PrototypeBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

use \Concise\TestCase;

// `callable` does not exist in PHP 5.3 and we need it for the prototype below.
if (version_compare(phpversion(), '5.4', '<')) {
eval("class callable {}");
}

abstract class MyClass
{
public function foo()
Expand All @@ -25,6 +30,9 @@ abstract protected function d(array $a);
abstract protected function e(\Closure $a);

abstract protected function f($a = array());

abstract protected function g(callable $a);

}

class PrototypeBuilderTest extends TestCase
Expand Down Expand Up @@ -90,7 +98,7 @@ public function testArrayHint()
$this->assert($this->builder->getPrototype($method), equals, 'abstract protected function d(array $a)');
}

public function testCallableHint()
public function testClosureHint()
{
$method = new \ReflectionMethod('\Concise\Mock\MyClass', 'e');
$this->assert($this->builder->getPrototype($method), equals, 'abstract protected function e(\Closure $a)');
Expand All @@ -115,4 +123,13 @@ public function testMethodMustBeAString()
{
$this->builder->getPrototypeForNonExistentMethod(123);
}

/**
* @requires PHP 5.4
*/
public function testCallableHint()
{
$method = new \ReflectionMethod('\Concise\Mock\MyClass', 'g');
$this->assert($this->builder->getPrototype($method), equals, 'abstract protected function g(callable $a)');
}
}

0 comments on commit ea6095f

Please sign in to comment.