This commit is contained in:
Johannes Schmitt 2010-12-12 10:06:25 +01:00 committed by Fabien Potencier
parent a7c81577c7
commit 763bba9b89
2 changed files with 8 additions and 4 deletions

View File

@ -80,9 +80,8 @@ class InterfaceInjector
{
if (is_string($object)) {
$reflection = new \ReflectionClass($object);
return $reflection->implementsInterface($this->class)
|| $reflection->isSubClassOf($this->class)
return $reflection->isSubClassOf($this->class)
|| $object === $this->class;
}

View File

@ -146,6 +146,9 @@ class InterfaceInjectorTest extends \PHPUnit_Framework_TestCase
array(new InterfaceInjector('Symfony\Tests\Component\DependencyInjection\SubService'), 'Symfony\Tests\Component\DependencyInjection\Service', false),
array(new InterfaceInjector('Symfony\Tests\Component\DependencyInjection\Service'), 'Symfony\Tests\Component\DependencyInjection\SubService', true),
array(new InterfaceInjector('Symfony\Tests\Component\DependencyInjection\SubService'), 'Symfony\Tests\Component\DependencyInjection\SubService', true),
array(new InterfaceInjector('Symfony\Tests\Component\DependencyInjection\FooInterface'), 'Symfony\Tests\Component\DependencyInjection\SubService', true),
array(new InterfaceInjector('Symfony\Tests\Component\DependencyInjection\FooInterface'), 'Symfony\Tests\Component\DependencyInjection\Service', false),
array(new InterfaceInjector('Symfony\Tests\Component\DependencyInjection\FooInterface'), 'Symfony\Tests\Component\DependencyInjection\ServiceWithConstructor', false),
);
}
@ -168,5 +171,7 @@ class InterfaceInjectorTest extends \PHPUnit_Framework_TestCase
}
}
class ServiceWithConstructor { public function __construct(\DateTime $required) {} }
class Service {}
class SubService extends Service {}
class SubService extends Service implements FooInterface {}
interface FooInterface {}