Skip to content

Commit

Permalink
Merge pull request #743 from Majkl578/proxygenerator-fix-interface-ty…
Browse files Browse the repository at this point in the history
…pehints

Fix parameter/return type validation for interfaces (introduced in #734)
  • Loading branch information
Ocramius authored Oct 6, 2016
2 parents 5086700 + f1cdfa1 commit f74f44d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/Common/Proxy/ProxyGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ private function formatType(
$name = $method->getDeclaringClass()->getParentClass()->getName();
}

if ( ! $type->isBuiltin() && ! class_exists($name)) {
if ( ! $type->isBuiltin() && ! class_exists($name) && ! interface_exists($name)) {
if (null !== $parameter) {
throw UnexpectedValueException::invalidParameterTypeHint(
$method->getDeclaringClass()->getName(),
Expand Down
3 changes: 2 additions & 1 deletion tests/Doctrine/Tests/Common/Proxy/ProxyGeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function testClassWithScalarTypeHintsOnProxiedMethods()

$this->assertEquals(1, substr_count($classCode, 'function singleTypeHint(string $param)'));
$this->assertEquals(1, substr_count($classCode, 'function multipleTypeHints(int $a, float $b, bool $c, string $d)'));
$this->assertEquals(1, substr_count($classCode, 'function combinationOfTypeHintsAndNormal(\stdClass $a, $b, int $c)'));
$this->assertEquals(1, substr_count($classCode, 'function combinationOfTypeHintsAndNormal(\stdClass $a, \Countable $b, $c, int $d)'));
$this->assertEquals(1, substr_count($classCode, 'function typeHintsWithVariadic(int ...$foo)'));
$this->assertEquals(1, substr_count($classCode, 'function withDefaultValue(int $foo = 123)'));
$this->assertEquals(1, substr_count($classCode, 'function withDefaultValueNull(int $foo = NULL)'));
Expand Down Expand Up @@ -229,6 +229,7 @@ public function testClassWithReturnTypesOnProxiedMethods()
$this->assertEquals(1, substr_count($classCode, 'function returnsCallable(): callable'));
$this->assertEquals(1, substr_count($classCode, 'function returnsSelf(): \\' . $className));
$this->assertEquals(1, substr_count($classCode, 'function returnsParent(): \stdClass'));
$this->assertEquals(1, substr_count($classCode, 'function returnsInterface(): \Countable'));
}

public function testClassWithNullableTypeHintsOnProxiedMethods()
Expand Down
4 changes: 4 additions & 0 deletions tests/Doctrine/Tests/Common/Proxy/ReturnTypesClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,8 @@ public function returnsSelf(): self
public function returnsParent(): parent
{
}

public function returnsInterface() : \Countable
{
}
}
2 changes: 1 addition & 1 deletion tests/Doctrine/Tests/Common/Proxy/ScalarTypeHintsClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function multipleTypeHints(int $a, float $b, bool $c, string $d)
{
}

public function combinationOfTypeHintsAndNormal(\stdClass $a, $b, int $c)
public function combinationOfTypeHintsAndNormal(\stdClass $a, \Countable $b, $c, int $d)
{
}

Expand Down

0 comments on commit f74f44d

Please sign in to comment.