Skip to content

Commit

Permalink
Merge branch 'hotfix/#301-fix-null-object-return-types' into 2.0.x
Browse files Browse the repository at this point in the history
Close #301
  • Loading branch information
Ocramius committed May 27, 2016
2 parents b88926c + 5143737 commit b3cd3bf
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/ProxyManager/ProxyGenerator/NullObjectGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ public function generate(ReflectionClass $originalClass, ClassGenerator $classGe

if ($originalClass->isInterface()) {
$interfaces[] = $originalClass->getName();
} else {
$classGenerator->setExtendedClass($originalClass->getName());
}

$classGenerator->setImplementedInterfaces($interfaces);

foreach (ProxiedMethodsFilter::getProxiedMethods($originalClass) as $method) {
foreach (ProxiedMethodsFilter::getProxiedMethods($originalClass, []) as $method) {
$classGenerator->addMethodFromGenerator(
NullObjectMethodInterceptor::generateMethod(
new MethodReflection($method->getDeclaringClass()->getName(), $method->getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,17 @@ public function testGeneratesValidCode(string $className)
$this->assertTrue($generatedReflection->implementsInterface($interface));
}

$proxyGenerated = $generatedClassName::staticProxyConstructor();
$proxy = $generatedClassName::staticProxyConstructor();

self::assertInstanceOf($className, $proxy);

foreach (Properties::fromReflectionClass($generatedReflection)->getPublicProperties() as $property) {
$this->assertNull($proxyGenerated->$property);
$this->assertNull($proxy->{$property->getName()});
}

foreach ($generatedReflection->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
if (! ($method->getNumberOfParameters() || $method->isStatic())) {
$this->assertNull(call_user_func([$proxyGenerated, $method->getName()]));
$this->assertNull(call_user_func([$proxy, $method->getName()]));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
Verifies that generated null object satisfies return type declarations
--FILE--
<?php

declare (strict_types = 1);

require_once __DIR__ . '/init.php';

class Kitchen
{
public function foo()
{
return 'bar';
}
}

$factory = new \ProxyManager\Factory\NullObjectFactory($configuration);

$proxy = $factory->createProxy(Kitchen::class);

var_dump($proxy instanceof Kitchen);
?>
--EXPECT--
bool(true)

0 comments on commit b3cd3bf

Please sign in to comment.